Merge pull request #5836 from izeye/polish-20160502

* pr/5836:
  Polish
This commit is contained in:
Phillip Webb 2016-05-02 17:08:57 -07:00
commit 50de70e2eb
12 changed files with 29 additions and 34 deletions

View File

@ -105,7 +105,7 @@ public @interface MockBean {
* When {@code @MockBean} also defines a {@code name} this attribute can only contain * When {@code @MockBean} also defines a {@code name} this attribute can only contain
* a single value. * a single value.
* <p> * <p>
* If this is the only attribute specified consider using the {@code value} alias * If this is the only specified attribute consider using the {@code value} alias
* instead. * instead.
* @return the classes to mock * @return the classes to mock
*/ */

View File

@ -70,7 +70,7 @@ class MockDefinition extends Definition {
} }
/** /**
* Return the classes that should be mocked. * Return the class that should be mocked.
* @return the class to mock; never {@code null} * @return the class to mock; never {@code null}
*/ */
public Class<?> getClassToMock() { public Class<?> getClassToMock() {
@ -79,7 +79,7 @@ class MockDefinition extends Definition {
/** /**
* Return the extra interfaces. * Return the extra interfaces.
* @return the extra interfaces or an empty array * @return the extra interfaces or an empty set
*/ */
public Set<Class<?>> getExtraInterfaces() { public Set<Class<?>> getExtraInterfaces() {
return this.extraInterfaces; return this.extraInterfaces;
@ -87,7 +87,7 @@ class MockDefinition extends Definition {
/** /**
* Return the answers mode. * Return the answers mode.
* @return the answer the answers mode; never {@code null} * @return the answers mode; never {@code null}
*/ */
public Answers getAnswer() { public Answers getAnswer() {
return this.answer; return this.answer;

View File

@ -55,7 +55,7 @@ public enum MockReset {
private static final MockUtil util = new MockUtil(); private static final MockUtil util = new MockUtil();
/** /**
* Create {@link MockSettings settings} to be use used with mocks where reset should * Create {@link MockSettings settings} to be used with mocks where reset should
* occur before each test method runs. * occur before each test method runs.
* @return mock settings * @return mock settings
*/ */
@ -64,7 +64,7 @@ public enum MockReset {
} }
/** /**
* Create {@link MockSettings settings} to be use used with mocks where reset should * Create {@link MockSettings settings} to be used with mocks where reset should
* occur after each test method runs. * occur after each test method runs.
* @return mock settings * @return mock settings
*/ */
@ -73,7 +73,7 @@ public enum MockReset {
} }
/** /**
* Create {@link MockSettings settings} to be use used with mocks where a specific * Create {@link MockSettings settings} to be used with mocks where a specific
* reset should occur. * reset should occur.
* @param reset the reset type * @param reset the reset type
* @return mock settings * @return mock settings

View File

@ -33,7 +33,7 @@ class MockitoContextCustomizerFactory implements ContextCustomizerFactory {
public ContextCustomizer createContextCustomizer(Class<?> testClass, public ContextCustomizer createContextCustomizer(Class<?> testClass,
List<ContextConfigurationAttributes> configAttributes) { List<ContextConfigurationAttributes> configAttributes) {
// We gather the explicit mock definitions here since they form part of the // We gather the explicit mock definitions here since they form part of the
// MergedContextConfiguration key. Different mocks need to have a different key // MergedContextConfiguration key. Different mocks need to have a different key.
DefinitionsParser parser = new DefinitionsParser(); DefinitionsParser parser = new DefinitionsParser();
parser.parse(testClass); parser.parse(testClass);
return new MockitoContextCustomizer(parser.getDefinitions()); return new MockitoContextCustomizer(parser.getDefinitions());

View File

@ -114,7 +114,7 @@ public class MockitoPostProcessor extends InstantiationAwareBeanPostProcessorAda
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
throws BeansException { throws BeansException {
Assert.isInstanceOf(BeanDefinitionRegistry.class, beanFactory, Assert.isInstanceOf(BeanDefinitionRegistry.class, beanFactory,
"@RegisterMocks can only be used on bean factories that " "@MockBean can only be used on bean factories that "
+ "implement BeanDefinitionRegistry"); + "implement BeanDefinitionRegistry");
postProcessBeanFactory(beanFactory, (BeanDefinitionRegistry) beanFactory); postProcessBeanFactory(beanFactory, (BeanDefinitionRegistry) beanFactory);
} }

View File

@ -75,7 +75,7 @@ class MockitoTestExecutionListener extends AbstractTestExecutionListener {
} }
/** /**
* {@link FieldCallback} to collect mockito annotations. * {@link FieldCallback} to collect Mockito annotations.
*/ */
private static class MockitoAnnotationCollection implements FieldCallback { private static class MockitoAnnotationCollection implements FieldCallback {

View File

@ -102,7 +102,7 @@ public @interface SpyBean {
* When {@code @MockBean} also defines a {@code name} this attribute can only contain * When {@code @MockBean} also defines a {@code name} this attribute can only contain
* a single value. * a single value.
* <p> * <p>
* If this is the only attribute specified consider using the {@code value} alias * If this is the only specified attribute consider using the {@code value} alias
* instead. * instead.
* @return the classes to mock * @return the classes to mock
*/ */

View File

@ -38,28 +38,28 @@ public class MockitoContextCustomizerFactoryTests {
public void getContextCustomizerWithoutAnnotationReturnsCustomizer() public void getContextCustomizerWithoutAnnotationReturnsCustomizer()
throws Exception { throws Exception {
ContextCustomizer customizer = this.factory ContextCustomizer customizer = this.factory
.createContextCustomizer(NoRegisterMocksAnnotation.class, null); .createContextCustomizer(NoMockBeanAnnotation.class, null);
assertThat(customizer).isNotNull(); assertThat(customizer).isNotNull();
} }
@Test @Test
public void getContextCustomizerWithAnnotationReturnsCustomizer() throws Exception { public void getContextCustomizerWithAnnotationReturnsCustomizer() throws Exception {
ContextCustomizer customizer = this.factory ContextCustomizer customizer = this.factory
.createContextCustomizer(WithRegisterMocksAnnotation.class, null); .createContextCustomizer(WithMockBeanAnnotation.class, null);
assertThat(customizer).isNotNull(); assertThat(customizer).isNotNull();
} }
@Test @Test
public void getContextCustomizerUsesMocksAsCacheKey() throws Exception { public void getContextCustomizerUsesMocksAsCacheKey() throws Exception {
ContextCustomizer customizer = this.factory ContextCustomizer customizer = this.factory
.createContextCustomizer(WithRegisterMocksAnnotation.class, null); .createContextCustomizer(WithMockBeanAnnotation.class, null);
assertThat(customizer).isNotNull(); assertThat(customizer).isNotNull();
ContextCustomizer same = this.factory ContextCustomizer same = this.factory
.createContextCustomizer(WithSameRegisterMocksAnnotation.class, null); .createContextCustomizer(WithSameMockBeanAnnotation.class, null);
assertThat(customizer).isNotNull(); assertThat(customizer).isNotNull();
ContextCustomizer different = this.factory.createContextCustomizer( ContextCustomizer different = this.factory.createContextCustomizer(
WithDifferentRegisterMocksAnnotation.class, null); WithDifferentMockBeanAnnotation.class, null);
assertThat(customizer).isNotNull(); assertThat(different).isNotNull();
assertThat(customizer.hashCode()).isEqualTo(same.hashCode()); assertThat(customizer.hashCode()).isEqualTo(same.hashCode());
assertThat(customizer.hashCode()).isNotEqualTo(different.hashCode()); assertThat(customizer.hashCode()).isNotEqualTo(different.hashCode());
assertThat(customizer).isEqualTo(customizer); assertThat(customizer).isEqualTo(customizer);
@ -67,22 +67,22 @@ public class MockitoContextCustomizerFactoryTests {
assertThat(customizer).isNotEqualTo(different); assertThat(customizer).isNotEqualTo(different);
} }
static class NoRegisterMocksAnnotation { static class NoMockBeanAnnotation {
} }
@MockBean({ Service1.class, Service2.class }) @MockBean({ Service1.class, Service2.class })
static class WithRegisterMocksAnnotation { static class WithMockBeanAnnotation {
} }
@MockBean({ Service2.class, Service1.class }) @MockBean({ Service2.class, Service1.class })
static class WithSameRegisterMocksAnnotation { static class WithSameMockBeanAnnotation {
} }
@MockBean({ Service1.class }) @MockBean({ Service1.class })
static class WithDifferentRegisterMocksAnnotation { static class WithDifferentMockBeanAnnotation {
} }

View File

@ -62,16 +62,16 @@ public class MockitoInitializeTestExecutionListenerTests {
} }
@Test @Test
public void prepareTestInstanceShouldInitMockitoAnnotation() throws Exception { public void prepareTestInstanceShouldInitMockitoAnnotations() throws Exception {
WithMockitoAnnotation instance = new WithMockitoAnnotation(); WithMockitoAnnotations instance = new WithMockitoAnnotations();
this.listener.prepareTestInstance(mockTestContext(instance)); this.listener.prepareTestInstance(mockTestContext(instance));
assertThat(instance.mock).isNotNull(); assertThat(instance.mock).isNotNull();
assertThat(instance.captor).isNotNull(); assertThat(instance.captor).isNotNull();
} }
@Test @Test
public void prepareTestInstanceShouldInjectMockBeans() throws Exception { public void prepareTestInstanceShouldInjectMockBean() throws Exception {
WithMockBeans instance = new WithMockBeans(); WithMockBean instance = new WithMockBean();
this.listener.prepareTestInstance(mockTestContext(instance)); this.listener.prepareTestInstance(mockTestContext(instance));
verify(this.postProcessor).inject(this.fieldCaptor.capture(), eq(instance), verify(this.postProcessor).inject(this.fieldCaptor.capture(), eq(instance),
(MockDefinition) any()); (MockDefinition) any());
@ -87,7 +87,7 @@ public class MockitoInitializeTestExecutionListenerTests {
return testContext; return testContext;
} }
static class WithMockitoAnnotation { static class WithMockitoAnnotations {
@Mock @Mock
InputStream mock; InputStream mock;
@ -97,7 +97,7 @@ public class MockitoInitializeTestExecutionListenerTests {
} }
static class WithMockBeans { static class WithMockBean {
@MockBean @MockBean
InputStream mockBean; InputStream mockBean;

View File

@ -41,8 +41,6 @@ import static org.mockito.Mockito.mock;
@FixMethodOrder(MethodSorters.NAME_ASCENDING) @FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class ResetMocksTestExecutionListenerTests { public class ResetMocksTestExecutionListenerTests {
static boolean test001executed;
@Autowired @Autowired
private ApplicationContext context; private ApplicationContext context;
@ -51,7 +49,6 @@ public class ResetMocksTestExecutionListenerTests {
given(getMock("none").greeting()).willReturn("none"); given(getMock("none").greeting()).willReturn("none");
given(getMock("before").greeting()).willReturn("before"); given(getMock("before").greeting()).willReturn("before");
given(getMock("after").greeting()).willReturn("after"); given(getMock("after").greeting()).willReturn("after");
test001executed = true;
} }
@Test @Test

View File

@ -16,10 +16,8 @@
package org.springframework.boot.test.mock.mockito.example; package org.springframework.boot.test.mock.mockito.example;
import java.security.Provider.Service;
/** /**
* Example bean for mocking tests that calls {@link Service}. * Example bean for mocking tests that calls {@link ExampleService}.
* *
* @author Phillip Webb * @author Phillip Webb
*/ */

View File

@ -85,7 +85,7 @@ public class LocalHostWebConnectionHtmlUnitDriverTests {
} }
@Test @Test
public void getPageWhenUrlIsRelativeAndNoPortWillUseLocalhost8080() throws Exception { public void getWhenUrlIsRelativeAndNoPortWillUseLocalhost8080() throws Exception {
MockEnvironment environment = new MockEnvironment(); MockEnvironment environment = new MockEnvironment();
LocalHostWebConnectionHtmlUnitDriver driver = new TestLocalHostWebConnectionHtmlUnitDriver( LocalHostWebConnectionHtmlUnitDriver driver = new TestLocalHostWebConnectionHtmlUnitDriver(
environment); environment);