|
33 | 33 | */
|
34 | 34 | class ExceptionTypeFilterTests {
|
35 | 35 |
|
| 36 | + ExceptionTypeFilter filter; |
| 37 | + |
36 | 38 | @Test
|
37 | 39 | void emptyFilter() {
|
38 |
| - var filter = new ExceptionTypeFilter(null, null); |
| 40 | + filter = new ExceptionTypeFilter(null, null); |
39 | 41 |
|
40 |
| - assertMatches(filter, Throwable.class); |
41 |
| - assertMatches(filter, Error.class); |
42 |
| - assertMatches(filter, Exception.class); |
43 |
| - assertMatches(filter, RuntimeException.class); |
| 42 | + assertMatches(new Throwable()); |
| 43 | + assertMatches(new Error()); |
| 44 | + assertMatches(new Exception()); |
| 45 | + assertMatches(new RuntimeException()); |
44 | 46 | }
|
45 | 47 |
|
46 | 48 | @Test
|
47 | 49 | void includes() {
|
48 |
| - var filter = new ExceptionTypeFilter(List.of(FileNotFoundException.class, IllegalArgumentException.class), null); |
| 50 | + filter = new ExceptionTypeFilter(List.of(FileNotFoundException.class, IllegalArgumentException.class), null); |
49 | 51 |
|
50 |
| - assertMatches(filter, FileNotFoundException.class); |
51 |
| - assertMatches(filter, IllegalArgumentException.class); |
52 |
| - assertMatches(filter, NumberFormatException.class); |
| 52 | + assertMatches(new FileNotFoundException()); |
| 53 | + assertMatches(new IllegalArgumentException()); |
| 54 | + assertMatches(new NumberFormatException()); |
53 | 55 |
|
54 |
| - assertDoesNotMatch(filter, Throwable.class); |
55 |
| - assertDoesNotMatch(filter, FileSystemException.class); |
| 56 | + assertDoesNotMatch(new Throwable()); |
| 57 | + assertDoesNotMatch(new FileSystemException("test")); |
56 | 58 | }
|
57 | 59 |
|
58 | 60 | @Test
|
59 | 61 | void includesSubtypeMatching() {
|
60 |
| - var filter = new ExceptionTypeFilter(List.of(RuntimeException.class), null); |
| 62 | + filter = new ExceptionTypeFilter(List.of(RuntimeException.class), null); |
61 | 63 |
|
62 |
| - assertMatches(filter, RuntimeException.class); |
63 |
| - assertMatches(filter, IllegalStateException.class); |
| 64 | + assertMatches(new RuntimeException()); |
| 65 | + assertMatches(new IllegalStateException()); |
64 | 66 |
|
65 |
| - assertDoesNotMatch(filter, Exception.class); |
| 67 | + assertDoesNotMatch(new Exception()); |
66 | 68 | }
|
67 | 69 |
|
68 | 70 | @Test
|
69 | 71 | void excludes() {
|
70 |
| - var filter = new ExceptionTypeFilter(null, List.of(FileNotFoundException.class, IllegalArgumentException.class)); |
| 72 | + filter = new ExceptionTypeFilter(null, List.of(FileNotFoundException.class, IllegalArgumentException.class)); |
71 | 73 |
|
72 |
| - assertDoesNotMatch(filter, FileNotFoundException.class); |
73 |
| - assertDoesNotMatch(filter, IllegalArgumentException.class); |
| 74 | + assertDoesNotMatch(new FileNotFoundException()); |
| 75 | + assertDoesNotMatch(new IllegalArgumentException()); |
74 | 76 |
|
75 |
| - assertMatches(filter, Throwable.class); |
76 |
| - assertMatches(filter, AssertionError.class); |
77 |
| - assertMatches(filter, FileSystemException.class); |
| 77 | + assertMatches(new Throwable()); |
| 78 | + assertMatches(new AssertionError()); |
| 79 | + assertMatches(new FileSystemException("test")); |
78 | 80 | }
|
79 | 81 |
|
80 | 82 | @Test
|
81 | 83 | void excludesSubtypeMatching() {
|
82 |
| - var filter = new ExceptionTypeFilter(null, List.of(IllegalArgumentException.class)); |
| 84 | + filter = new ExceptionTypeFilter(null, List.of(IllegalArgumentException.class)); |
83 | 85 |
|
84 |
| - assertDoesNotMatch(filter, IllegalArgumentException.class); |
85 |
| - assertDoesNotMatch(filter, NumberFormatException.class); |
| 86 | + assertDoesNotMatch(new IllegalArgumentException()); |
| 87 | + assertDoesNotMatch(new NumberFormatException()); |
86 | 88 |
|
87 |
| - assertMatches(filter, Throwable.class); |
| 89 | + assertMatches(new Throwable()); |
88 | 90 | }
|
89 | 91 |
|
90 | 92 | @Test
|
91 | 93 | void includesAndExcludes() {
|
92 |
| - var filter = new ExceptionTypeFilter(List.of(IOException.class), List.of(FileNotFoundException.class)); |
| 94 | + filter = new ExceptionTypeFilter(List.of(IOException.class), List.of(FileNotFoundException.class)); |
93 | 95 |
|
94 |
| - assertMatches(filter, IOException.class); |
95 |
| - assertMatches(filter, FileSystemException.class); |
| 96 | + assertMatches(new IOException()); |
| 97 | + assertMatches(new FileSystemException("test")); |
96 | 98 |
|
97 |
| - assertDoesNotMatch(filter, FileNotFoundException.class); |
98 |
| - assertDoesNotMatch(filter, Throwable.class); |
| 99 | + assertDoesNotMatch(new FileNotFoundException()); |
| 100 | + assertDoesNotMatch(new Throwable()); |
99 | 101 | }
|
100 | 102 |
|
101 | 103 |
|
102 |
| - private static void assertMatches(ExceptionTypeFilter filter, Class<? extends Throwable> candidate) { |
103 |
| - assertThat(filter.match(candidate)) |
104 |
| - .as("filter '" + filter + "' should match " + candidate.getSimpleName()) |
| 104 | + private void assertMatches(Throwable candidate) { |
| 105 | + assertThat(this.filter.match(candidate)) |
| 106 | + .as("filter '" + this.filter + "' should match " + candidate.getClass().getSimpleName()) |
105 | 107 | .isTrue();
|
106 | 108 | }
|
107 | 109 |
|
108 |
| - private static void assertDoesNotMatch(ExceptionTypeFilter filter, Class<? extends Throwable> candidate) { |
109 |
| - assertThat(filter.match(candidate)) |
110 |
| - .as("filter '" + filter + "' should not match " + candidate.getSimpleName()) |
| 110 | + private void assertDoesNotMatch(Throwable candidate) { |
| 111 | + assertThat(this.filter.match(candidate)) |
| 112 | + .as("filter '" + this.filter + "' should not match " + candidate.getClass().getSimpleName()) |
111 | 113 | .isFalse();
|
112 | 114 | }
|
113 | 115 |
|
|
0 commit comments