7272import static org .assertj .core .api .Assertions .assertThat ;
7373import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
7474import static org .assertj .core .api .Assertions .assertThatIllegalStateException ;
75- import static org .hamcrest .Matchers .containsString ;
76- import static org .hamcrest .Matchers .not ;
7775
7876/**
7977 * Tests for {@link LoggingApplicationListener} with Logback.
@@ -150,10 +148,10 @@ private String tmpDir() {
150148 @ Test
151149 public void baseConfigLocation () {
152150 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-" ));
156151 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-" );
157155 assertThat (new File (tmpDir () + "/spring.log" ).exists ()).isFalse ();
158156 }
159157
@@ -162,17 +160,16 @@ public void overrideConfigLocation() {
162160 addPropertiesToEnvironment (this .context , "logging.config=classpath:logback-nondefault.xml" );
163161 this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
164162 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" );
167164 }
168165
169166 @ Test
170167 public void overrideConfigDoesNotExist () {
171168 addPropertiesToEnvironment (this .context , "logging.config=doesnotexist.xml" );
172169 assertThatIllegalStateException ().isThrownBy (() -> {
173- this .output .expect (
174- containsString ("Logging system failed to initialize using configuration from 'doesnotexist.xml'" ));
175170 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'" );
176173 });
177174 }
178175
@@ -182,8 +179,7 @@ public void azureDefaultLoggingConfigDoesNotCauseAFailure() {
182179 "logging.config=-Djava.util.logging.config.file=\" d:\\ home\\ site\\ wwwroot\\ bin\\ apache-tomcat-7.0.52\\ conf\\ logging.properties\" " );
183180 this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
184181 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 ("???" );
187183 assertThat (new File (tmpDir () + "/spring.log" ).exists ()).isFalse ();
188184 }
189185
@@ -192,19 +188,18 @@ public void tomcatNopLoggingConfigDoesNotCauseAFailure() {
192188 addPropertiesToEnvironment (this .context , "LOGGING_CONFIG=-Dnop" );
193189 this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
194190 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 ("???" );
197192 assertThat (new File (tmpDir () + "/spring.log" ).exists ()).isFalse ();
198193 }
199194
200195 @ Test
201196 public void overrideConfigBroken () {
202197 addPropertiesToEnvironment (this .context , "logging.config=classpath:logback-broken.xml" );
203198 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" ));
207199 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" );
208203 });
209204 }
210205
@@ -246,7 +241,6 @@ public void addLogFilePropertyWithDefault() {
246241 @ Test
247242 @ Deprecated
248243 public void addLogFilePropertyWithDefaultAndDeprecatedProperty () {
249- assertThat (this .logFile ).doesNotExist ();
250244 addPropertiesToEnvironment (this .context , "logging.file=" + this .logFile );
251245 this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
252246 Log logger = LogFactory .getLog (LoggingApplicationListenerTests .class );
@@ -284,8 +278,8 @@ public void parseDebugArg() {
284278 this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
285279 this .logger .debug ("testatdebug" );
286280 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" );
289283 }
290284
291285 @ Test
@@ -294,8 +288,8 @@ public void parseDebugArgExpandGroups() {
294288 this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
295289 this .loggerContext .getLogger ("org.springframework.boot.actuate.endpoint.web" ).debug ("testdebugwebgroup" );
296290 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" );
299293 }
300294
301295 @ Test
@@ -304,8 +298,8 @@ public void parseTraceArg() {
304298 this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
305299 this .logger .debug ("testatdebug" );
306300 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" );
309303 }
310304
311305 @ Test
@@ -323,8 +317,8 @@ private void disableDebugTraceArg(String... environment) {
323317 this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
324318 this .logger .debug ("testatdebug" );
325319 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" );
328322 }
329323
330324 @ Test
@@ -333,8 +327,8 @@ public void parseLevels() {
333327 this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
334328 this .logger .debug ("testatdebug" );
335329 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" );
338332 }
339333
340334 @ Test
@@ -343,8 +337,8 @@ public void parseLevelsCaseInsensitive() {
343337 this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
344338 this .logger .debug ("testatdebug" );
345339 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" );
348342 }
349343
350344 @ Test
@@ -353,8 +347,8 @@ public void parseLevelsTrimsWhitespace() {
353347 this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
354348 this .logger .debug ("testatdebug" );
355349 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" );
358352 }
359353
360354 @ Test
@@ -363,8 +357,8 @@ public void parseLevelsWithPlaceholder() {
363357 this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
364358 this .logger .debug ("testatdebug" );
365359 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" );
368362 }
369363
370364 @ Test
@@ -381,7 +375,7 @@ public void parseLevelsNone() {
381375 this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
382376 this .logger .debug ("testatdebug" );
383377 this .logger .error ("testaterror" );
384- assertThat (this .output . toString () ).doesNotContain ("testatdebug" ).doesNotContain ("testaterror" );
378+ assertThat (this .output ).doesNotContain ("testatdebug" ).doesNotContain ("testaterror" );
385379 }
386380
387381 @ Test
@@ -390,7 +384,7 @@ public void parseLevelsMapsFalseToOff() {
390384 this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
391385 this .logger .debug ("testatdebug" );
392386 this .logger .error ("testaterror" );
393- assertThat (this .output . toString () ).doesNotContain ("testatdebug" ).doesNotContain ("testaterror" );
387+ assertThat (this .output ).doesNotContain ("testatdebug" ).doesNotContain ("testaterror" );
394388 }
395389
396390 @ Test
@@ -399,7 +393,7 @@ public void parseArgsDisabled() {
399393 addPropertiesToEnvironment (this .context , "debug" );
400394 this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
401395 this .logger .debug ("testatdebug" );
402- assertThat (this .output . toString () ).doesNotContain ("testatdebug" );
396+ assertThat (this .output ).doesNotContain ("testatdebug" );
403397 }
404398
405399 @ Test
@@ -409,7 +403,7 @@ public void parseArgsDoesntReplace() {
409403 multicastEvent (new ApplicationStartingEvent (this .springApplication , new String [] { "--debug" }));
410404 this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
411405 this .logger .debug ("testatdebug" );
412- assertThat (this .output . toString () ).doesNotContain ("testatdebug" );
406+ assertThat (this .output ).doesNotContain ("testatdebug" );
413407 }
414408
415409 @ Test
@@ -422,18 +416,18 @@ public void bridgeHandlerLifecycle() {
422416 @ Test
423417 public void defaultExceptionConversionWord () {
424418 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" )));
427419 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" );
428422 }
429423
430424 @ Test
431425 public void overrideExceptionConversionWord () {
432426 addPropertiesToEnvironment (this .context , "logging.exceptionConversionWord=%rEx" );
433427 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" ));
436428 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" );
437431 }
438432
439433 @ Test
@@ -554,7 +548,7 @@ public void lowPriorityPropertySourceShouldNotOverrideRootLoggerConfig() {
554548 propertySources .addLast (new MapPropertySource ("test2" , Collections .singletonMap ("logging.level.root" , "WARN" )));
555549 this .initializer .initialize (this .context .getEnvironment (), this .context .getClassLoader ());
556550 this .logger .debug ("testatdebug" );
557- assertThat (this .output . toString () ).contains ("testatdebug" );
551+ assertThat (this .output ).contains ("testatdebug" );
558552 }
559553
560554 @ Test
@@ -670,11 +664,11 @@ void registerShutdownHook(Thread shutdownHook) {
670664
671665 }
672666
673- public static final class TestCleanupLoggingSystem extends LoggingSystem {
667+ static final class TestCleanupLoggingSystem extends LoggingSystem {
674668
675669 private boolean cleanedUp = false ;
676670
677- public TestCleanupLoggingSystem (ClassLoader classLoader ) {
671+ TestCleanupLoggingSystem (ClassLoader classLoader ) {
678672 }
679673
680674 @ Override
0 commit comments