1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.classic.util;
15
16 public class TestHelper {
17
18 static public Throwable makeNestedException(int level) {
19 if (level == 0) {
20 return new Exception("nesting level=" + level);
21 }
22 Throwable cause = makeNestedException(level - 1);
23 return new Exception("nesting level =" + level, cause);
24 }
25
26
27
28
29
30
31
32
33
34
35
36
37 public static StringPosition positionOf(String pattern) {
38 return new StringPosition(pattern);
39 }
40
41 public static class StringPosition {
42 private final String pattern;
43
44 public StringPosition(String pattern) {
45 this.pattern = pattern;
46 }
47
48 public int in(String s) {
49 final int position = s.indexOf(pattern);
50 if (position < 0)
51 throw new IllegalArgumentException("String '" + pattern + "' not found in: '" + s + "'");
52 return position;
53 }
54
55 }
56
57 }