@Test
void logsMessageWithStacktraceDuringFinalizationIfLeaked( TestInfo testInfo ) throws Exception
{

    Logging logging = mock( Logging.class );
    Logger log = mock( Logger.class );
    when( logging.getLog( anyString() ) ).thenReturn( log );
    LeakLoggingNetworkSession session = newSession( logging, true );
    // begin transaction to make session obtain a connection
    session.beginTransactionAsync( TransactionConfig.empty() );
    finalize( session );
    ArgumentCaptor<String> messageCaptor = ArgumentCaptor.forClass( String.class );
    verify( log ).error( messageCaptor.capture(), any() );
    assertEquals( 1, messageCaptor.getAllValues().size() );
    String loggedMessage = messageCaptor.getValue();
    assertThat( loggedMessage, containsString( "Neo4j Session object leaked" ) );
    assertThat( loggedMessage, containsString( "Session was create at" ) );
    assertThat( loggedMessage, containsString(
            getClass().getSimpleName() + "." + testInfo.getTestMethod().get().getName() )
    );
}