Search in sources :

Example 1 with TrackLogRecords

use of org.junit.jupiter.api.fixtures.TrackLogRecords in project junit5 by junit-team.

the class JupiterEngineExecutionContextTests method closeAttemptExceptionWillBeThrownDownTheCallStack.

@Test
@TrackLogRecords
void closeAttemptExceptionWillBeThrownDownTheCallStack(LogRecordListener logRecordListener) throws Exception {
    ExtensionContext failingExtensionContext = mock(ExtensionContext.class, withSettings().extraInterfaces(AutoCloseable.class));
    Exception expectedException = new Exception("test message");
    doThrow(expectedException).when(((AutoCloseable) failingExtensionContext)).close();
    JupiterEngineExecutionContext newContext = // 
    originalContext.extend().withExtensionContext(// 
    failingExtensionContext).build();
    Exception actualException = assertThrows(Exception.class, newContext::close);
    assertSame(expectedException, actualException);
    // 
    assertThat(logRecordListener.stream(JupiterEngineExecutionContext.class, Level.SEVERE)).extracting(// 
    LogRecord::getMessage).containsOnly("Caught exception while closing extension context: " + failingExtensionContext);
}
Also used : ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) Test(org.junit.jupiter.api.Test) TrackLogRecords(org.junit.jupiter.api.fixtures.TrackLogRecords)

Example 2 with TrackLogRecords

use of org.junit.jupiter.api.fixtures.TrackLogRecords in project junit5 by junit-team.

the class DefaultLauncherTests method thirdPartyEngineUsingReservedEngineIdPrefixEmitsWarning.

@Test
@TrackLogRecords
void thirdPartyEngineUsingReservedEngineIdPrefixEmitsWarning(LogRecordListener listener) {
    var id = "junit-using-reserved-prefix";
    createLauncher(new TestEngineStub(id));
    // 
    assertThat(listener.stream(EngineIdValidator.class, Level.WARNING).map(LogRecord::getMessage)).containsExactly("Third-party TestEngine implementations are forbidden to use the reserved 'junit-' prefix for their ID: '" + id + "'");
}
Also used : LogRecord(java.util.logging.LogRecord) TestEngineStub(org.junit.platform.fakes.TestEngineStub) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) TrackLogRecords(org.junit.jupiter.api.fixtures.TrackLogRecords)

Aggregations

Test (org.junit.jupiter.api.Test)2 TrackLogRecords (org.junit.jupiter.api.fixtures.TrackLogRecords)2 LogRecord (java.util.logging.LogRecord)1 ExtensionContext (org.junit.jupiter.api.extension.ExtensionContext)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 TestEngineStub (org.junit.platform.fakes.TestEngineStub)1