Skip to content

Commit

Permalink
Fixes mockito#1853: Allow @MockitoSettings to be inherited
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianMendez committed Jan 2, 2020
1 parent 11552b8 commit 540c7c5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Expand Up @@ -7,6 +7,7 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.quality.Strictness;

import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;

import static java.lang.annotation.RetentionPolicy.RUNTIME;
Expand All @@ -15,6 +16,7 @@
* Annotation that can configure Mockito as invoked by the {@link MockitoExtension}.
*/
@ExtendWith(MockitoExtension.class)
@Inherited
@Retention(RUNTIME)
public @interface MockitoSettings {

Expand Down
Expand Up @@ -118,6 +118,26 @@ void by_default_configures_strict_stubs_in_runner() {
assertThat(result.getThrowable().get()).isInstanceOf(UnnecessaryStubbingException.class);
}

@MockitoSettings(strictness = Strictness.WARN)
static class BaseWarnStubs {}

static class InheritedWarnStubs extends BaseWarnStubs {
@Mock
private Function<Integer, String> rootMock;

@Test
void should_throw_an_exception_on_strict_stubs_configured_by_default() {
Mockito.when(rootMock.apply(10)).thenReturn("Foo");
}
}

@Test
void inherits_strictness_from_base_class() {
TestExecutionResult result = invokeTestClassAndRetrieveMethodResult(InheritedWarnStubs.class);

assertThat(result.getStatus()).isEqualTo(TestExecutionResult.Status.SUCCESSFUL);
}

private TestExecutionResult invokeTestClassAndRetrieveMethodResult(Class<?> clazz) {
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
.selectors(
Expand Down

0 comments on commit 540c7c5

Please sign in to comment.