Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,16 @@ private Optional<MockitoSettings> retrieveAnnotationFromTestClasses(
@Override
@SuppressWarnings("unchecked")
public void afterEach(ExtensionContext context) {
context.getStore(MOCKITO)
.remove(MOCKS, Set.class)
.forEach(mock -> ((ScopedMock) mock).closeOnDemand());
context.getStore(MOCKITO)
.remove(SESSION, MockitoSession.class)
.finishMocking(context.getExecutionException().orElse(null));
ExtensionContext.Store store = context.getStore(MOCKITO);

Optional.ofNullable(store.remove(MOCKS, Set.class))
.ifPresent(mocks -> mocks.forEach(mock -> ((ScopedMock) mock).closeOnDemand()));

Optional.ofNullable(store.remove(SESSION, MockitoSession.class))
.ifPresent(
session ->
session.finishMocking(
context.getExecutionException().orElse(null)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (c) 2018 Mockito contributors
* This program is made available under the terms of the MIT License.
*/
package org.mockitousage;

import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.mockito.junit.jupiter.MockitoExtension;
import org.opentest4j.TestAbortedException;

class JunitJupiterSkippedTest {
@Nested
class NestedSkipBeforeEachMockito {
@Test
@ExtendWith({SkipTestBeforeEachExtension.class, MockitoExtension.class})
void should_handle_skip_in_before_each() {}

@Test
@ExtendWith({MockitoExtension.class, SkipTestBeforeEachExtension.class})
void should_handle_skip_after_before_each() {}

@Test
@ExtendWith(MockitoExtension.class)
void should_handle_skip_in_test() {
skipTest();
}
}

@Nested
@ExtendWith({SkipTestBeforeAllExtension.class, MockitoExtension.class})
class NestedSkipBeforeAllSkipThenMockito {
@Test
void should_handle_skip_in_before_all() {}
}

@Nested
@ExtendWith({MockitoExtension.class, SkipTestBeforeAllExtension.class})
class NestedSkipBeforeAllMockitoThenSkip {
@Test
void should_handle_skip_in_before_all() {}
}

private static class SkipTestBeforeEachExtension implements BeforeEachCallback {
@Override
public void beforeEach(ExtensionContext context) {
skipTest();
}
}

private static class SkipTestBeforeAllExtension implements BeforeAllCallback {
@Override
public void beforeAll(ExtensionContext context) {
skipTest();
}
}

private static void skipTest() {
throw new TestAbortedException("Skipped test");
}
}