Replace EasyMock with Mockito in test sources
Issue: SPR-10126
This commit is contained in:
committed by
Chris Beams
parent
cbf6991d47
commit
d66c733ef4
@@ -16,8 +16,8 @@
|
||||
|
||||
package org.springframework.beans.factory.config;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -45,24 +45,20 @@ public final class CustomScopeConfigurerTests {
|
||||
|
||||
@Test
|
||||
public void testWithNoScopes() throws Exception {
|
||||
Scope scope = createMock(Scope.class);
|
||||
replay(scope);
|
||||
Scope scope = mock(Scope.class);
|
||||
CustomScopeConfigurer figurer = new CustomScopeConfigurer();
|
||||
figurer.postProcessBeanFactory(factory);
|
||||
verify(scope);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSunnyDayWithBonaFideScopeInstance() throws Exception {
|
||||
Scope scope = createMock(Scope.class);
|
||||
replay(scope);
|
||||
Scope scope = mock(Scope.class);
|
||||
factory.registerScope(FOO_SCOPE, scope);
|
||||
Map<String, Object> scopes = new HashMap<String, Object>();
|
||||
scopes.put(FOO_SCOPE, scope);
|
||||
CustomScopeConfigurer figurer = new CustomScopeConfigurer();
|
||||
figurer.setScopes(scopes);
|
||||
figurer.postProcessBeanFactory(factory);
|
||||
verify(scope);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -19,9 +19,11 @@ package org.springframework.beans.factory.config;
|
||||
import java.util.Date;
|
||||
import javax.inject.Provider;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import org.junit.After;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import static test.util.TestResourceUtils.*;
|
||||
@@ -105,9 +107,8 @@ public class ObjectFactoryCreatingFactoryBeanTests {
|
||||
final String targetBeanName = "singleton";
|
||||
final String expectedSingleton = "Alicia Keys";
|
||||
|
||||
BeanFactory beanFactory = createMock(BeanFactory.class);
|
||||
expect(beanFactory.getBean(targetBeanName)).andReturn(expectedSingleton);
|
||||
replay(beanFactory);
|
||||
BeanFactory beanFactory = mock(BeanFactory.class);
|
||||
given(beanFactory.getBean(targetBeanName)).willReturn(expectedSingleton);
|
||||
|
||||
ObjectFactoryCreatingFactoryBean factory = new ObjectFactoryCreatingFactoryBean();
|
||||
factory.setTargetBeanName(targetBeanName);
|
||||
@@ -116,8 +117,6 @@ public class ObjectFactoryCreatingFactoryBeanTests {
|
||||
ObjectFactory<?> objectFactory = factory.getObject();
|
||||
Object actualSingleton = objectFactory.getObject();
|
||||
assertSame(expectedSingleton, actualSingleton);
|
||||
|
||||
verify(beanFactory);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
package org.springframework.beans.factory.config;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.springframework.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -269,17 +269,13 @@ public final class ServiceLocatorFactoryBeanTests {
|
||||
|
||||
@Test
|
||||
public void testRequiresListableBeanFactoryAndChokesOnAnythingElse() throws Exception {
|
||||
final BeanFactory beanFactory = createMock(BeanFactory.class);
|
||||
replay(beanFactory);
|
||||
|
||||
BeanFactory beanFactory = mock(BeanFactory.class);
|
||||
try {
|
||||
ServiceLocatorFactoryBean factory = new ServiceLocatorFactoryBean();
|
||||
factory.setBeanFactory(beanFactory);
|
||||
} catch (FatalBeanException ex) {
|
||||
// expected
|
||||
}
|
||||
|
||||
verify(beanFactory);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,10 @@
|
||||
|
||||
package org.springframework.beans.factory.parsing;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.isA;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.junit.Test;
|
||||
@@ -41,15 +44,13 @@ public final class FailFastProblemReporterTests {
|
||||
Problem problem = new Problem("VGER", new Location(new DescriptiveResource("here")),
|
||||
null, new IllegalArgumentException());
|
||||
|
||||
Log log = createMock(Log.class);
|
||||
log.warn(anyObject(), isA(IllegalArgumentException.class));
|
||||
replay(log);
|
||||
Log log = mock(Log.class);
|
||||
|
||||
FailFastProblemReporter reporter = new FailFastProblemReporter();
|
||||
reporter.setLogger(log);
|
||||
reporter.warning(problem);
|
||||
|
||||
verify(log);
|
||||
verify(log).warn(any(), isA(IllegalArgumentException.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,8 +30,9 @@ import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import test.beans.GenericBean;
|
||||
import test.beans.GenericIntegerBean;
|
||||
import test.beans.GenericSetOfIntegerBean;
|
||||
@@ -626,10 +627,10 @@ public class BeanFactoryGenericsTests {
|
||||
|
||||
/**
|
||||
* Tests support for parameterized {@code factory-method} declarations such
|
||||
* as EasyMock's {@code createMock()} method which has the following signature.
|
||||
* as Mockito {@code mock()} method which has the following signature.
|
||||
*
|
||||
* <pre>{@code
|
||||
* public static <T> T createMock(Class<T> toMock)
|
||||
* public static <T> T mock(Class<T> classToMock)
|
||||
* }</pre>
|
||||
*
|
||||
* See SPR-9493
|
||||
@@ -637,12 +638,12 @@ public class BeanFactoryGenericsTests {
|
||||
*/
|
||||
@Test
|
||||
public void parameterizedFactoryMethod() {
|
||||
RootBeanDefinition rbd = new RootBeanDefinition(EasyMock.class);
|
||||
rbd.setFactoryMethodName("createMock");
|
||||
RootBeanDefinition rbd = new RootBeanDefinition(Mockito.class);
|
||||
rbd.setFactoryMethodName("mock");
|
||||
rbd.getConstructorArgumentValues().addGenericArgumentValue(Runnable.class);
|
||||
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.registerBeanDefinition("easyMock", rbd);
|
||||
bf.registerBeanDefinition("mock", rbd);
|
||||
|
||||
Map<String, Runnable> beans = bf.getBeansOfType(Runnable.class);
|
||||
assertEquals(1, beans.size());
|
||||
|
||||
@@ -16,8 +16,10 @@
|
||||
|
||||
package org.springframework.beans.factory.wiring;
|
||||
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import junit.framework.TestCase;
|
||||
import org.easymock.MockControl;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
@@ -32,31 +34,24 @@ import test.beans.TestBean;
|
||||
public class BeanConfigurerSupportTests extends TestCase {
|
||||
|
||||
public void testSupplyIncompatibleBeanFactoryImplementation() throws Exception {
|
||||
MockControl mock = MockControl.createControl(BeanFactory.class);
|
||||
mock.replay();
|
||||
try {
|
||||
new StubBeanConfigurerSupport().setBeanFactory((BeanFactory) mock.getMock());
|
||||
new StubBeanConfigurerSupport().setBeanFactory(mock(BeanFactory.class));
|
||||
fail("Must have thrown an IllegalArgumentException by this point (incompatible BeanFactory implementation supplied)");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
}
|
||||
mock.verify();
|
||||
}
|
||||
|
||||
public void testConfigureBeanDoesNothingIfBeanWiringInfoResolverResolvesToNull() throws Exception {
|
||||
TestBean beanInstance = new TestBean();
|
||||
|
||||
MockControl mock = MockControl.createControl(BeanWiringInfoResolver.class);
|
||||
BeanWiringInfoResolver resolver = (BeanWiringInfoResolver) mock.getMock();
|
||||
resolver.resolveWiringInfo(beanInstance);
|
||||
mock.setReturnValue(null);
|
||||
mock.replay();
|
||||
BeanWiringInfoResolver resolver = mock(BeanWiringInfoResolver.class);
|
||||
|
||||
BeanConfigurerSupport configurer = new StubBeanConfigurerSupport();
|
||||
configurer.setBeanWiringInfoResolver(resolver);
|
||||
configurer.setBeanFactory(new DefaultListableBeanFactory());
|
||||
configurer.configureBean(beanInstance);
|
||||
mock.verify();
|
||||
verify(resolver).resolveWiringInfo(beanInstance);
|
||||
assertNull(beanInstance.getName());
|
||||
}
|
||||
|
||||
@@ -91,19 +86,14 @@ public class BeanConfigurerSupportTests extends TestCase {
|
||||
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
|
||||
factory.registerBeanDefinition("spouse", builder.getBeanDefinition());
|
||||
|
||||
MockControl mock = MockControl.createControl(BeanWiringInfoResolver.class);
|
||||
BeanWiringInfoResolver resolver = (BeanWiringInfoResolver) mock.getMock();
|
||||
resolver.resolveWiringInfo(beanInstance);
|
||||
mock.setReturnValue(new BeanWiringInfo(BeanWiringInfo.AUTOWIRE_BY_NAME, false));
|
||||
mock.replay();
|
||||
BeanWiringInfoResolver resolver = mock(BeanWiringInfoResolver.class);
|
||||
given(resolver.resolveWiringInfo(beanInstance)).willReturn(new BeanWiringInfo(BeanWiringInfo.AUTOWIRE_BY_NAME, false));
|
||||
|
||||
BeanConfigurerSupport configurer = new StubBeanConfigurerSupport();
|
||||
configurer.setBeanFactory(factory);
|
||||
configurer.setBeanWiringInfoResolver(resolver);
|
||||
configurer.configureBean(beanInstance);
|
||||
assertEquals("Bean is evidently not being configured (for some reason)", "David Gavurin", beanInstance.getSpouse().getName());
|
||||
|
||||
mock.verify();
|
||||
}
|
||||
|
||||
public void testConfigureBeanPerformsAutowiringByTypeIfAppropriateBeanWiringInfoResolverIsPluggedIn() throws Exception {
|
||||
@@ -115,19 +105,14 @@ public class BeanConfigurerSupportTests extends TestCase {
|
||||
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
|
||||
factory.registerBeanDefinition("Mmm, I fancy a salad!", builder.getBeanDefinition());
|
||||
|
||||
MockControl mock = MockControl.createControl(BeanWiringInfoResolver.class);
|
||||
BeanWiringInfoResolver resolver = (BeanWiringInfoResolver) mock.getMock();
|
||||
resolver.resolveWiringInfo(beanInstance);
|
||||
mock.setReturnValue(new BeanWiringInfo(BeanWiringInfo.AUTOWIRE_BY_TYPE, false));
|
||||
mock.replay();
|
||||
BeanWiringInfoResolver resolver = mock(BeanWiringInfoResolver.class);
|
||||
given(resolver.resolveWiringInfo(beanInstance)).willReturn(new BeanWiringInfo(BeanWiringInfo.AUTOWIRE_BY_TYPE, false));
|
||||
|
||||
BeanConfigurerSupport configurer = new StubBeanConfigurerSupport();
|
||||
configurer.setBeanFactory(factory);
|
||||
configurer.setBeanWiringInfoResolver(resolver);
|
||||
configurer.configureBean(beanInstance);
|
||||
assertEquals("Bean is evidently not being configured (for some reason)", "David Gavurin", beanInstance.getSpouse().getName());
|
||||
|
||||
mock.verify();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user