Polish
This commit is contained in:
parent
7052af97a6
commit
313b063aef
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2024 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -142,6 +142,7 @@ public class MockitoTestExecutionListener extends AbstractTestExecutionListener
|
||||||
private static final class MockitoAnnotationCollector implements FieldCallback {
|
private static final class MockitoAnnotationCollector implements FieldCallback {
|
||||||
|
|
||||||
private static final String MOCKITO_BEAN_PACKAGE = MockitoBean.class.getPackageName();
|
private static final String MOCKITO_BEAN_PACKAGE = MockitoBean.class.getPackageName();
|
||||||
|
|
||||||
private static final String ORG_MOCKITO_PACKAGE = "org.mockito";
|
private static final String ORG_MOCKITO_PACKAGE = "org.mockito";
|
||||||
|
|
||||||
private final Set<Annotation> annotations = new LinkedHashSet<>();
|
private final Set<Annotation> annotations = new LinkedHashSet<>();
|
||||||
|
|
|
||||||
|
|
@ -33,11 +33,12 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||||
*/
|
*/
|
||||||
@SpringJUnitConfig(MockitoBeanForByNameLookupIntegrationTests.Config.class)
|
@SpringJUnitConfig(MockitoBeanForByNameLookupIntegrationTests.Config.class)
|
||||||
@MockitoBeanSettings(Strictness.LENIENT)
|
@MockitoBeanSettings(Strictness.LENIENT)
|
||||||
public class MockitoBeanSettingsLenientIntegrationTests {
|
class MockitoBeanSettingsLenientIntegrationTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void unusedStubbingNotReported() {
|
@SuppressWarnings("rawtypes")
|
||||||
var list = Mockito.mock(List.class);
|
void unusedStubbingNotReported() {
|
||||||
|
List list = Mockito.mock(List.class);
|
||||||
Mockito.when(list.get(Mockito.anyInt())).thenReturn(new Object());
|
Mockito.when(list.get(Mockito.anyInt())).thenReturn(new Object());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,18 +47,11 @@ import static org.junit.platform.testkit.engine.TestExecutionResultConditions.me
|
||||||
* @author Simon Baslé
|
* @author Simon Baslé
|
||||||
* @since 6.2
|
* @since 6.2
|
||||||
*/
|
*/
|
||||||
public final class MockitoBeanSettingsStrictIntegrationTests {
|
class MockitoBeanSettingsStrictIntegrationTests {
|
||||||
|
|
||||||
private static Stream<Named<Class<?>>> strictCases() {
|
|
||||||
return Stream.of(
|
|
||||||
Named.of("explicit strictness", ExplicitStrictness.class),
|
|
||||||
Named.of("implicit strictness with @MockitoBean on field", ImplicitStrictnessWithMockitoBean.class)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("strictCases")
|
@MethodSource("strictCases")
|
||||||
public void unusedStubbingIsReported(Class<?> forCase) {
|
void unusedStubbingIsReported(Class<?> forCase) {
|
||||||
Events events = EngineTestKit.engine("junit-jupiter")
|
Events events = EngineTestKit.engine("junit-jupiter")
|
||||||
.selectors(selectClass(forCase))
|
.selectors(selectClass(forCase))
|
||||||
.execute()
|
.execute()
|
||||||
|
|
@ -72,10 +65,19 @@ public final class MockitoBeanSettingsStrictIntegrationTests {
|
||||||
message(msg -> msg.contains("Unnecessary stubbings detected.")))));
|
message(msg -> msg.contains("Unnecessary stubbings detected.")))));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Stream<Named<Class<?>>> strictCases() {
|
||||||
|
return Stream.of(
|
||||||
|
Named.of("explicit strictness", ExplicitStrictness.class),
|
||||||
|
Named.of("implicit strictness with @MockitoBean on field", ImplicitStrictnessWithMockitoBean.class)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
abstract static class BaseCase {
|
abstract static class BaseCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
void unnecessaryStub() {
|
void unnecessaryStub() {
|
||||||
var list = Mockito.mock(List.class);
|
List list = Mockito.mock(List.class);
|
||||||
Mockito.when(list.get(Mockito.anyInt())).thenReturn(new Object());
|
Mockito.when(list.get(Mockito.anyInt())).thenReturn(new Object());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,7 @@ class MockitoSpyBeanForBeanFactoryIntegrationTests {
|
||||||
assertThat(this.testFactoryBean.getObject()).isNotSameAs(this.testBean);
|
assertThat(this.testFactoryBean.getObject()).isNotSameAs(this.testBean);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
static class Config {
|
static class Config {
|
||||||
|
|
||||||
|
|
@ -67,10 +68,10 @@ class MockitoSpyBeanForBeanFactoryIntegrationTests {
|
||||||
TestFactoryBean testFactoryBean() {
|
TestFactoryBean testFactoryBean() {
|
||||||
return new TestFactoryBean();
|
return new TestFactoryBean();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static class TestBeanImpl implements TestBean {
|
static class TestBeanImpl implements TestBean {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String hello() {
|
public String hello() {
|
||||||
return "hi";
|
return "hi";
|
||||||
|
|
@ -88,7 +89,6 @@ class MockitoSpyBeanForBeanFactoryIntegrationTests {
|
||||||
public Class<?> getObjectType() {
|
public Class<?> getObjectType() {
|
||||||
return TestBean.class;
|
return TestBean.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue