Polish
This commit is contained in:
parent
6ec1ac0aa0
commit
04448d6bd9
|
|
@ -38,7 +38,8 @@ abstract class Definition {
|
|||
|
||||
private final boolean proxyTargetAware;
|
||||
|
||||
Definition(AnnotatedElement element, String name, MockReset reset, boolean proxyTargetAware) {
|
||||
Definition(AnnotatedElement element, String name, MockReset reset,
|
||||
boolean proxyTargetAware) {
|
||||
this.element = element;
|
||||
this.name = name;
|
||||
this.reset = (reset != null ? reset : MockReset.AFTER);
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ class DefinitionsParser {
|
|||
}
|
||||
for (ResolvableType typeToMock : typesToMock) {
|
||||
MockDefinition definition = new MockDefinition(element, annotation.name(),
|
||||
typeToMock, annotation.extraInterfaces(), annotation.answer(),
|
||||
typeToMock, annotation.extraInterfaces(), annotation.answer(),
|
||||
annotation.serializable(), annotation.reset());
|
||||
addDefinition(definition, "mock");
|
||||
}
|
||||
|
|
@ -113,8 +113,7 @@ class DefinitionsParser {
|
|||
}
|
||||
}
|
||||
|
||||
private void addDefinition(Definition definition,
|
||||
String type) {
|
||||
private void addDefinition(Definition definition, String type) {
|
||||
boolean isNewDefinition = this.definitions.add(definition);
|
||||
Assert.state(isNewDefinition, "Duplicate " + type + " definition " + definition);
|
||||
AnnotatedElement element = definition.getElement();
|
||||
|
|
|
|||
|
|
@ -66,8 +66,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||
*
|
||||
*
|
||||
* }
|
||||
* </pre>
|
||||
* If there is more than one bean of the requested type, qualifier metadata must be
|
||||
* </pre> If there is more than one bean of the requested type, qualifier metadata must be
|
||||
* specified at field level: <pre class="code">
|
||||
* @RunWith(SpringRunner.class)
|
||||
* public class ExampleTests {
|
||||
|
|
|
|||
|
|
@ -50,8 +50,9 @@ class MockDefinition extends Definition {
|
|||
|
||||
private final boolean serializable;
|
||||
|
||||
MockDefinition(AnnotatedElement element, String name, ResolvableType typeToMock, Class<?>[] extraInterfaces,
|
||||
Answers answer, boolean serializable, MockReset reset) {
|
||||
MockDefinition(AnnotatedElement element, String name, ResolvableType typeToMock,
|
||||
Class<?>[] extraInterfaces, Answers answer, boolean serializable,
|
||||
MockReset reset) {
|
||||
super(element, name, reset, false);
|
||||
Assert.notNull(typeToMock, "TypeToMock must not be null");
|
||||
this.typeToMock = typeToMock;
|
||||
|
|
|
|||
|
|
@ -66,8 +66,7 @@ import org.springframework.test.context.junit4.SpringRunner;
|
|||
*
|
||||
*
|
||||
* }
|
||||
* </pre>
|
||||
* If there is more than one bean of the requested type, qualifier metadata must be
|
||||
* </pre> If there is more than one bean of the requested type, qualifier metadata must be
|
||||
* specified at field level: <pre class="code">
|
||||
* @RunWith(SpringRunner.class)
|
||||
* public class ExampleTests {
|
||||
|
|
|
|||
|
|
@ -82,8 +82,7 @@ public class DefinitionsParserTests {
|
|||
this.parser.parse(MockBeanOnClassAndField.class);
|
||||
assertThat(getDefinitions()).hasSize(2);
|
||||
MockDefinition classDefinition = getMockDefinition(0);
|
||||
assertThat(classDefinition.getElement())
|
||||
.isEqualTo(MockBeanOnClassAndField.class);
|
||||
assertThat(classDefinition.getElement()).isEqualTo(MockBeanOnClassAndField.class);
|
||||
assertThat(classDefinition.getTypeToMock().resolve())
|
||||
.isEqualTo(ExampleService.class);
|
||||
MockDefinition fieldDefinition = getMockDefinition(1);
|
||||
|
|
@ -161,8 +160,7 @@ public class DefinitionsParserTests {
|
|||
this.parser.parse(SpyBeanOnClassAndField.class);
|
||||
assertThat(getDefinitions()).hasSize(2);
|
||||
SpyDefinition classDefinition = getSpyDefinition(0);
|
||||
assertThat(classDefinition.getElement())
|
||||
.isEqualTo(SpyBeanOnClassAndField.class);
|
||||
assertThat(classDefinition.getElement()).isEqualTo(SpyBeanOnClassAndField.class);
|
||||
assertThat(classDefinition.getTypeToSpy().resolve())
|
||||
.isEqualTo(RealExampleService.class);
|
||||
SpyDefinition fieldDefinition = getSpyDefinition(1);
|
||||
|
|
|
|||
|
|
@ -34,8 +34,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* Test {@link MockBean} on a test class field can be used to replace existing bean
|
||||
* while preserving qualifiers.
|
||||
* Test {@link MockBean} on a test class field can be used to replace existing bean while
|
||||
* preserving qualifiers.
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
public class MockBeanOnTestFieldForExistingBeanWithQualifierIntegrationTests {
|
||||
|
|
@ -59,8 +59,8 @@ public class MockBeanOnTestFieldForExistingBeanWithQualifierIntegrationTests {
|
|||
@Test
|
||||
public void onlyQualifiedBeanIsReplaced() {
|
||||
assertThat(this.applicationContext.getBean("service")).isSameAs(this.service);
|
||||
ExampleService anotherService = this.applicationContext.getBean(
|
||||
"anotherService", ExampleService.class);
|
||||
ExampleService anotherService = this.applicationContext.getBean("anotherService",
|
||||
ExampleService.class);
|
||||
assertThat(anotherService.greeting()).isEqualTo("Another");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -65,8 +65,7 @@ public class MockDefinitionTests {
|
|||
@Test
|
||||
public void createExplicit() throws Exception {
|
||||
MockDefinition definition = new MockDefinition(getClass(), "name",
|
||||
EXAMPLE_SERVICE_TYPE,
|
||||
new Class<?>[] { ExampleExtraInterface.class },
|
||||
EXAMPLE_SERVICE_TYPE, new Class<?>[] { ExampleExtraInterface.class },
|
||||
Answers.RETURNS_SMART_NULLS, true, MockReset.BEFORE);
|
||||
assertThat(definition.getElement()).isEqualTo(getClass());
|
||||
assertThat(definition.getName()).isEqualTo("name");
|
||||
|
|
@ -81,8 +80,7 @@ public class MockDefinitionTests {
|
|||
|
||||
@Test
|
||||
public void createMock() throws Exception {
|
||||
MockDefinition definition = new MockDefinition(null, "name",
|
||||
EXAMPLE_SERVICE_TYPE,
|
||||
MockDefinition definition = new MockDefinition(null, "name", EXAMPLE_SERVICE_TYPE,
|
||||
new Class<?>[] { ExampleExtraInterface.class },
|
||||
Answers.RETURNS_SMART_NULLS, true, MockReset.BEFORE);
|
||||
ExampleService mock = definition.createMock();
|
||||
|
|
|
|||
|
|
@ -53,7 +53,8 @@ public class MockitoContextCustomizerTests {
|
|||
}
|
||||
|
||||
private MockDefinition createTestMockDefinition(Class<?> typeToMock) {
|
||||
return new MockDefinition(null, null, ResolvableType.forClass(typeToMock), null, null, false, null);
|
||||
return new MockDefinition(null, null, ResolvableType.forClass(typeToMock), null,
|
||||
null, false, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,8 @@ public class SpyDefinitionTests {
|
|||
|
||||
@Test
|
||||
public void createWithDefaults() throws Exception {
|
||||
SpyDefinition definition = new SpyDefinition(null, null, REAL_SERVICE_TYPE, null, true);
|
||||
SpyDefinition definition = new SpyDefinition(null, null, REAL_SERVICE_TYPE, null,
|
||||
true);
|
||||
assertThat(definition.getElement()).isNull();
|
||||
assertThat(definition.getName()).isNull();
|
||||
assertThat(definition.getTypeToSpy()).isEqualTo(REAL_SERVICE_TYPE);
|
||||
|
|
|
|||
Loading…
Reference in New Issue