|
16 | 16 | */ |
17 | 17 | package org.apache.logging.log4j.core.filter; |
18 | 18 |
|
| 19 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 20 | +import static org.junit.jupiter.api.Assertions.assertInstanceOf; |
| 21 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 22 | +import static org.junit.jupiter.api.Assertions.assertNull; |
| 23 | + |
19 | 24 | import org.apache.logging.log4j.core.Filter; |
20 | 25 | import org.apache.logging.log4j.core.config.Configuration; |
21 | 26 | import org.apache.logging.log4j.core.test.junit.LoggerContextSource; |
22 | 27 | import org.junit.jupiter.api.Assertions; |
23 | 28 | import org.junit.jupiter.api.Test; |
24 | 29 |
|
25 | | -import static org.junit.jupiter.api.Assertions.assertEquals; |
26 | | -import static org.junit.jupiter.api.Assertions.assertInstanceOf; |
27 | | -import static org.junit.jupiter.api.Assertions.assertNotNull; |
28 | | -import static org.junit.jupiter.api.Assertions.assertNull; |
29 | | - |
30 | 30 | /** |
31 | 31 | * Unit test for {@link StringMatchFilter}. |
32 | 32 | */ |
33 | 33 | public class StringMatchFilterTest { |
34 | 34 |
|
35 | | - /** |
36 | | - * Test that if no match-string is set on the builder, the '{@link StringMatchFilter.Builder#build()}' returns |
37 | | - * {@code null}. |
38 | | - */ |
39 | | - @Test |
40 | | - public void testFilterBuilderFailsWithNullText() { |
41 | | - Assertions.assertNull(StringMatchFilter.newBuilder().build()); |
42 | | - } |
43 | | - |
44 | | - /** |
45 | | - * Test that if a {@code null} string is set as a match-pattern, an {@code IllegalArgumentExeption} is thrown. |
46 | | - */ |
47 | | - @Test |
48 | | - void testFilterBuilderFailsWithExceptionOnNullText() { |
49 | | - Assertions.assertThrows(IllegalArgumentException.class, () -> StringMatchFilter.newBuilder().setMatchString(null)); |
50 | | - } |
| 35 | + /** |
| 36 | + * Test that if no match-string is set on the builder, the '{@link StringMatchFilter.Builder#build()}' returns |
| 37 | + * {@code null}. |
| 38 | + */ |
| 39 | + @Test |
| 40 | + public void testFilterBuilderFailsWithNullText() { |
| 41 | + Assertions.assertNull(StringMatchFilter.newBuilder().build()); |
| 42 | + } |
51 | 43 |
|
52 | | - /** |
53 | | - * Test that if an empty ({@code ""}) string is set as a match-pattern, an {@code IllegalArgumentException} is thrown. |
54 | | - */ |
55 | | - @Test |
56 | | - void testFilterBuilderFailsWithExceptionOnEmptyText() { |
57 | | - Assertions.assertThrows(IllegalArgumentException.class, () -> StringMatchFilter.newBuilder().setMatchString("")); |
58 | | - } |
| 44 | + /** |
| 45 | + * Test that if a {@code null} string is set as a match-pattern, an {@code IllegalArgumentExeption} is thrown. |
| 46 | + */ |
| 47 | + @Test |
| 48 | + void testFilterBuilderFailsWithExceptionOnNullText() { |
| 49 | + Assertions.assertThrows(IllegalArgumentException.class, () -> StringMatchFilter.newBuilder() |
| 50 | + .setMatchString(null)); |
| 51 | + } |
59 | 52 |
|
60 | | - /** |
61 | | - * Test that if a {@link StringMatchFilter} is specified with a 'text' attribute it is correctly instantiated. |
62 | | - * |
63 | | - * @param configuration the configuration |
64 | | - */ |
65 | | - @Test |
66 | | - @LoggerContextSource("log4j2-stringmatchfilter-3153-ok.xml") |
67 | | - void testConfigurationWithTextPOS(final Configuration configuration) { |
68 | | - final Filter filter = configuration.getFilter(); |
69 | | - assertNotNull(filter, "The filter should not be null."); |
70 | | - assertInstanceOf(StringMatchFilter.class, filter, "Expected a StringMatchFilter, but got: " + filter.getClass()); |
71 | | - assertEquals("FooBar", filter.toString()); |
72 | | - } |
| 53 | + /** |
| 54 | + * Test that if an empty ({@code ""}) string is set as a match-pattern, an {@code IllegalArgumentException} is thrown. |
| 55 | + */ |
| 56 | + @Test |
| 57 | + void testFilterBuilderFailsWithExceptionOnEmptyText() { |
| 58 | + Assertions.assertThrows(IllegalArgumentException.class, () -> StringMatchFilter.newBuilder() |
| 59 | + .setMatchString("")); |
| 60 | + } |
73 | 61 |
|
74 | | - /** |
75 | | - * Test that if a {@link StringMatchFilter} is specified without a 'text' attribute it is not instantiated. |
76 | | - * |
77 | | - * @param configuration the configuration |
78 | | - */ |
79 | | - @Test |
80 | | - @LoggerContextSource("log4j2-stringmatchfilter-3153-nok.xml") |
81 | | - void testConfigurationWithTextNEG(final Configuration configuration) { |
82 | | - final Filter filter = configuration.getFilter(); |
83 | | - assertNull(filter, "The filter should be null."); |
84 | | - } |
| 62 | + /** |
| 63 | + * Test that if a {@link StringMatchFilter} is specified with a 'text' attribute it is correctly instantiated. |
| 64 | + * |
| 65 | + * @param configuration the configuration |
| 66 | + */ |
| 67 | + @Test |
| 68 | + @LoggerContextSource("log4j2-stringmatchfilter-3153-ok.xml") |
| 69 | + void testConfigurationWithTextPOS(final Configuration configuration) { |
| 70 | + final Filter filter = configuration.getFilter(); |
| 71 | + assertNotNull(filter, "The filter should not be null."); |
| 72 | + assertInstanceOf( |
| 73 | + StringMatchFilter.class, filter, "Expected a StringMatchFilter, but got: " + filter.getClass()); |
| 74 | + assertEquals("FooBar", filter.toString()); |
| 75 | + } |
85 | 76 |
|
| 77 | + /** |
| 78 | + * Test that if a {@link StringMatchFilter} is specified without a 'text' attribute it is not instantiated. |
| 79 | + * |
| 80 | + * @param configuration the configuration |
| 81 | + */ |
| 82 | + @Test |
| 83 | + @LoggerContextSource("log4j2-stringmatchfilter-3153-nok.xml") |
| 84 | + void testConfigurationWithTextNEG(final Configuration configuration) { |
| 85 | + final Filter filter = configuration.getFilter(); |
| 86 | + assertNull(filter, "The filter should be null."); |
| 87 | + } |
86 | 88 | } |
0 commit comments