You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by re...@apache.org on 2023/06/11 22:31:35 UTC
[cxf] 01/01: CXF-8842: Get rid of EasyMock in cxf-core (#1228)
This is an automated email from the ASF dual-hosted git repository.
reta pushed a commit to branch 3.6.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git
commit 66afbe72d25741389d362bfb0c8bec9f5dbb5ee4
Author: Andriy Redko <dr...@gmail.com>
AuthorDate: Sun Jun 11 15:12:49 2023 -0400
CXF-8842: Get rid of EasyMock in cxf-core (#1228)
---
core/pom.xml | 5 +-
.../apache/cxf/attachment/AttachmentUtilTest.java | 76 +++++--------
.../java/org/apache/cxf/bus/CXFBusImplTest.java | 27 ++---
.../managers/EndpointResolverRegistryImplTest.java | 119 +++++----------------
.../ServiceContractResolverRegistryImplTest.java | 36 ++-----
.../apache/cxf/bus/osgi/OSGiBusListenerTest.java | 105 +++++++++---------
.../cxf/bus/spring/BusApplicationListenerTest.java | 17 ++-
.../cxf/bus/spring/SpringBusFactoryTest.java | 16 ++-
.../buslifecycle/CXFBusLifeCycleManagerTest.java | 90 +++++-----------
.../common/annotation/AnnotationProcessorTest.java | 57 +++++-----
.../cxf/common/injection/ResourceInjectorTest.java | 18 ++--
.../apache/cxf/common/logging/LogUtilsTest.java | 65 ++++++-----
.../apache/cxf/common/util/ClassHelperTest.java | 105 +++++++++---------
.../org/apache/cxf/helpers/ServiceUtilsTest.java | 16 +--
.../cxf/interceptor/LoggingInInterceptorTest.java | 33 +++---
.../cxf/interceptor/LoggingOutInterceptorTest.java | 45 +++-----
.../interceptor/OutgoingChainInterceptorTest.java | 63 +++++------
.../interceptor/ServiceInvokerInterceptorTest.java | 11 +-
.../security/JAASLoginInterceptorTest.java | 15 ++-
.../OperationInfoAuthorizingInterceptorTest.java | 21 ++--
.../security/SecureAnnotationsInterceptorTest.java | 14 +--
.../security/SimpleAuthorizingInterceptorTest.java | 15 +--
.../org/apache/cxf/io/CachedStreamTestBase.java | 26 ++---
.../cxf/phase/PhaseInterceptorChainTest.java | 112 +++++++++----------
.../validation/Stax2ValidationUtilsTest.java | 16 ++-
.../cxf/transport/ChainInitiationObserverTest.java | 22 ++--
.../common/gzip/GZIPAcceptEncodingTest.java | 7 +-
27 files changed, 474 insertions(+), 678 deletions(-)
diff --git a/core/pom.xml b/core/pom.xml
index 7ee353136d..c9aeb276e9 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -97,8 +97,9 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.easymock</groupId>
- <artifactId>easymock</artifactId>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-subclass</artifactId>
+ <version>${cxf.mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
diff --git a/core/src/test/java/org/apache/cxf/attachment/AttachmentUtilTest.java b/core/src/test/java/org/apache/cxf/attachment/AttachmentUtilTest.java
index 6b3285c810..bcab2aabb0 100644
--- a/core/src/test/java/org/apache/cxf/attachment/AttachmentUtilTest.java
+++ b/core/src/test/java/org/apache/cxf/attachment/AttachmentUtilTest.java
@@ -31,13 +31,12 @@ import org.apache.cxf.message.MessageImpl;
import org.junit.Test;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.endsWith;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
public class AttachmentUtilTest {
@Test
@@ -269,70 +268,57 @@ public class AttachmentUtilTest {
@Test
public void bigIntAsAttachmentMaxSize() throws IOException {
- CachedOutputStream cos = createMock(CachedOutputStream.class);
+ CachedOutputStream cos = spy(CachedOutputStream.class);
BigInteger bigInteger = new BigInteger(String.valueOf(Long.MAX_VALUE));
cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE, bigInteger, cos);
- replay(cos);
- cos.setMaxSize(bigInteger.longValue());
- cos.setThreshold(102400L);
- verify(cos);
+ verify(cos).setMaxSize(bigInteger.longValue());
+ verify(cos).setThreshold(102400L);
+
// Overflow long value
bigInteger = bigInteger.add(BigInteger.ONE);
- cos = createMock(CachedOutputStream.class);
+ cos = spy(CachedOutputStream.class);
cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE, bigInteger, cos);
- replay(cos);
- cos.setThreshold(102400L);
- verify(cos);
+ verify(cos).setThreshold(102400L);
}
@Test
public void longAsAttachmentMaxSize() throws IOException {
- CachedOutputStream cos = createMock(CachedOutputStream.class);
+ CachedOutputStream cos = spy(CachedOutputStream.class);
cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE, Long.MAX_VALUE, cos);
- replay(cos);
- cos.setMaxSize(Long.MAX_VALUE);
- cos.setThreshold(102400L);
- verify(cos);
+ verify(cos).setMaxSize(Long.MAX_VALUE);
+ verify(cos).setThreshold(102400L);
}
@Test
public void integerAsAttachmentMaxSize() throws IOException {
- CachedOutputStream cos = createMock(CachedOutputStream.class);
+ CachedOutputStream cos = spy(CachedOutputStream.class);
cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE, Integer.MAX_VALUE, cos);
- replay(cos);
- cos.setMaxSize(Integer.MAX_VALUE);
- cos.setThreshold(102400L);
- verify(cos);
+ verify(cos).setMaxSize(Integer.MAX_VALUE);
+ verify(cos).setThreshold(102400L);
}
@Test
public void shortAsAttachmentMaxSize() throws IOException {
- CachedOutputStream cos = createMock(CachedOutputStream.class);
+ CachedOutputStream cos = spy(CachedOutputStream.class);
cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE, Short.MAX_VALUE, cos);
- replay(cos);
- cos.setMaxSize(Short.MAX_VALUE);
- cos.setThreshold(102400L);
- verify(cos);
+ verify(cos).setMaxSize(Short.MAX_VALUE);
+ verify(cos).setThreshold(102400L);
}
@Test
public void byteAsAttachmentMaxSize() throws IOException {
- CachedOutputStream cos = createMock(CachedOutputStream.class);
+ CachedOutputStream cos = spy(CachedOutputStream.class);
cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE, Byte.MAX_VALUE, cos);
- replay(cos);
- cos.setMaxSize(Byte.MAX_VALUE);
- cos.setThreshold(102400L);
- verify(cos);
+ verify(cos).setMaxSize(Byte.MAX_VALUE);
+ verify(cos).setThreshold(102400L);
}
@Test
public void numberStringAsAttachmentMaxSize() throws IOException {
- CachedOutputStream cos = createMock(CachedOutputStream.class);
+ CachedOutputStream cos = spy(CachedOutputStream.class);
cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_MAX_SIZE, "12345", cos);
- replay(cos);
- cos.setMaxSize(12345);
- cos.setThreshold(102400L);
- verify(cos);
+ verify(cos).setMaxSize(12345);
+ verify(cos).setThreshold(102400L);
}
@Test(expected = IOException.class)
@@ -354,25 +340,21 @@ public class AttachmentUtilTest {
@Test
public void fileAsAttachmentDirectory() throws IOException {
File attachmentDirectory = new File("/dev/null");
- CachedOutputStream cos = createMock(CachedOutputStream.class);
+ CachedOutputStream cos = spy(CachedOutputStream.class);
cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_DIRECTORY, attachmentDirectory,
cos);
- replay(cos);
- cos.setOutputDir(attachmentDirectory);
- cos.setThreshold(102400L);
- verify(cos);
+ verify(cos).setOutputDir(attachmentDirectory);
+ verify(cos).setThreshold(102400L);
}
@Test
public void stringAsAttachmentDirectory() throws IOException {
String attachmentDirectory = "/dev/null";
- CachedOutputStream cos = createMock(CachedOutputStream.class);
+ CachedOutputStream cos = spy(CachedOutputStream.class);
cos = testSetStreamedAttachmentProperties(AttachmentDeserializer.ATTACHMENT_DIRECTORY, attachmentDirectory,
cos);
- replay(cos);
- cos.setOutputDir(new File(attachmentDirectory));
- cos.setThreshold(102400L);
- verify(cos);
+ verify(cos).setOutputDir(new File(attachmentDirectory));
+ verify(cos).setThreshold(102400L);
}
@Test(expected = IOException.class)
diff --git a/core/src/test/java/org/apache/cxf/bus/CXFBusImplTest.java b/core/src/test/java/org/apache/cxf/bus/CXFBusImplTest.java
index 7fc62bc362..ccdaa83a02 100644
--- a/core/src/test/java/org/apache/cxf/bus/CXFBusImplTest.java
+++ b/core/src/test/java/org/apache/cxf/bus/CXFBusImplTest.java
@@ -34,13 +34,13 @@ import org.apache.cxf.phase.PhaseManager;
import org.apache.cxf.transport.ConduitInitiatorManager;
import org.apache.cxf.transport.DestinationFactoryManager;
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
public class CXFBusImplTest {
@@ -67,17 +67,14 @@ public class CXFBusImplTest {
@Test
public void testConstructionWithExtensions() throws BusException {
- IMocksControl control;
BindingFactoryManager bindingFactoryManager;
InstrumentationManager instrumentationManager;
PhaseManager phaseManager;
- control = EasyMock.createNiceControl();
-
Map<Class<?>, Object> extensions = new HashMap<>();
- bindingFactoryManager = control.createMock(BindingFactoryManager.class);
- instrumentationManager = control.createMock(InstrumentationManager.class);
- phaseManager = control.createMock(PhaseManager.class);
+ bindingFactoryManager = mock(BindingFactoryManager.class);
+ instrumentationManager = mock(InstrumentationManager.class);
+ phaseManager = mock(PhaseManager.class);
extensions.put(BindingFactoryManager.class, bindingFactoryManager);
extensions.put(InstrumentationManager.class, instrumentationManager);
@@ -114,16 +111,14 @@ public class CXFBusImplTest {
public void testShutdownWithBusLifecycle() {
final Bus bus = new ExtensionManagerBus();
BusLifeCycleManager lifeCycleManager = bus.getExtension(BusLifeCycleManager.class);
- BusLifeCycleListener listener = EasyMock.createMock(BusLifeCycleListener.class);
- EasyMock.reset(listener);
- listener.preShutdown();
- EasyMock.expectLastCall();
- listener.postShutdown();
- EasyMock.expectLastCall();
- EasyMock.replay(listener);
+ BusLifeCycleListener listener = mock(BusLifeCycleListener.class);
+
lifeCycleManager.registerLifeCycleListener(listener);
bus.shutdown(true);
- EasyMock.verify(listener);
+
+ verify(listener).preShutdown();
+ verify(listener).postShutdown();
+
bus.shutdown(true);
}
diff --git a/core/src/test/java/org/apache/cxf/bus/managers/EndpointResolverRegistryImplTest.java b/core/src/test/java/org/apache/cxf/bus/managers/EndpointResolverRegistryImplTest.java
index 1e17bf26d1..6f48090ac7 100644
--- a/core/src/test/java/org/apache/cxf/bus/managers/EndpointResolverRegistryImplTest.java
+++ b/core/src/test/java/org/apache/cxf/bus/managers/EndpointResolverRegistryImplTest.java
@@ -24,8 +24,6 @@ import javax.xml.namespace.QName;
import org.apache.cxf.endpoint.EndpointResolver;
import org.apache.cxf.ws.addressing.EndpointReferenceType;
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -35,6 +33,8 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class EndpointResolverRegistryImplTest {
@@ -44,18 +44,16 @@ public class EndpointResolverRegistryImplTest {
private EndpointReferenceType logical;
private EndpointReferenceType physical;
private EndpointReferenceType fresh;
- private IMocksControl control;
private QName serviceName;
@Before
public void setUp() {
registry = new EndpointResolverRegistryImpl();
- control = EasyMock.createNiceControl();
- resolver1 = control.createMock(EndpointResolver.class);
- resolver2 = control.createMock(EndpointResolver.class);
- logical = control.createMock(EndpointReferenceType.class);
- physical = control.createMock(EndpointReferenceType.class);
- fresh = control.createMock(EndpointReferenceType.class);
+ resolver1 = mock(EndpointResolver.class);
+ resolver2 = mock(EndpointResolver.class);
+ logical = mock(EndpointReferenceType.class);
+ physical = mock(EndpointReferenceType.class);
+ fresh = mock(EndpointReferenceType.class);
serviceName = new QName("namespace", "local");
}
@@ -116,37 +114,22 @@ public class EndpointResolverRegistryImplTest {
public void testResolve() {
registry.register(resolver1);
registry.register(resolver2);
- resolver1.resolve(logical);
- EasyMock.expectLastCall().andReturn(physical);
- control.replay();
+ when(resolver1.resolve(logical)).thenReturn(physical);
EndpointReferenceType resolved = registry.resolve(logical);
-
- control.verify();
assertSame("unexpected physical EPR", physical, resolved);
- control.reset();
resolver1.resolve(logical);
- EasyMock.expectLastCall().andReturn(null);
- resolver2.resolve(logical);
- EasyMock.expectLastCall().andReturn(physical);
- control.replay();
+ when(resolver1.resolve(logical)).thenReturn(null);
+ when(resolver2.resolve(logical)).thenReturn(physical);
resolved = registry.resolve(logical);
-
- control.verify();
assertSame("unexpected physical EPR", physical, resolved);
- control.reset();
- resolver1.resolve(logical);
- EasyMock.expectLastCall().andReturn(null);
- resolver2.resolve(logical);
- EasyMock.expectLastCall().andReturn(null);
- control.replay();
+ when(resolver1.resolve(logical)).thenReturn(null);
+ when(resolver2.resolve(logical)).thenReturn(null);
resolved = registry.resolve(logical);
-
- control.verify();
assertNull("unexpected physical EPR", resolved);
}
@@ -154,37 +137,21 @@ public class EndpointResolverRegistryImplTest {
public void testRenew() {
registry.register(resolver1);
registry.register(resolver2);
- resolver1.renew(logical, physical);
- EasyMock.expectLastCall().andReturn(fresh);
- control.replay();
+ when(resolver1.renew(logical, physical)).thenReturn(fresh);
EndpointReferenceType renewed = registry.renew(logical, physical);
-
- control.verify();
assertSame("unexpected physical EPR", fresh, renewed);
- control.reset();
- resolver1.renew(logical, physical);
- EasyMock.expectLastCall().andReturn(null);
- resolver2.renew(logical, physical);
- EasyMock.expectLastCall().andReturn(physical);
- control.replay();
+ when(resolver1.renew(logical, physical)).thenReturn(null);
+ when(resolver2.renew(logical, physical)).thenReturn(physical);
renewed = registry.renew(logical, physical);
-
- control.verify();
assertSame("unexpected physical EPR", physical, renewed);
- control.reset();
- resolver1.renew(logical, physical);
- EasyMock.expectLastCall().andReturn(null);
- resolver2.renew(logical, physical);
- EasyMock.expectLastCall().andReturn(null);
- control.replay();
+ when(resolver1.renew(logical, physical)).thenReturn(null);
+ when(resolver2.renew(logical, physical)).thenReturn(null);
renewed = registry.renew(logical, physical);
-
- control.verify();
assertNull("unexpected physical EPR", renewed);
}
@@ -192,37 +159,21 @@ public class EndpointResolverRegistryImplTest {
public void testMintFromServiceName() {
registry.register(resolver1);
registry.register(resolver2);
- resolver1.mint(serviceName);
- EasyMock.expectLastCall().andReturn(logical);
- control.replay();
+ when(resolver1.mint(serviceName)).thenReturn(logical);
EndpointReferenceType minted = registry.mint(serviceName);
-
- control.verify();
assertSame("unexpected minted EPR", logical, minted);
- control.reset();
- resolver1.mint(serviceName);
- EasyMock.expectLastCall().andReturn(null);
- resolver2.mint(serviceName);
- EasyMock.expectLastCall().andReturn(logical);
- control.replay();
+ when(resolver1.mint(serviceName)).thenReturn(null);
+ when(resolver2.mint(serviceName)).thenReturn(logical);
minted = registry.mint(serviceName);
-
- control.verify();
assertSame("unexpected minted EPR", logical, minted);
- control.reset();
- resolver1.mint(serviceName);
- EasyMock.expectLastCall().andReturn(null);
- resolver2.mint(serviceName);
- EasyMock.expectLastCall().andReturn(null);
- control.replay();
+ when(resolver1.mint(serviceName)).thenReturn(null);
+ when(resolver2.mint(serviceName)).thenReturn(null);
minted = registry.mint(serviceName);
-
- control.verify();
assertNull("unexpected minted EPR", minted);
}
@@ -230,37 +181,21 @@ public class EndpointResolverRegistryImplTest {
public void testMintFromPhysical() {
registry.register(resolver1);
registry.register(resolver2);
- resolver1.mint(physical);
- EasyMock.expectLastCall().andReturn(logical);
- control.replay();
+ when(resolver1.mint(physical)).thenReturn(logical);
EndpointReferenceType minted = registry.mint(physical);
-
- control.verify();
assertSame("unexpected minted EPR", logical, minted);
- control.reset();
- resolver1.mint(physical);
- EasyMock.expectLastCall().andReturn(null);
- resolver2.mint(physical);
- EasyMock.expectLastCall().andReturn(logical);
- control.replay();
+ when(resolver1.mint(physical)).thenReturn(null);
+ when(resolver2.mint(physical)).thenReturn(logical);
minted = registry.mint(physical);
-
- control.verify();
assertSame("unexpected minted EPR", logical, minted);
- control.reset();
- resolver1.mint(physical);
- EasyMock.expectLastCall().andReturn(null);
- resolver2.mint(physical);
- EasyMock.expectLastCall().andReturn(null);
- control.replay();
+ when(resolver1.mint(physical)).thenReturn(null);
+ when(resolver2.mint(physical)).thenReturn(null);
minted = registry.mint(physical);
-
- control.verify();
assertNull("unexpected minted EPR", minted);
}
}
\ No newline at end of file
diff --git a/core/src/test/java/org/apache/cxf/bus/managers/ServiceContractResolverRegistryImplTest.java b/core/src/test/java/org/apache/cxf/bus/managers/ServiceContractResolverRegistryImplTest.java
index 8646451b5b..c23dd372e5 100644
--- a/core/src/test/java/org/apache/cxf/bus/managers/ServiceContractResolverRegistryImplTest.java
+++ b/core/src/test/java/org/apache/cxf/bus/managers/ServiceContractResolverRegistryImplTest.java
@@ -26,8 +26,6 @@ import javax.xml.namespace.QName;
import org.apache.cxf.endpoint.ServiceContractResolver;
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -38,6 +36,8 @@ import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class ServiceContractResolverRegistryImplTest {
private ServiceContractResolverRegistryImpl registry;
@@ -45,15 +45,13 @@ public class ServiceContractResolverRegistryImplTest {
private ServiceContractResolver resolver2;
private URI uri1;
private URI uri2;
- private IMocksControl control;
private QName serviceName;
@Before
public void setUp() throws URISyntaxException {
registry = new ServiceContractResolverRegistryImpl();
- control = EasyMock.createNiceControl();
- resolver1 = control.createMock(ServiceContractResolver.class);
- resolver2 = control.createMock(ServiceContractResolver.class);
+ resolver1 = mock(ServiceContractResolver.class);
+ resolver2 = mock(ServiceContractResolver.class);
uri1 = new URI("http://mock");
uri2 = new URI("file:///foo/bar");
@@ -114,38 +112,22 @@ public class ServiceContractResolverRegistryImplTest {
public void testGetContactLocation() {
registry.register(resolver1);
registry.register(resolver2);
- resolver1.getContractLocation(serviceName);
- EasyMock.expectLastCall().andReturn(uri1);
- control.replay();
+ when(resolver1.getContractLocation(serviceName)).thenReturn(uri1);
URI resolved = registry.getContractLocation(serviceName);
-
- control.verify();
assertSame("unexpected physical EPR", uri1, resolved);
- control.reset();
- resolver1.getContractLocation(serviceName);
- EasyMock.expectLastCall().andReturn(null);
- resolver2.getContractLocation(serviceName);
- EasyMock.expectLastCall().andReturn(uri2);
- control.replay();
+ when(resolver1.getContractLocation(serviceName)).thenReturn(null);
+ when(resolver2.getContractLocation(serviceName)).thenReturn(uri2);
resolved = registry.getContractLocation(serviceName);
-
- control.verify();
assertSame("unexpected physical EPR", uri2, resolved);
assertNotSame("unexpected physical EPR", uri1, resolved);
- control.reset();
- resolver1.getContractLocation(serviceName);
- EasyMock.expectLastCall().andReturn(null);
- resolver2.getContractLocation(serviceName);
- EasyMock.expectLastCall().andReturn(null);
- control.replay();
+ when(resolver1.getContractLocation(serviceName)).thenReturn(null);
+ when(resolver2.getContractLocation(serviceName)).thenReturn(null);
resolved = registry.getContractLocation(serviceName);
-
- control.verify();
assertNull("unexpected physical EPR", resolved);
}
diff --git a/core/src/test/java/org/apache/cxf/bus/osgi/OSGiBusListenerTest.java b/core/src/test/java/org/apache/cxf/bus/osgi/OSGiBusListenerTest.java
index 0d61f6332b..186988dcf6 100644
--- a/core/src/test/java/org/apache/cxf/bus/osgi/OSGiBusListenerTest.java
+++ b/core/src/test/java/org/apache/cxf/bus/osgi/OSGiBusListenerTest.java
@@ -34,13 +34,16 @@ import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
-
+import static org.mockito.ArgumentMatchers.isA;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
/**
@@ -52,36 +55,32 @@ public class OSGiBusListenerTest {
private static final String RESTRICTED = "me\\.my\\.app\\..*";
private static final String BUNDLE_NAME = "me.my.app";
- private IMocksControl control;
private Bus bus;
private BundleContext bundleContext;
private Bundle bundle;
-
+ private BusLifeCycleManager blcManager;
@Before
public void setUp() {
- control = EasyMock.createNiceControl();
- bus = control.createMock(Bus.class);
- BusLifeCycleManager blcManager = control.createMock(BusLifeCycleManager.class);
- EasyMock.expect(bus.getExtension(BusLifeCycleManager.class)).andReturn(blcManager).anyTimes();
-
- blcManager.registerLifeCycleListener(EasyMock.isA(OSGIBusListener.class));
- EasyMock.expectLastCall();
- bundleContext = control.createMock(BundleContext.class);
-
- BundleContext app = control.createMock(BundleContext.class);
- EasyMock.expect(bus.getExtension(BundleContext.class)).andReturn(app).anyTimes();
- bundle = control.createMock(Bundle.class);
- EasyMock.expect(app.getBundle()).andReturn(bundle).anyTimes();
- EasyMock.expect(bundle.getSymbolicName()).andReturn(BUNDLE_NAME).anyTimes();
+ bus = mock(Bus.class);
+ blcManager = mock(BusLifeCycleManager.class);
+ when(bus.getExtension(BusLifeCycleManager.class)).thenReturn(blcManager);
+
+ doNothing().when(blcManager).registerLifeCycleListener(isA(OSGIBusListener.class));
+ bundleContext = mock(BundleContext.class);
+
+ BundleContext app = mock(BundleContext.class);
+ when(bus.getExtension(BundleContext.class)).thenReturn(app);
+ bundle = mock(Bundle.class);
+ when(app.getBundle()).thenReturn(bundle);
+ when(bundle.getSymbolicName()).thenReturn(BUNDLE_NAME);
}
@Test
public void testRegistratioWithNoServices() throws Exception {
- control.replay();
new OSGIBusListener(bus, new Object[]{bundleContext});
- control.verify();
+ verify(blcManager, atLeastOnce()).registerLifeCycleListener(isA(OSGIBusListener.class));
}
@Test
@@ -91,12 +90,11 @@ public class OSGiBusListenerTest {
Collection<Feature> lst = new ArrayList<>();
setFeatures(SERVICE_BUNDLE_NAMES, new String[]{null, null}, lst);
- control.replay();
new OSGIBusListener(bus, new Object[]{bundleContext});
assertEquals(countServices(SERVICE_BUNDLE_NAMES, new String[]{null, null}, null), lst.size());
- control.verify();
+ verify(blcManager, atLeastOnce()).registerLifeCycleListener(isA(OSGIBusListener.class));
}
@Test
@@ -105,13 +103,12 @@ public class OSGiBusListenerTest {
setUpServerLifeCycleListeners(SERVICE_BUNDLE_NAMES, new String[]{null, null}, EXCLUDES);
Collection<Feature> lst = new ArrayList<>();
setFeatures(SERVICE_BUNDLE_NAMES, new String[]{null, null}, lst);
- EasyMock.expect(bus.getProperty("bus.extension.bundles.excludes")).andReturn(EXCLUDES);
- control.replay();
+ when(bus.getProperty("bus.extension.bundles.excludes")).thenReturn(EXCLUDES);
new OSGIBusListener(bus, new Object[]{bundleContext});
assertEquals(countServices(SERVICE_BUNDLE_NAMES, new String[]{null, null}, EXCLUDES), lst.size());
- control.verify();
+ verify(blcManager, atLeastOnce()).registerLifeCycleListener(isA(OSGIBusListener.class));
}
@Test
@@ -120,43 +117,40 @@ public class OSGiBusListenerTest {
setUpServerLifeCycleListeners(SERVICE_BUNDLE_NAMES, new String[]{RESTRICTED, null}, EXCLUDES);
Collection<Feature> lst = new ArrayList<>();
setFeatures(SERVICE_BUNDLE_NAMES, new String[]{RESTRICTED, null}, lst);
- EasyMock.expect(bus.getProperty("bus.extension.bundles.excludes")).andReturn(EXCLUDES);
- control.replay();
+ when(bus.getProperty("bus.extension.bundles.excludes")).thenReturn(EXCLUDES);
new OSGIBusListener(bus, new Object[]{bundleContext});
assertEquals(countServices(SERVICE_BUNDLE_NAMES, new String[]{RESTRICTED, null}, EXCLUDES), lst.size());
- control.verify();
+ verify(blcManager, atLeastOnce()).registerLifeCycleListener(isA(OSGIBusListener.class));
}
private void setUpClientLifeCycleListeners(String[] names, String[] restricted, String excludes) throws Exception {
ServiceReference<Object>[] svcrefs = createTestServiceReferences(names, restricted);
- EasyMock.expect(bundleContext.getServiceReferences(ClientLifeCycleListener.class.getName(), null))
- .andReturn(svcrefs);
- ClientLifeCycleManager lcmanager = control.createMock(ClientLifeCycleManager.class);
- EasyMock.expect(bus.getExtension(ClientLifeCycleManager.class)).andReturn(lcmanager).anyTimes();
+ when(bundleContext.getServiceReferences(ClientLifeCycleListener.class.getName(), null))
+ .thenReturn(svcrefs);
+ ClientLifeCycleManager lcmanager = mock(ClientLifeCycleManager.class);
+ when(bus.getExtension(ClientLifeCycleManager.class)).thenReturn(lcmanager);
for (int i = 0; i < names.length; i++) {
- ClientLifeCycleListener cl = control.createMock(ClientLifeCycleListener.class);
- EasyMock.expect(bundleContext.getService(svcrefs[i])).andReturn(cl).anyTimes();
+ ClientLifeCycleListener cl = mock(ClientLifeCycleListener.class);
+ when(bundleContext.getService(svcrefs[i])).thenReturn(cl);
if (!isExcluded(BUNDLE_NAME, names[i], restricted[i], excludes)) {
- lcmanager.registerListener(cl);
- EasyMock.expectLastCall();
+ doNothing().when(lcmanager).registerListener(cl);
}
}
}
private void setUpServerLifeCycleListeners(String[] names, String[] restricted, String excludes) throws Exception {
ServiceReference<Object>[] svcrefs = createTestServiceReferences(names, restricted);
- EasyMock.expect(bundleContext.getServiceReferences(ServerLifeCycleListener.class.getName(), null))
- .andReturn(svcrefs);
- ServerLifeCycleManager lcmanager = control.createMock(ServerLifeCycleManager.class);
- EasyMock.expect(bus.getExtension(ServerLifeCycleManager.class)).andReturn(lcmanager).anyTimes();
+ when(bundleContext.getServiceReferences(ServerLifeCycleListener.class.getName(), null))
+ .thenReturn(svcrefs);
+ ServerLifeCycleManager lcmanager = mock(ServerLifeCycleManager.class);
+ when(bus.getExtension(ServerLifeCycleManager.class)).thenReturn(lcmanager);
for (int i = 0; i < names.length; i++) {
- ServerLifeCycleListener cl = control.createMock(ServerLifeCycleListener.class);
- EasyMock.expect(bundleContext.getService(svcrefs[i])).andReturn(cl).anyTimes();
+ ServerLifeCycleListener cl = mock(ServerLifeCycleListener.class);
+ when(bundleContext.getService(svcrefs[i])).thenReturn(cl);
if (!isExcluded(BUNDLE_NAME, names[i], restricted[i], excludes)) {
- lcmanager.registerListener(cl);
- EasyMock.expectLastCall();
+ doNothing().when(lcmanager).registerListener(cl);
}
}
}
@@ -164,13 +158,13 @@ public class OSGiBusListenerTest {
private void setFeatures(String[] names, String[] restricted,
Collection<Feature> lst) throws Exception {
ServiceReference<Object>[] svcrefs = createTestServiceReferences(names, restricted);
- EasyMock.expect(bundleContext.getServiceReferences(Feature.class.getName(), null))
- .andReturn(svcrefs);
+ when(bundleContext.getServiceReferences(Feature.class.getName(), null))
+ .thenReturn(svcrefs);
for (int i = 0; i < names.length; i++) {
- Feature f = control.createMock(Feature.class);
- EasyMock.expect(bundleContext.getService(svcrefs[i])).andReturn(f).anyTimes();
+ Feature f = mock(Feature.class);
+ when(bundleContext.getService(svcrefs[i])).thenReturn(f);
}
- EasyMock.expect(bus.getFeatures()).andReturn(lst).anyTimes();
+ when(bus.getFeatures()).thenReturn(lst);
}
@@ -186,12 +180,13 @@ public class OSGiBusListenerTest {
// Creates a test service reference with the specified symbolic name and the restricted extension property.
+ @SuppressWarnings("unchecked")
private ServiceReference<Object> createTestServiceReference(String name, String rst) {
- ServiceReference<Object> ref = control.createMock(ServiceReference.class);
- Bundle b = control.createMock(Bundle.class);
- EasyMock.expect(b.getSymbolicName()).andReturn(name).anyTimes();
- EasyMock.expect(ref.getBundle()).andReturn(b).anyTimes();
- EasyMock.expect(ref.getProperty("org.apache.cxf.bus.restricted.extension")).andReturn(rst).anyTimes();
+ ServiceReference<Object> ref = mock(ServiceReference.class);
+ Bundle b = mock(Bundle.class);
+ when(b.getSymbolicName()).thenReturn(name);
+ when(ref.getBundle()).thenReturn(b);
+ when(ref.getProperty("org.apache.cxf.bus.restricted.extension")).thenReturn(rst);
return ref;
}
diff --git a/core/src/test/java/org/apache/cxf/bus/spring/BusApplicationListenerTest.java b/core/src/test/java/org/apache/cxf/bus/spring/BusApplicationListenerTest.java
index afc50c338d..3e569a516f 100644
--- a/core/src/test/java/org/apache/cxf/bus/spring/BusApplicationListenerTest.java
+++ b/core/src/test/java/org/apache/cxf/bus/spring/BusApplicationListenerTest.java
@@ -24,10 +24,11 @@ import org.apache.cxf.buslifecycle.BusLifeCycleListener;
import org.springframework.context.support.AbstractRefreshableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
-import org.easymock.EasyMock;
import org.junit.Test;
-
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
public class BusApplicationListenerTest {
@@ -38,16 +39,12 @@ public class BusApplicationListenerTest {
SpringBusFactory factory = new SpringBusFactory(parent);
Bus bus = factory.createBus();
CXFBusLifeCycleManager manager = bus.getExtension(CXFBusLifeCycleManager.class);
- BusLifeCycleListener listener = EasyMock.createMock(BusLifeCycleListener.class);
+ BusLifeCycleListener listener = mock(BusLifeCycleListener.class);
manager.registerLifeCycleListener(listener);
- EasyMock.reset(listener);
- listener.preShutdown();
- EasyMock.expectLastCall().times(1);
- listener.postShutdown();
- EasyMock.expectLastCall().times(1);
- EasyMock.replay(listener);
parent.close();
- EasyMock.verify(listener);
+
+ verify(listener).preShutdown();
+ verify(listener, times(1)).postShutdown();
}
}
diff --git a/core/src/test/java/org/apache/cxf/bus/spring/SpringBusFactoryTest.java b/core/src/test/java/org/apache/cxf/bus/spring/SpringBusFactoryTest.java
index 058e8268e5..ea75efaf0a 100644
--- a/core/src/test/java/org/apache/cxf/bus/spring/SpringBusFactoryTest.java
+++ b/core/src/test/java/org/apache/cxf/bus/spring/SpringBusFactoryTest.java
@@ -48,7 +48,6 @@ import org.apache.cxf.transport.ConduitInitiatorManager;
import org.apache.cxf.transport.DestinationFactoryManager;
import org.apache.cxf.workqueue.WorkQueueManager;
-import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Test;
@@ -58,6 +57,8 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
public class SpringBusFactoryTest {
@@ -144,19 +145,14 @@ public class SpringBusFactoryTest {
@Test
public void testForLifeCycle() {
- BusLifeCycleListener bl = EasyMock.createMock(BusLifeCycleListener.class);
+ BusLifeCycleListener bl = mock(BusLifeCycleListener.class);
Bus bus = new SpringBusFactory().createBus();
BusLifeCycleManager lifeCycleManager = bus.getExtension(BusLifeCycleManager.class);
lifeCycleManager.registerLifeCycleListener(bl);
- EasyMock.reset(bl);
- bl.preShutdown();
- EasyMock.expectLastCall();
- bl.postShutdown();
- EasyMock.expectLastCall();
- EasyMock.replay(bl);
bus.shutdown(true);
- EasyMock.verify(bl);
-
+
+ verify(bl).preShutdown();
+ verify(bl).postShutdown();
}
@Test
diff --git a/core/src/test/java/org/apache/cxf/buslifecycle/CXFBusLifeCycleManagerTest.java b/core/src/test/java/org/apache/cxf/buslifecycle/CXFBusLifeCycleManagerTest.java
index da36403ff5..8dfd585af2 100644
--- a/core/src/test/java/org/apache/cxf/buslifecycle/CXFBusLifeCycleManagerTest.java
+++ b/core/src/test/java/org/apache/cxf/buslifecycle/CXFBusLifeCycleManagerTest.java
@@ -21,124 +21,90 @@ package org.apache.cxf.buslifecycle;
import org.apache.cxf.bus.managers.CXFBusLifeCycleManager;
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
import org.junit.Test;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoInteractions;
+
public class CXFBusLifeCycleManagerTest {
@Test
public void testListenerNotRegistered() {
- BusLifeCycleListener listener1 = EasyMock.createMock(BusLifeCycleListener.class);
+ BusLifeCycleListener listener1 = mock(BusLifeCycleListener.class);
CXFBusLifeCycleManager mgr = new CXFBusLifeCycleManager();
- EasyMock.reset(listener1);
- EasyMock.replay(listener1);
mgr.initComplete();
- EasyMock.verify(listener1);
+ verifyNoInteractions(listener1);
- EasyMock.reset(listener1);
- EasyMock.replay(listener1);
mgr.preShutdown();
- EasyMock.verify(listener1);
+ verifyNoInteractions(listener1);
- EasyMock.reset(listener1);
- EasyMock.replay(listener1);
mgr.postShutdown();
- EasyMock.verify(listener1);
+ verifyNoInteractions(listener1);
}
@Test
public void testSingleListenerRegistration() {
- BusLifeCycleListener listener1 = EasyMock.createMock(BusLifeCycleListener.class);
+ BusLifeCycleListener listener1 = mock(BusLifeCycleListener.class);
CXFBusLifeCycleManager mgr = new CXFBusLifeCycleManager();
mgr.registerLifeCycleListener(listener1);
- EasyMock.reset(listener1);
- listener1.initComplete();
- EasyMock.replay(listener1);
mgr.initComplete();
- EasyMock.verify(listener1);
+ verify(listener1).initComplete();
- EasyMock.reset(listener1);
- listener1.preShutdown();
- EasyMock.replay(listener1);
mgr.preShutdown();
- EasyMock.verify(listener1);
+ verify(listener1).preShutdown();
- EasyMock.reset(listener1);
- listener1.postShutdown();
- EasyMock.replay(listener1);
mgr.postShutdown();
- EasyMock.verify(listener1);
+ verify(listener1).postShutdown();
}
@Test
public void testMultipleListeners() {
-
- IMocksControl ctrl = EasyMock.createStrictControl();
-
- BusLifeCycleListener listener1 = ctrl.createMock(BusLifeCycleListener.class);
- BusLifeCycleListener listener2 = ctrl.createMock(BusLifeCycleListener.class);
+ BusLifeCycleListener listener1 = mock(BusLifeCycleListener.class);
+ BusLifeCycleListener listener2 = mock(BusLifeCycleListener.class);
CXFBusLifeCycleManager mgr = new CXFBusLifeCycleManager();
mgr.registerLifeCycleListener(listener1);
mgr.registerLifeCycleListener(listener2);
- ctrl.reset();
- listener1.initComplete();
- listener2.initComplete();
- ctrl.replay();
mgr.initComplete();
- ctrl.verify();
+ verify(listener1).initComplete();
+ verify(listener2).initComplete();
- ctrl.reset();
- listener2.preShutdown();
- listener1.preShutdown();
- ctrl.replay();
mgr.preShutdown();
- ctrl.verify();
+ verify(listener1).preShutdown();
+ verify(listener2).preShutdown();
- ctrl.reset();
- listener2.postShutdown();
- listener1.postShutdown();
- ctrl.replay();
mgr.postShutdown();
- ctrl.verify();
+ verify(listener1).postShutdown();
+ verify(listener2).postShutdown();
}
@Test
public void testDeregistration() {
-
- IMocksControl ctrl = EasyMock.createStrictControl();
-
- BusLifeCycleListener listener1 = ctrl.createMock(BusLifeCycleListener.class);
- BusLifeCycleListener listener2 = ctrl.createMock(BusLifeCycleListener.class);
+ BusLifeCycleListener listener1 = mock(BusLifeCycleListener.class);
+ BusLifeCycleListener listener2 = mock(BusLifeCycleListener.class);
CXFBusLifeCycleManager mgr = new CXFBusLifeCycleManager();
mgr.registerLifeCycleListener(listener2);
mgr.registerLifeCycleListener(listener1);
mgr.unregisterLifeCycleListener(listener2);
- ctrl.reset();
- listener1.initComplete();
- ctrl.replay();
mgr.initComplete();
- ctrl.verify();
+ verify(listener1).initComplete();
+ verifyNoInteractions(listener2);
- ctrl.reset();
- listener1.preShutdown();
- ctrl.replay();
mgr.preShutdown();
- ctrl.verify();
+ verify(listener1).preShutdown();
+ verifyNoInteractions(listener2);
- ctrl.reset();
- listener1.postShutdown();
- ctrl.replay();
mgr.postShutdown();
- ctrl.verify();
+ verify(listener1).postShutdown();
+ verifyNoInteractions(listener2);
}
}
diff --git a/core/src/test/java/org/apache/cxf/common/annotation/AnnotationProcessorTest.java b/core/src/test/java/org/apache/cxf/common/annotation/AnnotationProcessorTest.java
index bec33558d1..d666e9eb11 100644
--- a/core/src/test/java/org/apache/cxf/common/annotation/AnnotationProcessorTest.java
+++ b/core/src/test/java/org/apache/cxf/common/annotation/AnnotationProcessorTest.java
@@ -32,12 +32,16 @@ import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.ws.WebServiceContext;
-import org.easymock.EasyMock;
-import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.fail;
-
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.isA;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class AnnotationProcessorTest {
@@ -45,12 +49,7 @@ public class AnnotationProcessorTest {
AnnotationProcessor processor = new AnnotationProcessor(greeterImpl);
List<Class<? extends Annotation>> expectedAnnotations = new ArrayList<>();
- AnnotationVisitor visitor = EasyMock.createMock(AnnotationVisitor.class);
-
- @Before
- public void setUp() {
- EasyMock.checkOrder(visitor, false);
- }
+ AnnotationVisitor visitor = mock(AnnotationVisitor.class);
@Test
public void testVisitClass() {
@@ -58,8 +57,8 @@ public class AnnotationProcessorTest {
expectedAnnotations.add(WebService.class);
prepareCommonExpectations(visitor);
- visitor.visitClass(EasyMock.eq(AnnotatedGreeterImpl.class),
- EasyMock.isA(WebService.class));
+ visitor.visitClass(eq(AnnotatedGreeterImpl.class),
+ isA(WebService.class));
runProcessor(visitor);
}
@@ -71,9 +70,9 @@ public class AnnotationProcessorTest {
expectedAnnotations.add(Resource.class);
prepareCommonExpectations(visitor);
- visitor.visitField(EasyMock.eq(expectedField),
- EasyMock.isA(Resource.class));
- visitor.visitMethod((Method)EasyMock.anyObject(), (Annotation)EasyMock.anyObject());
+ visitor.visitField(eq(expectedField),
+ isA(Resource.class));
+ visitor.visitMethod(any(Method.class), any(Annotation.class));
runProcessor(visitor);
@@ -94,18 +93,18 @@ public class AnnotationProcessorTest {
expectedAnnotations.add(Resource.class);
prepareCommonExpectations(visitor);
- visitor.visitField(EasyMock.eq(expectedField),
- EasyMock.isA(Resource.class));
- visitor.visitMethod(EasyMock.eq(expectedMethod1),
- EasyMock.isA(WebMethod.class));
- visitor.visitMethod(EasyMock.eq(expectedMethod2),
- EasyMock.isA(WebMethod.class));
- visitor.visitMethod(EasyMock.eq(expectedMethod3),
- EasyMock.isA(WebMethod.class));
- visitor.visitMethod(EasyMock.eq(expectedMethod4),
- EasyMock.isA(Resource.class));
- visitor.visitMethod(EasyMock.eq(expectedMethod5),
- EasyMock.isA(WebMethod.class));
+ visitor.visitField(eq(expectedField),
+ isA(Resource.class));
+ visitor.visitMethod(eq(expectedMethod1),
+ isA(WebMethod.class));
+ visitor.visitMethod(eq(expectedMethod2),
+ isA(WebMethod.class));
+ visitor.visitMethod(eq(expectedMethod3),
+ isA(WebMethod.class));
+ visitor.visitMethod(eq(expectedMethod4),
+ isA(Resource.class));
+ visitor.visitMethod(eq(expectedMethod5),
+ isA(WebMethod.class));
runProcessor(visitor);
}
@@ -135,14 +134,12 @@ public class AnnotationProcessorTest {
private void prepareCommonExpectations(AnnotationVisitor v) {
- v.getTargetAnnotations();
- EasyMock.expectLastCall().andReturn(expectedAnnotations);
+ when(v.getTargetAnnotations()).thenReturn(expectedAnnotations);
v.setTarget(greeterImpl);
}
private void runProcessor(AnnotationVisitor v) {
- EasyMock.replay(v);
processor.accept(v);
- EasyMock.verify(v);
+ verify(v, times(1)).getTargetAnnotations();
}
}
diff --git a/core/src/test/java/org/apache/cxf/common/injection/ResourceInjectorTest.java b/core/src/test/java/org/apache/cxf/common/injection/ResourceInjectorTest.java
index 48085f1f17..967631b93a 100644
--- a/core/src/test/java/org/apache/cxf/common/injection/ResourceInjectorTest.java
+++ b/core/src/test/java/org/apache/cxf/common/injection/ResourceInjectorTest.java
@@ -38,12 +38,13 @@ import net.sf.cglib.proxy.MethodProxy;
import org.apache.cxf.resource.ResourceManager;
import org.apache.cxf.resource.ResourceResolver;
-import org.easymock.EasyMock;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class ResourceInjectorTest {
private static final String RESOURCE_ONE = "resource one";
@@ -54,18 +55,13 @@ public class ResourceInjectorTest {
public void setUpResourceManager(String pfx) {
- ResourceManager resMgr = EasyMock.createMock(ResourceManager.class);
+ ResourceManager resMgr = mock(ResourceManager.class);
List<ResourceResolver> resolvers = new ArrayList<>();
- resMgr.getResourceResolvers();
- EasyMock.expectLastCall().andReturn(resolvers);
- resMgr.resolveResource(pfx + "resource1", String.class, resolvers);
- EasyMock.expectLastCall().andReturn(RESOURCE_ONE);
- resMgr.resolveResource("resource2", String.class, resolvers);
- EasyMock.expectLastCall().andReturn(RESOURCE_TWO);
- resMgr.resolveResource("resource3", CharSequence.class, resolvers);
- EasyMock.expectLastCall().andReturn(RESOURCE_THREE);
- EasyMock.replay(resMgr);
+ when(resMgr.getResourceResolvers()).thenReturn(resolvers);
+ when(resMgr.resolveResource(pfx + "resource1", String.class, resolvers)).thenReturn(RESOURCE_ONE);
+ when(resMgr.resolveResource("resource2", String.class, resolvers)).thenReturn(RESOURCE_TWO);
+ when(resMgr.resolveResource("resource3", CharSequence.class, resolvers)).thenReturn(RESOURCE_THREE);
injector = new ResourceInjector(resMgr);
}
diff --git a/core/src/test/java/org/apache/cxf/common/logging/LogUtilsTest.java b/core/src/test/java/org/apache/cxf/common/logging/LogUtilsTest.java
index 2cdabb16ad..fa56c278e0 100644
--- a/core/src/test/java/org/apache/cxf/common/logging/LogUtilsTest.java
+++ b/core/src/test/java/org/apache/cxf/common/logging/LogUtilsTest.java
@@ -25,15 +25,18 @@ import java.util.logging.LogRecord;
import java.util.logging.Logger;
import org.apache.cxf.common.i18n.BundleUtils;
+import org.hamcrest.BaseMatcher;
+import org.hamcrest.Description;
-import org.easymock.EasyMock;
-import org.easymock.IArgumentMatcher;
import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-
-
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
public class LogUtilsTest {
@@ -52,87 +55,94 @@ public class LogUtilsTest {
@Test
public void testHandleL7dMessage() throws Exception {
+ final ArgumentCaptor<LogRecord> captor = ArgumentCaptor.forClass(LogRecord.class);
+
Logger log = LogUtils.getL7dLogger(LogUtilsTest.class, null, "testHandleL7dMessage");
- Handler handler = EasyMock.createNiceMock(Handler.class);
+ Handler handler = mock(Handler.class);
log.addHandler(handler);
// handler called *before* localization of message
LogRecord record = new LogRecord(Level.WARNING, "FOOBAR_MSG");
record.setResourceBundle(log.getResourceBundle());
- EasyMock.reportMatcher(new LogRecordMatcher(record));
handler.publish(record);
- EasyMock.replay(handler);
log.log(Level.WARNING, "FOOBAR_MSG");
- EasyMock.verify(handler);
+
+ verify(handler, times(2)).publish(captor.capture());
+ assertThat(captor.getValue(), new LogRecordMatcher(record));
log.removeHandler(handler);
}
@Test
public void testLogNoParamsOrThrowable() {
+ final ArgumentCaptor<LogRecord> captor = ArgumentCaptor.forClass(LogRecord.class);
+
Logger log = LogUtils.getL7dLogger(LogUtilsTest.class, null, "testLogNoParamsOrThrowable");
- Handler handler = EasyMock.createNiceMock(Handler.class);
+ Handler handler = mock(Handler.class);
log.addHandler(handler);
// handler called *after* localization of message
LogRecord record = new LogRecord(Level.SEVERE, "subbed in {0} only");
- EasyMock.reportMatcher(new LogRecordMatcher(record));
handler.publish(record);
- EasyMock.replay(handler);
LogUtils.log(log, Level.SEVERE, "SUB1_MSG");
- EasyMock.verify(handler);
+
+ verify(handler, times(2)).publish(captor.capture());
+ assertThat(captor.getValue(), new LogRecordMatcher(record));
log.removeHandler(handler);
}
@Test
public void testLogNoParamsWithThrowable() {
+ final ArgumentCaptor<LogRecord> captor = ArgumentCaptor.forClass(LogRecord.class);
+
Logger log = LogUtils.getL7dLogger(LogUtilsTest.class, null, "testLogNoParamsWithThrowable");
- Handler handler = EasyMock.createNiceMock(Handler.class);
+ Handler handler = mock(Handler.class);
Exception ex = new Exception("x");
LogRecord record = new LogRecord(Level.SEVERE, "subbed in {0} only");
record.setThrown(ex);
- EasyMock.reportMatcher(new LogRecordMatcher(record));
handler.publish(record);
- EasyMock.replay(handler);
synchronized (log) {
log.addHandler(handler);
// handler called *after* localization of message
LogUtils.log(log, Level.SEVERE, "SUB1_MSG", ex);
- EasyMock.verify(handler);
+ verify(handler, times(2)).publish(captor.capture());
+ assertThat(captor.getValue(), new LogRecordMatcher(record));
log.removeHandler(handler);
}
}
@Test
public void testLogParamSubstitutionWithThrowable() throws Exception {
+ final ArgumentCaptor<LogRecord> captor = ArgumentCaptor.forClass(LogRecord.class);
+
Logger log = LogUtils.getL7dLogger(LogUtilsTest.class, null, "testLogParamSubstitutionWithThrowable");
- Handler handler = EasyMock.createNiceMock(Handler.class);
+ Handler handler = mock(Handler.class);
Exception ex = new Exception();
LogRecord record = new LogRecord(Level.SEVERE, "subbed in 1 only");
record.setThrown(ex);
- EasyMock.reportMatcher(new LogRecordMatcher(record));
handler.publish(record);
- EasyMock.replay(handler);
synchronized (log) {
log.addHandler(handler);
LogUtils.log(log, Level.SEVERE, "SUB1_MSG", ex, 1);
- EasyMock.verify(handler);
+ verify(handler, times(2)).publish(captor.capture());
+ assertThat(captor.getValue(), new LogRecordMatcher(record));
log.removeHandler(handler);
}
}
@Test
public void testLogParamsSubstitutionWithThrowable() throws Exception {
+ final ArgumentCaptor<LogRecord> captor = ArgumentCaptor.forClass(LogRecord.class);
+
Logger log = LogUtils.getL7dLogger(LogUtilsTest.class, null,
"testLogParamsSubstitutionWithThrowable");
- Handler handler = EasyMock.createNiceMock(Handler.class);
+ Handler handler = mock(Handler.class);
Exception ex = new Exception();
LogRecord record = new LogRecord(Level.SEVERE, "subbed in 4 & 3");
record.setThrown(ex);
- EasyMock.reportMatcher(new LogRecordMatcher(record));
handler.publish(record);
- EasyMock.replay(handler);
synchronized (log) {
log.addHandler(handler);
LogUtils.log(log, Level.SEVERE, "SUB2_MSG", ex, new Object[] {3, 4});
- EasyMock.verify(handler);
+ verify(handler, times(2)).publish(captor.capture());
+ assertThat(captor.getValue(), new LogRecordMatcher(record));
log.removeHandler(handler);
}
}
@@ -175,7 +185,7 @@ public class LogUtilsTest {
}
}
- private static final class LogRecordMatcher implements IArgumentMatcher {
+ private static final class LogRecordMatcher extends BaseMatcher<LogRecord> {
private final LogRecord record;
private LogRecordMatcher(LogRecord r) {
@@ -197,8 +207,9 @@ public class LogUtilsTest {
return false;
}
- public void appendTo(StringBuffer buffer) {
- buffer.append("log records did not match");
+ @Override
+ public void describeTo(Description description) {
+ description.appendValue(record);
}
}
}
\ No newline at end of file
diff --git a/core/src/test/java/org/apache/cxf/common/util/ClassHelperTest.java b/core/src/test/java/org/apache/cxf/common/util/ClassHelperTest.java
index d8aa69b8c8..e0d2d1750d 100644
--- a/core/src/test/java/org/apache/cxf/common/util/ClassHelperTest.java
+++ b/core/src/test/java/org/apache/cxf/common/util/ClassHelperTest.java
@@ -30,12 +30,15 @@ import org.apache.cxf.BusFactory;
import org.springframework.aop.AfterReturningAdvice;
import org.springframework.aop.framework.ProxyFactory;
-import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertSame;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class ClassHelperTest {
@@ -92,7 +95,7 @@ public class ClassHelperTest {
currentThreadBus = BusFactory.getThreadDefaultBus();
- bus = EasyMock.mock(Bus.class);
+ bus = mock(Bus.class);
BusFactory.setThreadDefaultBus(bus);
}
@@ -105,146 +108,144 @@ public class ClassHelperTest {
@Test
public void getRealClassPropertyWasSetInBus() {
- EasyMock.expect(bus.getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER)).andReturn(true);
- EasyMock.expect(bus.getProperty(ClassUnwrapper.class.getName())).andReturn(null);
- EasyMock.replay(bus);
+ when(bus.getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER)).thenReturn(true);
+ when(bus.getProperty(ClassUnwrapper.class.getName())).thenReturn(null);
assertSame(realObjectInternalProxy.getClass(), ClassHelper.getRealClass(proxiedObject));
- EasyMock.verify(bus);
+ verify(bus, times(1)).getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER);
+ verify(bus, times(1)).getProperty(ClassUnwrapper.class.getName());
}
@Test
public void getRealClassPropertyWasNotSetInBus() {
- EasyMock.expect(bus.getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER)).andReturn(false);
- EasyMock.expect(bus.getProperty(ClassUnwrapper.class.getName())).andReturn(null);
- EasyMock.replay(bus);
+ when(bus.getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER)).thenReturn(false);
+ when(bus.getProperty(ClassUnwrapper.class.getName())).thenReturn(null);
assertSame(realObjectInternalSpring.getClass(), ClassHelper.getRealClass(springAopObject));
- EasyMock.verify(bus);
+ verify(bus, times(1)).getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER);
+ verify(bus, times(1)).getProperty(ClassUnwrapper.class.getName());
}
@Test
public void getRealClassFromClassPropertyWasSetInBus() {
- EasyMock.expect(bus.getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER)).andReturn(true);
- EasyMock.expect(bus.getProperty(ClassUnwrapper.class.getName())).andReturn(null);
- EasyMock.replay(bus);
+ when(bus.getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER)).thenReturn(true);
+ when(bus.getProperty(ClassUnwrapper.class.getName())).thenReturn(null);
assertSame(proxiedObject.getClass(), ClassHelper.getRealClassFromClass(proxiedObject.getClass()));
- EasyMock.verify(bus);
-
+ verify(bus, times(1)).getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER);
+ verify(bus, times(1)).getProperty(ClassUnwrapper.class.getName());
}
@Test
public void getRealClassFromClassPropertyWasNotSetInBus() {
- EasyMock.expect(bus.getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER)).andReturn(false);
- EasyMock.expect(bus.getProperty(ClassUnwrapper.class.getName())).andReturn(null);
- EasyMock.replay(bus);
+ when(bus.getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER)).thenReturn(false);
+ when(bus.getProperty(ClassUnwrapper.class.getName())).thenReturn(null);
assertSame(realObjectInternalSpring.getClass(), ClassHelper.getRealClassFromClass(springAopObject.getClass()));
- EasyMock.verify(bus);
-
+ verify(bus, times(1)).getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER);
+ verify(bus, times(1)).getProperty(ClassUnwrapper.class.getName());
}
@Test
public void getRealObjectPropertyWasSetInBus() {
- EasyMock.expect(bus.getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER)).andReturn(true);
- EasyMock.expect(bus.getProperty(ClassUnwrapper.class.getName())).andReturn(null);
- EasyMock.replay(bus);
+ when(bus.getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER)).thenReturn(true);
+ when(bus.getProperty(ClassUnwrapper.class.getName())).thenReturn(null);
assertSame(realObjectInternalProxy, ClassHelper.getRealObject(proxiedObject));
- EasyMock.verify(bus);
+ verify(bus, times(1)).getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER);
+ verify(bus, times(1)).getProperty(ClassUnwrapper.class.getName());
}
@Test
public void getRealObjectPropertyWasNotSetInBus() {
- EasyMock.expect(bus.getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER)).andReturn(false);
- EasyMock.expect(bus.getProperty(ClassUnwrapper.class.getName())).andReturn(null);
- EasyMock.replay(bus);
+ when(bus.getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER)).thenReturn(false);
+ when(bus.getProperty(ClassUnwrapper.class.getName())).thenReturn(null);
assertSame(realObjectInternalSpring, ClassHelper.getRealObject(springAopObject));
- EasyMock.verify(bus);
+ verify(bus, times(1)).getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER);
+ verify(bus, times(1)).getProperty(ClassUnwrapper.class.getName());
}
@Test
public void getRealLambdaClassPropertyWasNotSetInBus() {
- EasyMock.expect(bus.getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER)).andReturn(false);
- EasyMock.expect(bus.getProperty(ClassUnwrapper.class.getName())).andReturn(null);
- EasyMock.replay(bus);
+ when(bus.getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER)).thenReturn(false);
+ when(bus.getProperty(ClassUnwrapper.class.getName())).thenReturn(null);
assertSame(fn.getClass(), ClassHelper.getRealClass(fn));
- EasyMock.verify(bus);
+ verify(bus, times(1)).getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER);
+ verify(bus, times(1)).getProperty(ClassUnwrapper.class.getName());
}
@Test
public void getRealLambdaClassPropertyWasSetInBus() {
- EasyMock.expect(bus.getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER)).andReturn(true);
- EasyMock.expect(bus.getProperty(ClassUnwrapper.class.getName())).andReturn(null);
- EasyMock.replay(bus);
+ when(bus.getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER)).thenReturn(true);
+ when(bus.getProperty(ClassUnwrapper.class.getName())).thenReturn(null);
assertSame(fn.getClass(), ClassHelper.getRealClass(fn));
- EasyMock.verify(bus);
+ verify(bus, times(1)).getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER);
+ verify(bus, times(1)).getProperty(ClassUnwrapper.class.getName());
}
@Test
public void getRealLambdaClassFromClassPropertyWasSetInBus() {
- EasyMock.expect(bus.getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER)).andReturn(true);
- EasyMock.expect(bus.getProperty(ClassUnwrapper.class.getName())).andReturn(null);
- EasyMock.replay(bus);
+ when(bus.getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER)).thenReturn(true);
+ when(bus.getProperty(ClassUnwrapper.class.getName())).thenReturn(null);
assertSame(fn.getClass(), ClassHelper.getRealClassFromClass(fn.getClass()));
- EasyMock.verify(bus);
+ verify(bus, times(1)).getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER);
+ verify(bus, times(1)).getProperty(ClassUnwrapper.class.getName());
}
@Test
public void getRealLambdaClassFromClassPropertyWasNotSetInBus() {
- EasyMock.expect(bus.getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER)).andReturn(false);
- EasyMock.expect(bus.getProperty(ClassUnwrapper.class.getName())).andReturn(null);
- EasyMock.replay(bus);
+ when(bus.getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER)).thenReturn(false);
+ when(bus.getProperty(ClassUnwrapper.class.getName())).thenReturn(null);
assertSame(fn.getClass(), ClassHelper.getRealClassFromClass(fn.getClass()));
- EasyMock.verify(bus);
+ verify(bus, times(1)).getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER);
+ verify(bus, times(1)).getProperty(ClassUnwrapper.class.getName());
}
@Test
public void getRealCglibClassFromClassPropertyWasNotSetInBus() {
- EasyMock.expect(bus.getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER)).andReturn(false);
- EasyMock.expect(bus.getProperty(ClassUnwrapper.class.getName())).andReturn(null);
- EasyMock.replay(bus);
+ when(bus.getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER)).thenReturn(false);
+ when(bus.getProperty(ClassUnwrapper.class.getName())).thenReturn(null);
assertSame(Object.class, ClassHelper.getRealClassFromClass(cglibProxyObject.getClass()));
- EasyMock.verify(bus);
+ verify(bus, times(1)).getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER);
+ verify(bus, times(1)).getProperty(ClassUnwrapper.class.getName());
}
@Test
public void getRealCglibClassFromClassPropertyWasSetInBus() {
- EasyMock.expect(bus.getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER)).andReturn(true);
- EasyMock.expect(bus.getProperty(ClassUnwrapper.class.getName())).andReturn(null);
- EasyMock.replay(bus);
+ when(bus.getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER)).thenReturn(true);
+ when(bus.getProperty(ClassUnwrapper.class.getName())).thenReturn(null);
assertSame(cglibProxyObject.getClass(), ClassHelper.getRealClassFromClass(cglibProxyObject.getClass()));
- EasyMock.verify(bus);
+ verify(bus, times(1)).getProperty(ClassHelper.USE_DEFAULT_CLASS_HELPER);
+ verify(bus, times(1)).getProperty(ClassUnwrapper.class.getName());
}
public interface AnyInterface {
diff --git a/core/src/test/java/org/apache/cxf/helpers/ServiceUtilsTest.java b/core/src/test/java/org/apache/cxf/helpers/ServiceUtilsTest.java
index ea3c94c93e..307027f02c 100644
--- a/core/src/test/java/org/apache/cxf/helpers/ServiceUtilsTest.java
+++ b/core/src/test/java/org/apache/cxf/helpers/ServiceUtilsTest.java
@@ -24,23 +24,21 @@ import org.apache.cxf.annotations.SchemaValidation.SchemaValidationType;
import org.apache.cxf.common.util.StringUtils;
import org.apache.cxf.message.Message;
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class ServiceUtilsTest {
- private IMocksControl control;
private Message msg;
@Before
public void setUp() {
- control = EasyMock.createNiceControl();
- msg = control.createMock(Message.class);
+ msg = mock(Message.class);
}
@Test
@@ -166,11 +164,7 @@ public class ServiceUtilsTest {
}
private void setupSchemaValidationValue(Object value, boolean isRequestor) {
- control.reset();
- EasyMock.expect(msg.getContextualProperty(Message.SCHEMA_VALIDATION_ENABLED)).andReturn(value);
-
- EasyMock.expect(msg.get(Message.REQUESTOR_ROLE)).andReturn(isRequestor);
-
- control.replay();
+ when(msg.getContextualProperty(Message.SCHEMA_VALIDATION_ENABLED)).thenReturn(value);
+ when(msg.get(Message.REQUESTOR_ROLE)).thenReturn(isRequestor);
}
}
\ No newline at end of file
diff --git a/core/src/test/java/org/apache/cxf/interceptor/LoggingInInterceptorTest.java b/core/src/test/java/org/apache/cxf/interceptor/LoggingInInterceptorTest.java
index eed8d771e2..47d2e35d28 100644
--- a/core/src/test/java/org/apache/cxf/interceptor/LoggingInInterceptorTest.java
+++ b/core/src/test/java/org/apache/cxf/interceptor/LoggingInInterceptorTest.java
@@ -28,15 +28,18 @@ import org.apache.cxf.message.ExchangeImpl;
import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageImpl;
-import org.easymock.EasyMock;
-import org.easymock.IAnswer;
-import org.easymock.IMocksControl;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
@SuppressWarnings("deprecation")
public class LoggingInInterceptorTest {
@@ -47,7 +50,6 @@ public class LoggingInInterceptorTest {
+ "</seventeen></thousand></two></july></of></eighteenth></the></is></today>";
static int bufferLength = bufferContent.getBytes().length;
- protected IMocksControl control;
private Message message;
private InputStream inputStream;
private LoggingMessage loggingMessage;
@@ -56,7 +58,6 @@ public class LoggingInInterceptorTest {
@Before
public void setUp() throws Exception {
loggingMessage = new LoggingMessage("", "");
- control = EasyMock.createNiceControl();
StringWriter sw = new StringWriter();
sw.append("<today/>");
@@ -65,22 +66,20 @@ public class LoggingInInterceptorTest {
message.put(Message.CONTENT_TYPE, "application/xml");
message.setContent(Writer.class, sw);
- inputStream = control.createMock(InputStream.class);
- EasyMock.expect(inputStream.read(EasyMock.anyObject(byte[].class), EasyMock.anyInt(), EasyMock.anyInt()))
- .andAnswer(new IAnswer<Integer>() {
- public Integer answer() {
- System.arraycopy(bufferContent.getBytes(), 0,
- EasyMock.getCurrentArguments()[0], 0,
- bufferLength);
- return bufferLength;
- }
- }).andStubReturn(-1);
- control.replay();
+ inputStream = mock(InputStream.class);
+ when(inputStream.read(any(byte[].class), anyInt(), anyInt()))
+ .then(invocation -> {
+ System.arraycopy(bufferContent.getBytes(), 0,
+ invocation.getArgument(0), 0,
+ bufferLength);
+ return bufferLength;
+ })
+ .thenReturn(-1);
}
@After
public void tearDown() throws Exception {
- control.verify();
+ verify(inputStream, atLeastOnce()).read(any(byte[].class), anyInt(), anyInt());
}
@Test
diff --git a/core/src/test/java/org/apache/cxf/interceptor/LoggingOutInterceptorTest.java b/core/src/test/java/org/apache/cxf/interceptor/LoggingOutInterceptorTest.java
index 8fdf531222..cceae2a913 100644
--- a/core/src/test/java/org/apache/cxf/interceptor/LoggingOutInterceptorTest.java
+++ b/core/src/test/java/org/apache/cxf/interceptor/LoggingOutInterceptorTest.java
@@ -36,35 +36,19 @@ import org.apache.cxf.message.MessageImpl;
import org.apache.cxf.service.model.BindingInfo;
import org.apache.cxf.service.model.EndpointInfo;
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
-import org.junit.After;
-import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
@SuppressWarnings("deprecation")
public class LoggingOutInterceptorTest {
-
- protected IMocksControl control;
-
- @Before
- public void setUp() throws Exception {
- control = EasyMock.createNiceControl();
- }
-
- @After
- public void tearDown() throws Exception {
- control.verify();
- }
-
@Test
public void testFormatting() throws Exception {
- control.replay();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintWriter pw = new PrintWriter(baos);
@@ -88,7 +72,6 @@ public class LoggingOutInterceptorTest {
@Test
public void testPrettyLoggingWithoutEncoding() throws Exception {
- control.replay();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintWriter pw = new PrintWriter(baos);
@@ -112,7 +95,6 @@ public class LoggingOutInterceptorTest {
@Test
public void testPrettyLoggingWithEncoding() throws Exception {
- control.replay();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintWriter pw = new PrintWriter(baos);
@@ -138,7 +120,6 @@ public class LoggingOutInterceptorTest {
@Test
public void testFormattingOverride() throws Exception {
- control.replay();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// create a custom logging interceptor that overrides how formatting is done
@@ -171,10 +152,9 @@ public class LoggingOutInterceptorTest {
StringWriter sw = new StringWriter();
sw.append("<today/>");
- Endpoint endpoint = control.createMock(Endpoint.class);
- EndpointInfo endpointInfo = control.createMock(EndpointInfo.class);
- EasyMock.expect(endpoint.getEndpointInfo()).andReturn(endpointInfo).anyTimes();
- control.replay();
+ Endpoint endpoint = mock(Endpoint.class);
+ EndpointInfo endpointInfo = mock(EndpointInfo.class);
+ when(endpoint.getEndpointInfo()).thenReturn(endpointInfo);
Message message = new MessageImpl();
message.setExchange(new ExchangeImpl());
@@ -207,14 +187,13 @@ public class LoggingOutInterceptorTest {
private CachedOutputStream handleAndGetCachedOutputStream(LoggingOutInterceptor interceptor) {
interceptor.setPrintWriter(new PrintWriter(new ByteArrayOutputStream()));
- Endpoint endpoint = control.createMock(Endpoint.class);
- EndpointInfo endpointInfo = control.createMock(EndpointInfo.class);
- EasyMock.expect(endpoint.getEndpointInfo()).andReturn(endpointInfo).anyTimes();
- BindingInfo bindingInfo = control.createMock(BindingInfo.class);
- EasyMock.expect(endpointInfo.getBinding()).andReturn(bindingInfo).anyTimes();
- EasyMock.expect(endpointInfo.getProperties()).andReturn(new HashMap<String, Object>()).anyTimes();
- EasyMock.expect(bindingInfo.getProperties()).andReturn(new HashMap<String, Object>()).anyTimes();
- control.replay();
+ Endpoint endpoint = mock(Endpoint.class);
+ EndpointInfo endpointInfo = mock(EndpointInfo.class);
+ when(endpoint.getEndpointInfo()).thenReturn(endpointInfo);
+ BindingInfo bindingInfo = mock(BindingInfo.class);
+ when(endpointInfo.getBinding()).thenReturn(bindingInfo);
+ when(endpointInfo.getProperties()).thenReturn(new HashMap<String, Object>());
+ when(bindingInfo.getProperties()).thenReturn(new HashMap<String, Object>());
Message message = new MessageImpl();
ExchangeImpl exchange = new ExchangeImpl();
diff --git a/core/src/test/java/org/apache/cxf/interceptor/OutgoingChainInterceptorTest.java b/core/src/test/java/org/apache/cxf/interceptor/OutgoingChainInterceptorTest.java
index 9f8e2bfabf..6519dbf921 100644
--- a/core/src/test/java/org/apache/cxf/interceptor/OutgoingChainInterceptorTest.java
+++ b/core/src/test/java/org/apache/cxf/interceptor/OutgoingChainInterceptorTest.java
@@ -38,15 +38,16 @@ import org.apache.cxf.service.model.BindingOperationInfo;
import org.apache.cxf.service.model.MessageInfo;
import org.apache.cxf.service.model.OperationInfo;
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
public class OutgoingChainInterceptorTest {
- private IMocksControl control;
private Bus bus;
private Service service;
private Endpoint endpoint;
@@ -61,44 +62,34 @@ public class OutgoingChainInterceptorTest {
@Before
public void setUp() throws Exception {
- control = EasyMock.createNiceControl();
-
phases = new ArrayList<>();
phases.add(new Phase(Phase.SEND, 1000));
empty = new ArrayList<>();
- bus = control.createMock(Bus.class);
+ bus = mock(Bus.class);
PhaseManager pm = new PhaseManagerImpl();
- EasyMock.expect(bus.getExtension(PhaseManager.class)).andReturn(pm).anyTimes();
+ when(bus.getExtension(PhaseManager.class)).thenReturn(pm);
- service = control.createMock(Service.class);
- endpoint = control.createMock(Endpoint.class);
- binding = control.createMock(Binding.class);
- EasyMock.expect(endpoint.getBinding()).andStubReturn(binding);
+ service = mock(Service.class);
+ endpoint = mock(Endpoint.class);
+ binding = mock(Binding.class);
+ when(endpoint.getBinding()).thenReturn(binding);
MessageImpl m = new MessageImpl();
- EasyMock.expect(binding.createMessage()).andStubReturn(m);
-
- EasyMock.expect(endpoint.getService()).andReturn(service).anyTimes();
- EasyMock.expect(endpoint.getOutInterceptors()).andReturn(empty);
- EasyMock.expect(service.getOutInterceptors()).andReturn(empty);
- EasyMock.expect(bus.getOutInterceptors()).andReturn(empty);
-
- bopInfo = control.createMock(BindingOperationInfo.class);
- opInfo = control.createMock(OperationInfo.class);
- mInfo = control.createMock(MessageInfo.class);
- bmInfo = control.createMock(BindingMessageInfo.class);
- EasyMock.expect(bopInfo.getOperationInfo()).andReturn(opInfo).times(3);
- EasyMock.expect(opInfo.getOutput()).andReturn(mInfo);
- EasyMock.expect(opInfo.isOneWay()).andReturn(false);
- EasyMock.expect(bopInfo.getOutput()).andReturn(bmInfo);
-
- control.replay();
-
- }
-
- @After
- public void tearDown() {
- control.verify();
+ when(binding.createMessage()).thenReturn(m);
+
+ when(endpoint.getService()).thenReturn(service);
+ when(endpoint.getOutInterceptors()).thenReturn(empty);
+ when(service.getOutInterceptors()).thenReturn(empty);
+ when(bus.getOutInterceptors()).thenReturn(empty);
+
+ bopInfo = mock(BindingOperationInfo.class);
+ opInfo = mock(OperationInfo.class);
+ mInfo = mock(MessageInfo.class);
+ bmInfo = mock(BindingMessageInfo.class);
+ when(bopInfo.getOperationInfo()).thenReturn(opInfo);
+ when(opInfo.getOutput()).thenReturn(mInfo);
+ when(opInfo.isOneWay()).thenReturn(false);
+ when(bopInfo.getOutput()).thenReturn(bmInfo);
}
@Test
@@ -114,6 +105,8 @@ public class OutgoingChainInterceptorTest {
exchange.put(BindingOperationInfo.class, bopInfo);
exchange.setOutMessage(m);
intc.handleMessage(m);
+
+ verify(bopInfo, times(3)).getOperationInfo();
}
}
diff --git a/core/src/test/java/org/apache/cxf/interceptor/ServiceInvokerInterceptorTest.java b/core/src/test/java/org/apache/cxf/interceptor/ServiceInvokerInterceptorTest.java
index bf081953ed..293812a6fb 100644
--- a/core/src/test/java/org/apache/cxf/interceptor/ServiceInvokerInterceptorTest.java
+++ b/core/src/test/java/org/apache/cxf/interceptor/ServiceInvokerInterceptorTest.java
@@ -32,13 +32,13 @@ import org.apache.cxf.service.ServiceImpl;
import org.apache.cxf.service.invoker.Invoker;
import org.apache.cxf.service.model.ServiceInfo;
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class ServiceInvokerInterceptorTest {
@@ -70,15 +70,12 @@ public class ServiceInvokerInterceptorTest {
}
Endpoint createEndpoint(Invoker i) throws Exception {
- IMocksControl control = EasyMock.createNiceControl();
- Endpoint endpoint = control.createMock(Endpoint.class);
+ Endpoint endpoint = mock(Endpoint.class);
ServiceImpl service = new ServiceImpl((ServiceInfo)null);
service.setInvoker(i);
service.setExecutor(new SimpleExecutor());
- EasyMock.expect(endpoint.getService()).andReturn(service).anyTimes();
-
- control.replay();
+ when(endpoint.getService()).thenReturn(service);
return endpoint;
}
diff --git a/core/src/test/java/org/apache/cxf/interceptor/security/JAASLoginInterceptorTest.java b/core/src/test/java/org/apache/cxf/interceptor/security/JAASLoginInterceptorTest.java
index acb184e204..c8f325a000 100644
--- a/core/src/test/java/org/apache/cxf/interceptor/security/JAASLoginInterceptorTest.java
+++ b/core/src/test/java/org/apache/cxf/interceptor/security/JAASLoginInterceptorTest.java
@@ -39,10 +39,11 @@ import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageImpl;
import org.apache.cxf.security.transport.TLSSessionInfo;
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
import org.junit.Test;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
public class JAASLoginInterceptorTest {
private static final String TEST_SUBJECT_DN = "CN=" + TestUserPasswordLoginModule.TESTUSER
@@ -115,12 +116,10 @@ public class JAASLoginInterceptorTest {
}
private X509Certificate createTestCert(String subjectDn) {
- IMocksControl c = EasyMock.createControl();
- X509Certificate cert = c.createMock(X509Certificate.class);
- Principal principal = c.createMock(Principal.class);
- EasyMock.expect(principal.getName()).andReturn(subjectDn);
- EasyMock.expect(cert.getSubjectDN()).andReturn(principal);
- c.replay();
+ X509Certificate cert = mock(X509Certificate.class);
+ Principal principal = mock(Principal.class);
+ when(principal.getName()).thenReturn(subjectDn);
+ when(cert.getSubjectDN()).thenReturn(principal);
return cert;
}
diff --git a/core/src/test/java/org/apache/cxf/interceptor/security/OperationInfoAuthorizingInterceptorTest.java b/core/src/test/java/org/apache/cxf/interceptor/security/OperationInfoAuthorizingInterceptorTest.java
index fb7096b3a8..a2eb6ac806 100755
--- a/core/src/test/java/org/apache/cxf/interceptor/security/OperationInfoAuthorizingInterceptorTest.java
+++ b/core/src/test/java/org/apache/cxf/interceptor/security/OperationInfoAuthorizingInterceptorTest.java
@@ -29,27 +29,28 @@ import org.apache.cxf.service.invoker.MethodDispatcher;
import org.apache.cxf.service.model.BindingOperationInfo;
import org.apache.cxf.service.model.OperationInfo;
-import org.easymock.EasyMock;
import org.junit.Before;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
public class OperationInfoAuthorizingInterceptorTest extends SimpleAuthorizingInterceptorTest {
@Before
@Override
public void setUp() throws Exception {
Exchange ex = setUpExchange();
- Service service = EasyMock.createMock(Service.class);
+ Service service = mock(Service.class);
ex.put(Service.class, service);
- MethodDispatcher md = EasyMock.createMock(MethodDispatcher.class);
- EasyMock.expect(service.get(MethodDispatcher.class.getName())).andReturn(md).anyTimes();
+ MethodDispatcher md = mock(MethodDispatcher.class);
+ when(service.get(MethodDispatcher.class.getName())).thenReturn(md);
- BindingOperationInfo boi = EasyMock.createMock(BindingOperationInfo.class);
+ BindingOperationInfo boi = mock(BindingOperationInfo.class);
ex.put(BindingOperationInfo.class, boi);
- EasyMock.expect(md.getMethod(boi)).andReturn(null);
- OperationInfo opinfo = EasyMock.createMock(OperationInfo.class);
- EasyMock.expect(opinfo.getName()).andReturn(new QName("urn:test", "echo")).anyTimes();
- EasyMock.expect(boi.getOperationInfo()).andReturn(opinfo).anyTimes();
- EasyMock.replay(service, md, boi, opinfo);
+ when(md.getMethod(boi)).thenReturn(null);
+ OperationInfo opinfo = mock(OperationInfo.class);
+ when(opinfo.getName()).thenReturn(new QName("urn:test", "echo"));
+ when(boi.getOperationInfo()).thenReturn(opinfo);
}
@Override
diff --git a/core/src/test/java/org/apache/cxf/interceptor/security/SecureAnnotationsInterceptorTest.java b/core/src/test/java/org/apache/cxf/interceptor/security/SecureAnnotationsInterceptorTest.java
index bb5c254056..dea2b0a25b 100644
--- a/core/src/test/java/org/apache/cxf/interceptor/security/SecureAnnotationsInterceptorTest.java
+++ b/core/src/test/java/org/apache/cxf/interceptor/security/SecureAnnotationsInterceptorTest.java
@@ -35,10 +35,11 @@ import org.apache.cxf.service.Service;
import org.apache.cxf.service.invoker.MethodDispatcher;
import org.apache.cxf.service.model.BindingOperationInfo;
-import org.easymock.EasyMock;
import org.junit.Before;
import org.junit.Test;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class SecureAnnotationsInterceptorTest {
@@ -52,15 +53,14 @@ public class SecureAnnotationsInterceptorTest {
Exchange ex = new ExchangeImpl();
message.setExchange(ex);
- Service service = EasyMock.createMock(Service.class);
+ Service service = mock(Service.class);
ex.put(Service.class, service);
- MethodDispatcher md = EasyMock.createMock(MethodDispatcher.class);
- EasyMock.expect(service.get(MethodDispatcher.class.getName())).andReturn(md);
+ MethodDispatcher md = mock(MethodDispatcher.class);
+ when(service.get(MethodDispatcher.class.getName())).thenReturn(md);
- BindingOperationInfo boi = EasyMock.createMock(BindingOperationInfo.class);
+ BindingOperationInfo boi = mock(BindingOperationInfo.class);
ex.put(BindingOperationInfo.class, boi);
- EasyMock.expect(md.getMethod(boi)).andReturn(method);
- EasyMock.replay(service, md);
+ when(md.getMethod(boi)).thenReturn(method);
}
@Test
diff --git a/core/src/test/java/org/apache/cxf/interceptor/security/SimpleAuthorizingInterceptorTest.java b/core/src/test/java/org/apache/cxf/interceptor/security/SimpleAuthorizingInterceptorTest.java
index f8c63df455..3f923726ee 100644
--- a/core/src/test/java/org/apache/cxf/interceptor/security/SimpleAuthorizingInterceptorTest.java
+++ b/core/src/test/java/org/apache/cxf/interceptor/security/SimpleAuthorizingInterceptorTest.java
@@ -32,10 +32,12 @@ import org.apache.cxf.service.Service;
import org.apache.cxf.service.invoker.MethodDispatcher;
import org.apache.cxf.service.model.BindingOperationInfo;
-import org.easymock.EasyMock;
import org.junit.Before;
import org.junit.Test;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
public class SimpleAuthorizingInterceptorTest {
protected Message message = new MessageImpl();
@@ -46,15 +48,14 @@ public class SimpleAuthorizingInterceptorTest {
public void setUp() throws Exception {
method = TestService.class.getMethod("echo", new Class[]{});
Exchange ex = setUpExchange();
- Service service = EasyMock.createMock(Service.class);
+ Service service = mock(Service.class);
ex.put(Service.class, service);
- MethodDispatcher md = EasyMock.createMock(MethodDispatcher.class);
- EasyMock.expect(service.get(MethodDispatcher.class.getName())).andReturn(md);
+ MethodDispatcher md = mock(MethodDispatcher.class);
+ when(service.get(MethodDispatcher.class.getName())).thenReturn(md);
- BindingOperationInfo boi = EasyMock.createMock(BindingOperationInfo.class);
+ BindingOperationInfo boi = mock(BindingOperationInfo.class);
ex.put(BindingOperationInfo.class, boi);
- EasyMock.expect(md.getMethod(boi)).andReturn(method);
- EasyMock.replay(service, md);
+ when(md.getMethod(boi)).thenReturn(method);
}
protected Exchange setUpExchange() {
diff --git a/core/src/test/java/org/apache/cxf/io/CachedStreamTestBase.java b/core/src/test/java/org/apache/cxf/io/CachedStreamTestBase.java
index 91cae1f722..9ad61f47c7 100755
--- a/core/src/test/java/org/apache/cxf/io/CachedStreamTestBase.java
+++ b/core/src/test/java/org/apache/cxf/io/CachedStreamTestBase.java
@@ -34,8 +34,6 @@ import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
import org.apache.cxf.helpers.IOUtils;
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
@@ -43,6 +41,9 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public abstract class CachedStreamTestBase {
// use two typical ciphers for testing
@@ -230,19 +231,15 @@ public abstract class CachedStreamTestBase {
assertNull("expects no tmp file", tmpfile);
close(cache);
- IMocksControl control = EasyMock.createControl();
-
- Bus b = control.createMock(Bus.class);
- EasyMock.expect(b.getProperty(CachedConstants.THRESHOLD_BUS_PROP)).andReturn("4");
- EasyMock.expect(b.getProperty(CachedConstants.MAX_SIZE_BUS_PROP)).andReturn(null);
- EasyMock.expect(b.getProperty(CachedConstants.CIPHER_TRANSFORMATION_BUS_PROP)).andReturn(null);
+ Bus b = mock(Bus.class);
+ when(b.getProperty(CachedConstants.THRESHOLD_BUS_PROP)).thenReturn("4");
+ when(b.getProperty(CachedConstants.MAX_SIZE_BUS_PROP)).thenReturn(null);
+ when(b.getProperty(CachedConstants.CIPHER_TRANSFORMATION_BUS_PROP)).thenReturn(null);
Path tmpDirPath = Files.createTempDirectory("temp-dir");
- EasyMock.expect(b.getProperty(CachedConstants.OUTPUT_DIRECTORY_BUS_PROP)).andReturn(tmpDirPath.toString());
+ when(b.getProperty(CachedConstants.OUTPUT_DIRECTORY_BUS_PROP)).thenReturn(tmpDirPath.toString());
BusFactory.setThreadDefaultBus(b);
- control.replay();
-
cache = createCache();
tmpfile = getTmpFile("Hello World!", cache);
assertEquals(tmpfile.getParent(), tmpDirPath.toString());
@@ -250,8 +247,11 @@ public abstract class CachedStreamTestBase {
assertTrue("expects a tmp file", tmpfile.exists());
close(cache);
assertFalse("expects no tmp file", tmpfile.exists());
-
- control.verify();
+
+ verify(b).getProperty(CachedConstants.THRESHOLD_BUS_PROP);
+ verify(b).getProperty(CachedConstants.MAX_SIZE_BUS_PROP);
+ verify(b).getProperty(CachedConstants.CIPHER_TRANSFORMATION_BUS_PROP);
+ verify(b).getProperty(CachedConstants.OUTPUT_DIRECTORY_BUS_PROP);
} finally {
BusFactory.setThreadDefaultBus(oldbus);
}
diff --git a/core/src/test/java/org/apache/cxf/phase/PhaseInterceptorChainTest.java b/core/src/test/java/org/apache/cxf/phase/PhaseInterceptorChainTest.java
index 6101af50b7..8067b0fdf0 100644
--- a/core/src/test/java/org/apache/cxf/phase/PhaseInterceptorChainTest.java
+++ b/core/src/test/java/org/apache/cxf/phase/PhaseInterceptorChainTest.java
@@ -35,9 +35,6 @@ import org.apache.cxf.logging.FaultListener;
import org.apache.cxf.message.FaultMode;
import org.apache.cxf.message.Message;
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -45,20 +42,23 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.isA;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class PhaseInterceptorChainTest {
- private IMocksControl control;
-
private PhaseInterceptorChain chain;
private Message message;
@Before
public void setUp() {
-
- control = EasyMock.createNiceControl();
- message = control.createMock(Message.class);
+ message = mock(Message.class);
Phase phase1 = new Phase("phase1", 1);
Phase phase2 = new Phase("phase2", 2);
@@ -71,16 +71,10 @@ public class PhaseInterceptorChainTest {
chain = new PhaseInterceptorChain(phases);
}
- @After
- public void tearDown() {
- control.verify();
- }
-
@Test
public void testState() throws Exception {
AbstractPhaseInterceptor<? extends Message> p = setUpPhaseInterceptor("phase1", "p1");
- control.replay();
chain.add(p);
assertSame("Initial state is State.EXECUTING",
@@ -103,10 +97,7 @@ public class PhaseInterceptorChainTest {
SuspendedInvocationInterceptor p2 =
new SuspendedInvocationInterceptor("phase2", "p2");
- message.getInterceptorChain();
- EasyMock.expectLastCall().andReturn(chain).anyTimes();
-
- control.replay();
+ when(message.getInterceptorChain()).thenReturn(chain);
chain.add(p1);
chain.add(p2);
@@ -121,12 +112,13 @@ public class PhaseInterceptorChainTest {
assertSame("No previous interceptor selected", p1, chain.iterator().next());
assertSame("Suspended invocation should lead to State.PAUSED",
InterceptorChain.State.PAUSED, chain.getState());
+
+ verify(message).getInterceptorChain();
}
@Test
public void testAddOneInterceptor() throws Exception {
AbstractPhaseInterceptor<? extends Message> p = setUpPhaseInterceptor("phase1", "p1");
- control.replay();
chain.add(p);
Iterator<Interceptor<? extends Message>> it = chain.iterator();
assertSame(p, it.next());
@@ -135,9 +127,7 @@ public class PhaseInterceptorChainTest {
@Test
public void testForceAddSameInterceptor() throws Exception {
-
AbstractPhaseInterceptor<? extends Message> p = setUpPhaseInterceptor("phase1", "p1");
- control.replay();
chain.add(p, false);
chain.add(p, false);
Iterator<Interceptor<? extends Message>> it = chain.iterator();
@@ -152,10 +142,8 @@ public class PhaseInterceptorChainTest {
@Test
public void testForceAddSameInterceptorType() throws Exception {
-
AbstractPhaseInterceptor<? extends Message> p1 = setUpPhaseInterceptor("phase1", "p1");
AbstractPhaseInterceptor<? extends Message> p2 = setUpPhaseInterceptor("phase1", "p1");
- control.replay();
chain.add(p1, false);
chain.add(p2, false);
Iterator<Interceptor<? extends Message>> it = chain.iterator();
@@ -174,7 +162,6 @@ public class PhaseInterceptorChainTest {
Set<String> after = new HashSet<>();
after.add("p1");
AbstractPhaseInterceptor<? extends Message> p2 = setUpPhaseInterceptor("phase1", "p2", null, after);
- control.replay();
chain.add(p1);
chain.add(p2);
Iterator<Interceptor<? extends Message>> it = chain.iterator();
@@ -193,7 +180,6 @@ public class PhaseInterceptorChainTest {
Set<String> before1 = new HashSet<>();
before1.add("p2");
AbstractPhaseInterceptor<? extends Message> p3 = setUpPhaseInterceptor("phase1", "p3", before1, null);
- control.replay();
chain.add(p3);
chain.add(p1);
chain.add(p2);
@@ -209,18 +195,18 @@ public class PhaseInterceptorChainTest {
public void testSingleInterceptorPass() throws Exception {
AbstractPhaseInterceptor<Message> p = setUpPhaseInterceptor("phase1", "p1");
setUpPhaseInterceptorInvocations(p, false, false);
- control.replay();
chain.add(p);
chain.doIntercept(message);
+ verifyPhaseInterceptorInvocations(p, false, false);
}
@Test
public void testSingleInterceptorFail() throws Exception {
AbstractPhaseInterceptor<Message> p = setUpPhaseInterceptor("phase1", "p1");
setUpPhaseInterceptorInvocations(p, true, true);
- control.replay();
chain.add(p);
chain.doIntercept(message);
+ verifyPhaseInterceptorInvocations(p, true, true);
}
@Test
@@ -228,9 +214,9 @@ public class PhaseInterceptorChainTest {
AbstractPhaseInterceptor<Message> p = setUpPhaseInterceptor("phase1", "p1");
setUpPhaseInterceptorInvocations(p, true, true);
setUpCustomLogger(true, true, false);
- control.replay();
chain.add(p);
chain.doIntercept(message);
+ verifyPhaseInterceptorInvocations(p, true, true);
}
@Test
@@ -238,9 +224,9 @@ public class PhaseInterceptorChainTest {
AbstractPhaseInterceptor<Message> p = setUpPhaseInterceptor("phase1", "p1");
setUpPhaseInterceptorInvocations(p, true, true);
setUpCustomLogger(true, true, true);
- control.replay();
chain.add(p);
chain.doIntercept(message);
+ verifyPhaseInterceptorInvocations(p, true, true);
}
@Test
@@ -248,9 +234,9 @@ public class PhaseInterceptorChainTest {
AbstractPhaseInterceptor<Message> p = setUpPhaseInterceptor("phase1", "p1");
setUpPhaseInterceptorInvocations(p, true, true);
setUpCustomLogger(false, true, false);
- control.replay();
chain.add(p);
chain.doIntercept(message);
+ verifyPhaseInterceptorInvocations(p, true, true);
}
@Test
@@ -259,10 +245,10 @@ public class PhaseInterceptorChainTest {
setUpPhaseInterceptorInvocations(p1, false, false);
AbstractPhaseInterceptor<Message> p2 = setUpPhaseInterceptor("phase1", "p2");
setUpPhaseInterceptorInvocations(p2, false, false);
- control.replay();
chain.add(p2);
chain.add(p1);
chain.doIntercept(message);
+ verifyPhaseInterceptorInvocations(p2, false, false);
}
@Test
@@ -272,11 +258,12 @@ public class PhaseInterceptorChainTest {
AbstractPhaseInterceptor<Message> p2 = setUpPhaseInterceptor("phase1", "p2");
setUpPhaseInterceptorInvocations(p2, true, true);
AbstractPhaseInterceptor<Message> p3 = setUpPhaseInterceptor("phase1", "p3");
- control.replay();
chain.add(p1);
chain.add(p2);
chain.add(p3);
chain.doIntercept(message);
+ verifyPhaseInterceptorInvocations(p1, false, true);
+ verifyPhaseInterceptorInvocations(p2, true, true);
}
@Test
@@ -285,10 +272,10 @@ public class PhaseInterceptorChainTest {
setUpPhaseInterceptorInvocations(p1, false, true);
AbstractPhaseInterceptor<Message> p2 = setUpPhaseInterceptor("phase1", "p2");
setUpPhaseInterceptorInvocations(p2, true, true);
- control.replay();
chain.add(p1);
chain.add(p2);
chain.doIntercept(message);
+ verifyPhaseInterceptorInvocations(p2, true, true);
}
@Test
@@ -297,10 +284,10 @@ public class PhaseInterceptorChainTest {
setUpPhaseInterceptorInvocations(p1, false, false);
AbstractPhaseInterceptor<Message> p2 = setUpPhaseInterceptor("phase2", "p2");
setUpPhaseInterceptorInvocations(p2, false, false);
- control.replay();
chain.add(p1);
chain.add(p2);
chain.doIntercept(message);
+ verifyPhaseInterceptorInvocations(p1, false, false);
}
@Test
@@ -309,10 +296,11 @@ public class PhaseInterceptorChainTest {
setUpPhaseInterceptorInvocations(p1, false, true);
AbstractPhaseInterceptor<Message> p2 = setUpPhaseInterceptor("phase2", "p2");
setUpPhaseInterceptorInvocations(p2, true, true);
- control.replay();
chain.add(p1);
chain.add(p2);
chain.doIntercept(message);
+ verifyPhaseInterceptorInvocations(p1, false, true);
+ verifyPhaseInterceptorInvocations(p2, true, true);
}
@Test
@@ -324,12 +312,13 @@ public class PhaseInterceptorChainTest {
setUpPhaseInterceptorInvocations(p3, false, false);
InsertingPhaseInterceptor p1 = new InsertingPhaseInterceptor(chain, p2,
"phase1", "p1");
- control.replay();
chain.add(p3);
chain.add(p1);
chain.doIntercept(message);
assertEquals(1, p1.invoked);
assertEquals(0, p1.faultInvoked);
+ verifyPhaseInterceptorInvocations(p2, false, false);
+ verifyPhaseInterceptorInvocations(p3, false, false);
}
@Test
@@ -344,12 +333,12 @@ public class PhaseInterceptorChainTest {
InsertingPhaseInterceptor p1 = new InsertingPhaseInterceptor(chain, p3,
"phase1", "p1");
p1.addBefore("p2");
- control.replay();
chain.add(p1);
chain.add(p2);
chain.doIntercept(message);
assertEquals(1, p1.invoked);
assertEquals(0, p1.faultInvoked);
+ verifyPhaseInterceptorInvocations(p2, false, false);
}
@Test
@@ -361,10 +350,8 @@ public class PhaseInterceptorChainTest {
CountingPhaseInterceptor p3 = new CountingPhaseInterceptor("phase3",
"p3");
- message.getInterceptorChain();
- EasyMock.expectLastCall().andReturn(chain).anyTimes();
+ when(message.getInterceptorChain()).thenReturn(chain);
- control.replay();
chain.add(p1);
chain.add(p2);
chain.add(p3);
@@ -372,6 +359,8 @@ public class PhaseInterceptorChainTest {
assertEquals(1, p1.invoked);
assertEquals(1, p2.invoked);
assertEquals(1, p3.invoked);
+
+ verify(message).getInterceptorChain();
}
@Test
@@ -383,10 +372,8 @@ public class PhaseInterceptorChainTest {
CountingPhaseInterceptor p3 = new CountingPhaseInterceptor("phase3",
"p3");
- message.getInterceptorChain();
- EasyMock.expectLastCall().andReturn(chain).anyTimes();
+ when(message.getInterceptorChain()).thenReturn(chain);
- control.replay();
chain.add(p1);
chain.add(p2);
chain.add(p3);
@@ -394,6 +381,8 @@ public class PhaseInterceptorChainTest {
assertEquals(0, p1.invoked);
assertEquals(0, p2.invoked);
assertEquals(1, p3.invoked);
+
+ verify(message, never()).getInterceptorChain();
}
AbstractPhaseInterceptor<Message> setUpPhaseInterceptor(String phase, String id) throws Exception {
@@ -405,8 +394,8 @@ public class PhaseInterceptorChainTest {
Set<String> b,
Set<String> a) throws Exception {
- AbstractPhaseInterceptor<Message> p = control
- .createMock(AbstractPhaseInterceptor.class);
+ @SuppressWarnings("unchecked")
+ AbstractPhaseInterceptor<Message> p = mock(AbstractPhaseInterceptor.class);
if (a == null) {
a = new SortedArraySet<>();
@@ -435,18 +424,20 @@ public class PhaseInterceptorChainTest {
void setUpPhaseInterceptorInvocations(AbstractPhaseInterceptor<Message> p,
boolean fail, boolean expectFault) {
- p.handleMessage(message);
if (fail) {
- EasyMock.expectLastCall().andThrow(new RuntimeException());
- message.setContent(EasyMock.eq(Exception.class),
- EasyMock.isA(Exception.class));
- EasyMock.expectLastCall();
+ doThrow(new RuntimeException()).when(p).handleMessage(message);
+ }
+ }
+
+ void verifyPhaseInterceptorInvocations(AbstractPhaseInterceptor<Message> p,
+ boolean fail, boolean expectFault) {
+ if (fail) {
+ verify(message).setContent(eq(Exception.class), isA(Exception.class));
} else {
- EasyMock.expectLastCall();
+ verify(p).handleMessage(message);
}
if (expectFault) {
- p.handleFault(message);
- EasyMock.expectLastCall();
+ verify(p).handleFault(message);
}
}
@@ -454,21 +445,20 @@ public class PhaseInterceptorChainTest {
boolean expectFault,
boolean returnFromCustomLogger) {
if (useCustomLogger) {
- FaultListener customLogger = control.createMock(FaultListener.class);
- EasyMock.expect(message.getContextualProperty(FaultListener.class.getName())).andReturn(customLogger);
+ FaultListener customLogger = mock(FaultListener.class);
+ when(message.getContextualProperty(FaultListener.class.getName())).thenReturn(customLogger);
if (expectFault) {
- customLogger.faultOccurred(EasyMock.isA(Exception.class),
- EasyMock.isA(String.class),
- EasyMock.isA(Message.class));
- EasyMock.expectLastCall().andReturn(returnFromCustomLogger);
+ when(customLogger.faultOccurred(isA(Exception.class),
+ isA(String.class),
+ isA(Message.class))).thenReturn(returnFromCustomLogger);
if (returnFromCustomLogger) {
//default logging should also be invoked
//not too beautiful way to verify that defaultLogging was invoked.
- EasyMock.expect(message.get(FaultMode.class)).andReturn(FaultMode.RUNTIME_FAULT);
+ when(message.get(FaultMode.class)).thenReturn(FaultMode.RUNTIME_FAULT);
}
}
} else {
- EasyMock.expect(message.getContextualProperty(FaultListener.class.getName())).andReturn(null);
+ when(message.getContextualProperty(FaultListener.class.getName())).thenReturn(null);
}
}
diff --git a/core/src/test/java/org/apache/cxf/staxutils/validation/Stax2ValidationUtilsTest.java b/core/src/test/java/org/apache/cxf/staxutils/validation/Stax2ValidationUtilsTest.java
index 5493c9f6f0..f9058051c0 100644
--- a/core/src/test/java/org/apache/cxf/staxutils/validation/Stax2ValidationUtilsTest.java
+++ b/core/src/test/java/org/apache/cxf/staxutils/validation/Stax2ValidationUtilsTest.java
@@ -42,16 +42,15 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
-import static org.easymock.EasyMock.anyObject;
-import static org.easymock.EasyMock.anyString;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.mock;
-import static org.easymock.EasyMock.replay;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
@RunWith(Parameterized.class)
public class Stax2ValidationUtilsTest {
@@ -121,10 +120,9 @@ public class Stax2ValidationUtilsTest {
schemaCol.read(new StreamSource(io, sysId));
serviceInfo.addSchema(schemaInfo);
schemaInfo.setSchema(schemaCol.getXmlSchema(sysId)[0]);
- expect(endpoint.get(anyObject())).andReturn(null);
- expect(endpoint.containsKey(anyObject())).andReturn(false);
- expect(endpoint.put(anyString(), anyObject())).andReturn(null);
- replay(endpoint);
+ when(endpoint.get(any())).thenReturn(null);
+ when(endpoint.containsKey(any())).thenReturn(false);
+ when(endpoint.put(anyString(), any())).thenReturn(null);
}
@Test
diff --git a/core/src/test/java/org/apache/cxf/transport/ChainInitiationObserverTest.java b/core/src/test/java/org/apache/cxf/transport/ChainInitiationObserverTest.java
index 278600c681..c77e9ea2bb 100644
--- a/core/src/test/java/org/apache/cxf/transport/ChainInitiationObserverTest.java
+++ b/core/src/test/java/org/apache/cxf/transport/ChainInitiationObserverTest.java
@@ -26,17 +26,17 @@ import org.apache.cxf.message.Message;
import org.apache.cxf.phase.Phase;
import org.apache.cxf.phase.PhaseInterceptorChain;
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class ChainInitiationObserverTest {
- private IMocksControl control;
private TestChain chain;
private Message message;
private ChainInitiationObserver observer;
@@ -44,8 +44,7 @@ public class ChainInitiationObserverTest {
@Before
public void setUp() {
- control = EasyMock.createNiceControl();
- message = control.createMock(Message.class);
+ message = mock(Message.class);
Phase phase1 = new Phase("phase1", 1);
SortedSet<Phase> phases = new TreeSet<>();
@@ -54,19 +53,14 @@ public class ChainInitiationObserverTest {
observer = new ChainInitiationObserver(null, null);
}
- @After
- public void tearDown() {
- control.verify();
- }
-
@Test
public void testPausedChain() {
- message.getInterceptorChain();
- EasyMock.expectLastCall().andReturn(chain).times(2);
- control.replay();
+ when(message.getInterceptorChain()).thenReturn(chain);
observer.onMessage(message);
assertTrue(chain.isInvoked());
+
+ verify(message, times(2)).getInterceptorChain();
}
private static class TestChain extends PhaseInterceptorChain {
diff --git a/core/src/test/java/org/apache/cxf/transport/common/gzip/GZIPAcceptEncodingTest.java b/core/src/test/java/org/apache/cxf/transport/common/gzip/GZIPAcceptEncodingTest.java
index 2e007a57a2..a529639c7c 100644
--- a/core/src/test/java/org/apache/cxf/transport/common/gzip/GZIPAcceptEncodingTest.java
+++ b/core/src/test/java/org/apache/cxf/transport/common/gzip/GZIPAcceptEncodingTest.java
@@ -35,7 +35,6 @@ import org.apache.cxf.message.ExchangeImpl;
import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageImpl;
-import org.easymock.EasyMock;
import org.junit.Before;
import org.junit.Test;
@@ -43,6 +42,7 @@ import static org.apache.cxf.transport.common.gzip.GZIPOutInterceptor.UseGzip.FO
import static org.apache.cxf.transport.common.gzip.GZIPOutInterceptor.UseGzip.YES;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
+import static org.mockito.Mockito.mock;
/**
* Test for the parsing of Accept-Encoding by the GZIPOutInterceptor. For
@@ -70,13 +70,12 @@ public class GZIPAcceptEncodingTest {
exchange.setOutMessage(outMessage);
outMessage.setExchange(exchange);
outMessage.setContent(OutputStream.class, new ByteArrayOutputStream());
- outInterceptors = EasyMock.createMock(InterceptorChain.class);
+ outInterceptors = mock(InterceptorChain.class);
outMessage.setInterceptorChain(outInterceptors);
}
@Test
public void testNoAcceptEncoding() throws Exception {
- EasyMock.replay(outInterceptors);
interceptor.handleMessage(outMessage);
}
@@ -112,7 +111,6 @@ public class GZIPAcceptEncodingTest {
@Test(expected = Fault.class)
public void testNoValidEncodings() throws Exception {
- EasyMock.replay();
setAcceptEncoding("*;q=0, deflate;q=0.5");
interceptor.handleMessage(outMessage);
}
@@ -121,7 +119,6 @@ public class GZIPAcceptEncodingTest {
GZIPOutInterceptor.UseGzip expectedUseGzip, String expectedGzipEncoding)
throws Exception {
- EasyMock.replay(outInterceptors);
setAcceptEncoding(encoding);
interceptor.handleMessage(outMessage);
assertSame("Wrong value of " + GZIPOutInterceptor.USE_GZIP_KEY, expectedUseGzip, outMessage