|
38 | 38 | @RunWith(PowerMockRunner.class) |
39 | 39 | @PrepareForTest (Log4JLogFactory.class) |
40 | 40 | public class Log4JLogFactoryTest { |
41 | | - @Rule |
| 41 | + @Rule |
42 | 42 | public TestName testName = new TestName(); |
43 | | - |
| 43 | + |
44 | 44 | @Test |
45 | 45 | public void testCreateLoggerByString() { |
46 | 46 | Logger logger = new Log4JLogFactory().getLogger("test"); |
47 | 47 | Assert.assertTrue(logger instanceof Log4JLogger); |
48 | 48 | } |
49 | | - |
| 49 | + |
50 | 50 | @Test public void testCreateLoggerByClass() { |
51 | 51 | Logger logger = new Log4JLogFactory().getLogger(Log4JLogBridgeImplTest.class); |
52 | 52 | Assert.assertTrue(logger instanceof Log4JLogger); |
53 | 53 | } |
54 | | - |
| 54 | + |
55 | 55 | @Test |
56 | 56 | public void checkScrubberWithEncoding() throws Exception { |
57 | 57 | ArgumentCaptor<List> delegates = ArgumentCaptor.forClass(List.class); |
58 | 58 | PowerMockito.whenNew(CompositeLogScrubber.class).withArguments(delegates.capture()).thenReturn(null); |
59 | | - |
| 59 | + |
60 | 60 | //Call to invoke the constructor capture |
61 | 61 | Log4JLogFactory.createLogScrubber(true); |
62 | | - |
| 62 | + |
63 | 63 | List<LogScrubber> scrubbers = delegates.getValue(); |
64 | 64 | Assert.assertEquals(2, scrubbers.size()); |
65 | 65 | Assert.assertTrue(scrubbers.get(0) instanceof NewlineLogScrubber); |
66 | 66 | Assert.assertTrue(scrubbers.get(1) instanceof CodecLogScrubber); |
67 | 67 | } |
68 | | - |
| 68 | + |
69 | 69 | @Test |
70 | 70 | public void checkScrubberWithoutEncoding() throws Exception { |
71 | 71 | ArgumentCaptor<List> delegates = ArgumentCaptor.forClass(List.class); |
72 | 72 | PowerMockito.whenNew(CompositeLogScrubber.class).withArguments(delegates.capture()).thenReturn(null); |
73 | | - |
| 73 | + |
74 | 74 | //Call to invoke the constructor capture |
75 | 75 | Log4JLogFactory.createLogScrubber(false); |
76 | | - |
| 76 | + |
77 | 77 | List<LogScrubber> scrubbers = delegates.getValue(); |
78 | 78 | Assert.assertEquals(1, scrubbers.size()); |
79 | 79 | Assert.assertTrue(scrubbers.get(0) instanceof NewlineLogScrubber); |
80 | 80 | } |
81 | | - |
| 81 | + |
82 | 82 | /** |
83 | | - * At this time there are no special considerations or handling for the appender |
84 | | - * creation in this scope. It is expected that the arguments to the internal |
85 | | - * creation method are passed directly to the constructor of the |
86 | | - * LogPrefixAppender with no mutation or additional validation. |
87 | | - */ |
| 83 | + * At this time there are no special considerations or handling for the appender |
| 84 | + * creation in this scope. It is expected that the arguments to the internal |
| 85 | + * creation method are passed directly to the constructor of the |
| 86 | + * LogPrefixAppender with no mutation or additional validation. |
| 87 | + */ |
88 | 88 | @Test |
89 | 89 | public void checkPassthroughAppenderConstruct() throws Exception { |
90 | | - LogPrefixAppender stubAppender = new LogPrefixAppender(true, true, true, ""); |
91 | | - ArgumentCaptor<Boolean> clientInfoCapture = ArgumentCaptor.forClass(Boolean.class); |
92 | | - ArgumentCaptor<Boolean> serverInfoCapture = ArgumentCaptor.forClass(Boolean.class); |
93 | | - ArgumentCaptor<Boolean> logAppNameCapture = ArgumentCaptor.forClass(Boolean.class); |
94 | | - ArgumentCaptor<String> appNameCapture = ArgumentCaptor.forClass(String.class); |
95 | | - |
96 | | - PowerMockito.whenNew(LogPrefixAppender.class).withArguments(clientInfoCapture.capture(), serverInfoCapture.capture(), logAppNameCapture.capture(), appNameCapture.capture()).thenReturn(stubAppender); |
97 | | - |
98 | | - LogAppender appender = Log4JLogFactory.createLogAppender(true, false, true, testName.getMethodName()); |
99 | | - |
100 | | - Assert.assertEquals(stubAppender, appender); |
101 | | - Assert.assertTrue(clientInfoCapture.getValue()); |
102 | | - Assert.assertFalse(serverInfoCapture.getValue()); |
103 | | - Assert.assertTrue(logAppNameCapture.getValue()); |
104 | | - Assert.assertEquals(testName.getMethodName(), appNameCapture.getValue()); |
| 90 | + LogPrefixAppender stubAppender = new LogPrefixAppender(true, true, true, ""); |
| 91 | + ArgumentCaptor<Boolean> clientInfoCapture = ArgumentCaptor.forClass(Boolean.class); |
| 92 | + ArgumentCaptor<Boolean> serverInfoCapture = ArgumentCaptor.forClass(Boolean.class); |
| 93 | + ArgumentCaptor<Boolean> logAppNameCapture = ArgumentCaptor.forClass(Boolean.class); |
| 94 | + ArgumentCaptor<String> appNameCapture = ArgumentCaptor.forClass(String.class); |
| 95 | + |
| 96 | + PowerMockito.whenNew(LogPrefixAppender.class).withArguments(clientInfoCapture.capture(), serverInfoCapture.capture(), logAppNameCapture.capture(), appNameCapture.capture()).thenReturn(stubAppender); |
| 97 | + |
| 98 | + LogAppender appender = Log4JLogFactory.createLogAppender(true, false, true, testName.getMethodName()); |
| 99 | + |
| 100 | + Assert.assertEquals(stubAppender, appender); |
| 101 | + Assert.assertTrue(clientInfoCapture.getValue()); |
| 102 | + Assert.assertFalse(serverInfoCapture.getValue()); |
| 103 | + Assert.assertTrue(logAppNameCapture.getValue()); |
| 104 | + Assert.assertEquals(testName.getMethodName(), appNameCapture.getValue()); |
105 | 105 | } |
106 | | - |
107 | | - |
| 106 | + |
| 107 | + |
108 | 108 | } |
0 commit comments