Remove dependency to EasyMock. Rework a single test to Mockito based
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/10207bfc Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/10207bfc Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/10207bfc Branch: refs/heads/master Commit: 10207bfccee2000f64676fcb939bca4247340e84 Parents: 6611bfc Author: Martin Tzvetanov Grigorov <[email protected]> Authored: Wed Sep 10 12:47:21 2014 +0300 Committer: Martin Tzvetanov Grigorov <[email protected]> Committed: Wed Sep 10 12:47:21 2014 +0300 ---------------------------------------------------------------------- pom.xml | 6 --- wicket-ioc/pom.xml | 4 +- .../CompoundFieldValueFactoryTest.java | 45 +++++++++++--------- wicket-spring/pom.xml | 4 -- 4 files changed, 28 insertions(+), 31 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/wicket/blob/10207bfc/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index b29b84d..0d66eb2 100644 --- a/pom.xml +++ b/pom.xml @@ -491,12 +491,6 @@ <version>3.0</version> </dependency> <dependency> - <groupId>org.easymock</groupId> - <artifactId>easymock</artifactId> - <version>3.2</version> - <scope>test</scope> - </dependency> - <dependency> <groupId>org.httpunit</groupId> <artifactId>httpunit</artifactId> <version>1.7.2</version> http://git-wip-us.apache.org/repos/asf/wicket/blob/10207bfc/wicket-ioc/pom.xml ---------------------------------------------------------------------- diff --git a/wicket-ioc/pom.xml b/wicket-ioc/pom.xml index 3cd76cd..7391f9b 100644 --- a/wicket-ioc/pom.xml +++ b/wicket-ioc/pom.xml @@ -49,8 +49,8 @@ <artifactId>javax.inject</artifactId> </dependency> <dependency> - <groupId>org.easymock</groupId> - <artifactId>easymock</artifactId> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> </dependency> </dependencies> <build> http://git-wip-us.apache.org/repos/asf/wicket/blob/10207bfc/wicket-ioc/src/test/java/org/apache/wicket/injection/CompoundFieldValueFactoryTest.java ---------------------------------------------------------------------- diff --git a/wicket-ioc/src/test/java/org/apache/wicket/injection/CompoundFieldValueFactoryTest.java b/wicket-ioc/src/test/java/org/apache/wicket/injection/CompoundFieldValueFactoryTest.java index 8db6ea5..f4eadbf 100644 --- a/wicket-ioc/src/test/java/org/apache/wicket/injection/CompoundFieldValueFactoryTest.java +++ b/wicket-ioc/src/test/java/org/apache/wicket/injection/CompoundFieldValueFactoryTest.java @@ -16,12 +16,16 @@ */ package org.apache.wicket.injection; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + import java.lang.reflect.Field; import java.util.Arrays; import java.util.List; -import org.easymock.EasyMock; -import org.easymock.IMocksControl; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -38,8 +42,6 @@ public class CompoundFieldValueFactoryTest extends Assert private Field field; - private final IMocksControl[] ctrl = new IMocksControl[4]; - private final IFieldValueFactory[] fact = new IFieldValueFactory[4]; /** @@ -53,8 +55,7 @@ public class CompoundFieldValueFactoryTest extends Assert for (int i = 0; i < 4; i++) { - ctrl[i] = EasyMock.createControl(); - fact[i] = ctrl[i].createMock(IFieldValueFactory.class); + fact[i] = mock(IFieldValueFactory.class); } } @@ -62,16 +63,23 @@ public class CompoundFieldValueFactoryTest extends Assert { for (int i = 0; i < cnt; i++) { - EasyMock.expect(fact[i].getFieldValue(field, this)).andReturn(null); - ctrl[i].replay(); + when(fact[i].getFieldValue(field, this)).thenReturn(null); } } - protected void verify(final int cnt) + protected void verifyCalled(int... indices) { - for (int i = 0; i < cnt; i++) + for (int i : indices) + { + verify(fact[i], times(1)).getFieldValue(field, this); + } + } + + private void verifyNotCalled(int... indices) + { + for (int i : indices) { - ctrl[i].verify(); + verify(fact[i], never()).getFieldValue(field, this); } } @@ -85,7 +93,7 @@ public class CompoundFieldValueFactoryTest extends Assert CompoundFieldValueFactory f = new CompoundFieldValueFactory(new IFieldValueFactory[] { fact[0], fact[1] }); f.getFieldValue(field, this); - verify(2); + verifyCalled(0, 1); try { @@ -108,7 +116,7 @@ public class CompoundFieldValueFactoryTest extends Assert List<IFieldValueFactory> list = Arrays.asList(fact[0], fact[1], fact[2], fact[3]); CompoundFieldValueFactory f = new CompoundFieldValueFactory(list); f.getFieldValue(field, this); - verify(4); + verifyCalled(0, 1, 2, 3); try { @@ -131,7 +139,7 @@ public class CompoundFieldValueFactoryTest extends Assert prepare(2); CompoundFieldValueFactory f = new CompoundFieldValueFactory(fact[0], fact[1]); f.getFieldValue(field, this); - verify(2); + verifyCalled(0, 1); try { @@ -161,15 +169,14 @@ public class CompoundFieldValueFactoryTest extends Assert public void testBreakOnNonNullReturn() { prepare(2); - EasyMock.expect(fact[2].getFieldValue(field, this)).andReturn(new Object()); - ctrl[2].replay(); - ctrl[3].replay(); + when(fact[2].getFieldValue(field, this)).thenReturn(new Object()); List<IFieldValueFactory> list = Arrays.asList(fact[0], fact[1], fact[2], fact[3]); CompoundFieldValueFactory f = new CompoundFieldValueFactory(list); f.getFieldValue(field, this); - verify(4); + verifyCalled(0, 1, 2); + verifyNotCalled(3); } /** @@ -183,7 +190,7 @@ public class CompoundFieldValueFactoryTest extends Assert fact[0], fact[1] }); f.addFactory(fact[2]); f.getFieldValue(field, this); - verify(3); + verifyCalled(0, 1, 2); try { http://git-wip-us.apache.org/repos/asf/wicket/blob/10207bfc/wicket-spring/pom.xml ---------------------------------------------------------------------- diff --git a/wicket-spring/pom.xml b/wicket-spring/pom.xml index f3dfd1d..4a85d13 100644 --- a/wicket-spring/pom.xml +++ b/wicket-spring/pom.xml @@ -42,10 +42,6 @@ <artifactId>spring-web</artifactId> <scope>provided</scope> </dependency> - <dependency> - <groupId>org.easymock</groupId> - <artifactId>easymock</artifactId> - </dependency> </dependencies> <build> <pluginManagement>
