|
47 | 47 | import static java.nio.charset.StandardCharsets.UTF_8;
|
48 | 48 | import static java.util.Arrays.asList;
|
49 | 49 | import static org.hamcrest.Matchers.containsString;
|
| 50 | +import static org.hamcrest.Matchers.emptyString; |
50 | 51 | import static org.hamcrest.Matchers.equalTo;
|
51 | 52 | import static org.hamcrest.Matchers.greaterThan;
|
52 | 53 | import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
@@ -462,20 +463,29 @@ void testSlf4jLogging() throws Exception
|
462 | 463 | {
|
463 | 464 | // log file is defined in logback-test.xml configuration file
|
464 | 465 | Path logFile = Paths.get( "target", "test.log" );
|
465 |
| - Files.deleteIfExists( logFile ); |
| 466 | + if ( Files.exists( logFile ) ) |
| 467 | + { |
| 468 | + // delete file made this test flaky |
| 469 | + // erase content instead |
| 470 | + Files.write( logFile, new byte[0] ); |
| 471 | + } |
| 472 | + |
| 473 | + // verify erased |
| 474 | + String logFileContent = new String( Files.readAllBytes( logFile ), UTF_8 ); |
| 475 | + assertThat( logFileContent, is( emptyString() ) ); |
466 | 476 |
|
| 477 | + String randomString = UUID.randomUUID().toString(); |
467 | 478 | try ( Slf4jLoggingExample example = new Slf4jLoggingExample( uri, USER, PASSWORD ) )
|
468 | 479 | {
|
469 |
| - String randomString = UUID.randomUUID().toString(); |
470 | 480 | Object result = example.runReturnQuery( randomString );
|
471 | 481 | assertEquals( randomString, result );
|
| 482 | + } |
| 483 | + assertTrue( Files.exists( logFile ) ); |
472 | 484 |
|
473 |
| - assertTrue( Files.exists( logFile ) ); |
| 485 | + logFileContent = new String( Files.readAllBytes( logFile ), UTF_8 ); |
| 486 | + assertThat( logFileContent, containsString( "RETURN $x" ) ); |
| 487 | + assertThat( logFileContent, containsString( randomString ) ); |
474 | 488 |
|
475 |
| - String logFileContent = new String( Files.readAllBytes( logFile ), UTF_8 ); |
476 |
| - assertThat( logFileContent, containsString( "RETURN $x" ) ); |
477 |
| - assertThat( logFileContent, containsString( randomString ) ); |
478 |
| - } |
479 | 489 | }
|
480 | 490 |
|
481 | 491 | @Test
|
|
0 commit comments