72
72
import static org .assertj .core .api .Assertions .assertThat ;
73
73
import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
74
74
import static org .assertj .core .api .Assertions .assertThatIllegalStateException ;
75
- import static org .hamcrest .Matchers .containsString ;
76
- import static org .hamcrest .Matchers .not ;
77
75
78
76
/**
79
77
* Tests for {@link LoggingApplicationListener} with Logback.
@@ -150,10 +148,10 @@ private String tmpDir() {
150
148
@ Test
151
149
public void baseConfigLocation () {
152
150
this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
153
- this .output .expect (containsString ("Hello world" ));
154
- this .output .expect (not (containsString ("???" )));
155
- this .output .expect (containsString ("[junit-" ));
156
151
this .logger .info ("Hello world" , new RuntimeException ("Expected" ));
152
+ assertThat (this .output ).contains ("Hello world" );
153
+ assertThat (this .output ).doesNotContain ("???" );
154
+ assertThat (this .output ).contains ("[junit-" );
157
155
assertThat (new File (tmpDir () + "/spring.log" ).exists ()).isFalse ();
158
156
}
159
157
@@ -162,17 +160,16 @@ public void overrideConfigLocation() {
162
160
addPropertiesToEnvironment (this .context , "logging.config=classpath:logback-nondefault.xml" );
163
161
this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
164
162
this .logger .info ("Hello world" );
165
- String output = this .output .toString ().trim ();
166
- assertThat (output ).contains ("Hello world" ).doesNotContain ("???" ).startsWith ("null " ).endsWith ("BOOTBOOT" );
163
+ assertThat (this .output ).contains ("Hello world" ).doesNotContain ("???" ).startsWith ("null " ).endsWith ("BOOTBOOT" );
167
164
}
168
165
169
166
@ Test
170
167
public void overrideConfigDoesNotExist () {
171
168
addPropertiesToEnvironment (this .context , "logging.config=doesnotexist.xml" );
172
169
assertThatIllegalStateException ().isThrownBy (() -> {
173
- this .output .expect (
174
- containsString ("Logging system failed to initialize using configuration from 'doesnotexist.xml'" ));
175
170
this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
171
+ assertThat (this .output )
172
+ .contains ("Logging system failed to initialize using configuration from 'doesnotexist.xml'" );
176
173
});
177
174
}
178
175
@@ -182,8 +179,7 @@ public void azureDefaultLoggingConfigDoesNotCauseAFailure() {
182
179
"logging.config=-Djava.util.logging.config.file=\" d:\\ home\\ site\\ wwwroot\\ bin\\ apache-tomcat-7.0.52\\ conf\\ logging.properties\" " );
183
180
this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
184
181
this .logger .info ("Hello world" );
185
- String output = this .output .toString ().trim ();
186
- assertThat (output ).contains ("Hello world" ).doesNotContain ("???" );
182
+ assertThat (this .output ).contains ("Hello world" ).doesNotContain ("???" );
187
183
assertThat (new File (tmpDir () + "/spring.log" ).exists ()).isFalse ();
188
184
}
189
185
@@ -192,19 +188,18 @@ public void tomcatNopLoggingConfigDoesNotCauseAFailure() {
192
188
addPropertiesToEnvironment (this .context , "LOGGING_CONFIG=-Dnop" );
193
189
this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
194
190
this .logger .info ("Hello world" );
195
- String output = this .output .toString ().trim ();
196
- assertThat (output ).contains ("Hello world" ).doesNotContain ("???" );
191
+ assertThat (this .output ).contains ("Hello world" ).doesNotContain ("???" );
197
192
assertThat (new File (tmpDir () + "/spring.log" ).exists ()).isFalse ();
198
193
}
199
194
200
195
@ Test
201
196
public void overrideConfigBroken () {
202
197
addPropertiesToEnvironment (this .context , "logging.config=classpath:logback-broken.xml" );
203
198
assertThatIllegalStateException ().isThrownBy (() -> {
204
- this .output .expect (containsString (
205
- "Logging system failed to initialize using configuration from 'classpath:logback-broken.xml'" ));
206
- this .output .expect (containsString ("ConsolAppender" ));
207
199
this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
200
+ assertThat (this .output ).contains (
201
+ "Logging system failed to initialize using configuration from 'classpath:logback-broken.xml'" );
202
+ assertThat (this .output ).contains ("ConsolAppender" );
208
203
});
209
204
}
210
205
@@ -246,7 +241,6 @@ public void addLogFilePropertyWithDefault() {
246
241
@ Test
247
242
@ Deprecated
248
243
public void addLogFilePropertyWithDefaultAndDeprecatedProperty () {
249
- assertThat (this .logFile ).doesNotExist ();
250
244
addPropertiesToEnvironment (this .context , "logging.file=" + this .logFile );
251
245
this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
252
246
Log logger = LogFactory .getLog (LoggingApplicationListenerTests .class );
@@ -284,8 +278,8 @@ public void parseDebugArg() {
284
278
this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
285
279
this .logger .debug ("testatdebug" );
286
280
this .logger .trace ("testattrace" );
287
- assertThat (this .output . toString () ).contains ("testatdebug" );
288
- assertThat (this .output . toString () ).doesNotContain ("testattrace" );
281
+ assertThat (this .output ).contains ("testatdebug" );
282
+ assertThat (this .output ).doesNotContain ("testattrace" );
289
283
}
290
284
291
285
@ Test
@@ -294,8 +288,8 @@ public void parseDebugArgExpandGroups() {
294
288
this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
295
289
this .loggerContext .getLogger ("org.springframework.boot.actuate.endpoint.web" ).debug ("testdebugwebgroup" );
296
290
this .loggerContext .getLogger ("org.hibernate.SQL" ).debug ("testdebugsqlgroup" );
297
- assertThat (this .output . toString () ).contains ("testdebugwebgroup" );
298
- assertThat (this .output . toString () ).contains ("testdebugsqlgroup" );
291
+ assertThat (this .output ).contains ("testdebugwebgroup" );
292
+ assertThat (this .output ).contains ("testdebugsqlgroup" );
299
293
}
300
294
301
295
@ Test
@@ -304,8 +298,8 @@ public void parseTraceArg() {
304
298
this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
305
299
this .logger .debug ("testatdebug" );
306
300
this .logger .trace ("testattrace" );
307
- assertThat (this .output . toString () ).contains ("testatdebug" );
308
- assertThat (this .output . toString () ).contains ("testattrace" );
301
+ assertThat (this .output ).contains ("testatdebug" );
302
+ assertThat (this .output ).contains ("testattrace" );
309
303
}
310
304
311
305
@ Test
@@ -323,8 +317,8 @@ private void disableDebugTraceArg(String... environment) {
323
317
this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
324
318
this .logger .debug ("testatdebug" );
325
319
this .logger .trace ("testattrace" );
326
- assertThat (this .output . toString () ).doesNotContain ("testatdebug" );
327
- assertThat (this .output . toString () ).doesNotContain ("testattrace" );
320
+ assertThat (this .output ).doesNotContain ("testatdebug" );
321
+ assertThat (this .output ).doesNotContain ("testattrace" );
328
322
}
329
323
330
324
@ Test
@@ -333,8 +327,8 @@ public void parseLevels() {
333
327
this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
334
328
this .logger .debug ("testatdebug" );
335
329
this .logger .trace ("testattrace" );
336
- assertThat (this .output . toString () ).contains ("testatdebug" );
337
- assertThat (this .output . toString () ).contains ("testattrace" );
330
+ assertThat (this .output ).contains ("testatdebug" );
331
+ assertThat (this .output ).contains ("testattrace" );
338
332
}
339
333
340
334
@ Test
@@ -343,8 +337,8 @@ public void parseLevelsCaseInsensitive() {
343
337
this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
344
338
this .logger .debug ("testatdebug" );
345
339
this .logger .trace ("testattrace" );
346
- assertThat (this .output . toString () ).contains ("testatdebug" );
347
- assertThat (this .output . toString () ).contains ("testattrace" );
340
+ assertThat (this .output ).contains ("testatdebug" );
341
+ assertThat (this .output ).contains ("testattrace" );
348
342
}
349
343
350
344
@ Test
@@ -353,8 +347,8 @@ public void parseLevelsTrimsWhitespace() {
353
347
this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
354
348
this .logger .debug ("testatdebug" );
355
349
this .logger .trace ("testattrace" );
356
- assertThat (this .output . toString () ).contains ("testatdebug" );
357
- assertThat (this .output . toString () ).contains ("testattrace" );
350
+ assertThat (this .output ).contains ("testatdebug" );
351
+ assertThat (this .output ).contains ("testattrace" );
358
352
}
359
353
360
354
@ Test
@@ -363,8 +357,8 @@ public void parseLevelsWithPlaceholder() {
363
357
this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
364
358
this .logger .debug ("testatdebug" );
365
359
this .logger .trace ("testattrace" );
366
- assertThat (this .output . toString () ).contains ("testatdebug" );
367
- assertThat (this .output . toString () ).contains ("testattrace" );
360
+ assertThat (this .output ).contains ("testatdebug" );
361
+ assertThat (this .output ).contains ("testattrace" );
368
362
}
369
363
370
364
@ Test
@@ -381,7 +375,7 @@ public void parseLevelsNone() {
381
375
this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
382
376
this .logger .debug ("testatdebug" );
383
377
this .logger .error ("testaterror" );
384
- assertThat (this .output . toString () ).doesNotContain ("testatdebug" ).doesNotContain ("testaterror" );
378
+ assertThat (this .output ).doesNotContain ("testatdebug" ).doesNotContain ("testaterror" );
385
379
}
386
380
387
381
@ Test
@@ -390,7 +384,7 @@ public void parseLevelsMapsFalseToOff() {
390
384
this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
391
385
this .logger .debug ("testatdebug" );
392
386
this .logger .error ("testaterror" );
393
- assertThat (this .output . toString () ).doesNotContain ("testatdebug" ).doesNotContain ("testaterror" );
387
+ assertThat (this .output ).doesNotContain ("testatdebug" ).doesNotContain ("testaterror" );
394
388
}
395
389
396
390
@ Test
@@ -399,7 +393,7 @@ public void parseArgsDisabled() {
399
393
addPropertiesToEnvironment (this .context , "debug" );
400
394
this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
401
395
this .logger .debug ("testatdebug" );
402
- assertThat (this .output . toString () ).doesNotContain ("testatdebug" );
396
+ assertThat (this .output ).doesNotContain ("testatdebug" );
403
397
}
404
398
405
399
@ Test
@@ -409,7 +403,7 @@ public void parseArgsDoesntReplace() {
409
403
multicastEvent (new ApplicationStartingEvent (this .springApplication , new String [] { "--debug" }));
410
404
this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
411
405
this .logger .debug ("testatdebug" );
412
- assertThat (this .output . toString () ).doesNotContain ("testatdebug" );
406
+ assertThat (this .output ).doesNotContain ("testatdebug" );
413
407
}
414
408
415
409
@ Test
@@ -422,18 +416,18 @@ public void bridgeHandlerLifecycle() {
422
416
@ Test
423
417
public void defaultExceptionConversionWord () {
424
418
this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
425
- this .output .expect (containsString ("Hello world" ));
426
- this .output .expect (not (containsString ("Wrapped by: java.lang.RuntimeException: Wrapper" )));
427
419
this .logger .info ("Hello world" , new RuntimeException ("Wrapper" , new RuntimeException ("Expected" )));
420
+ assertThat (this .output ).contains ("Hello world" );
421
+ assertThat (this .output ).doesNotContain ("Wrapped by: java.lang.RuntimeException: Wrapper" );
428
422
}
429
423
430
424
@ Test
431
425
public void overrideExceptionConversionWord () {
432
426
addPropertiesToEnvironment (this .context , "logging.exceptionConversionWord=%rEx" );
433
427
this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
434
- this .output .expect (containsString ("Hello world" ));
435
- this .output .expect (containsString ("Wrapped by: java.lang.RuntimeException: Wrapper" ));
436
428
this .logger .info ("Hello world" , new RuntimeException ("Wrapper" , new RuntimeException ("Expected" )));
429
+ assertThat (this .output ).contains ("Hello world" );
430
+ assertThat (this .output ).contains ("Wrapped by: java.lang.RuntimeException: Wrapper" );
437
431
}
438
432
439
433
@ Test
@@ -554,7 +548,7 @@ public void lowPriorityPropertySourceShouldNotOverrideRootLoggerConfig() {
554
548
propertySources .addLast (new MapPropertySource ("test2" , Collections .singletonMap ("logging.level.root" , "WARN" )));
555
549
this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
556
550
this .logger .debug ("testatdebug" );
557
- assertThat (this .output . toString () ).contains ("testatdebug" );
551
+ assertThat (this .output ).contains ("testatdebug" );
558
552
}
559
553
560
554
@ Test
@@ -670,11 +664,11 @@ void registerShutdownHook(Thread shutdownHook) {
670
664
671
665
}
672
666
673
- public static final class TestCleanupLoggingSystem extends LoggingSystem {
667
+ static final class TestCleanupLoggingSystem extends LoggingSystem {
674
668
675
669
private boolean cleanedUp = false ;
676
670
677
- public TestCleanupLoggingSystem (ClassLoader classLoader ) {
671
+ TestCleanupLoggingSystem (ClassLoader classLoader ) {
678
672
}
679
673
680
674
@ Override
0 commit comments