From 324d2ca6e2dcbd9b08a2c85cb3382b76d411dbae Mon Sep 17 00:00:00 2001 From: Andriy Redko Date: Fri, 11 Aug 2023 17:14:51 -0400 Subject: [PATCH] CXF-8848: Get rid of EasyMock in cxf-rt-databinding-jaxb --- rt/databinding/jaxb/pom.xml | 5 +++-- .../cxf/jaxb/BareInInterceptorTest.java | 20 +++++++++---------- .../cxf/jaxb/BareOutInterceptorTest.java | 8 ++------ .../cxf/jaxb/DocLiteralInInterceptorTest.java | 20 +++++++++---------- .../apache/cxf/jaxb/JAXBDataBindingTest.java | 20 ++++++++----------- .../java/org/apache/cxf/jaxb/TestBase.java | 20 +++++++++---------- 6 files changed, 40 insertions(+), 53 deletions(-) diff --git a/rt/databinding/jaxb/pom.xml b/rt/databinding/jaxb/pom.xml index 37dfdea58a8..785f62c0c33 100644 --- a/rt/databinding/jaxb/pom.xml +++ b/rt/databinding/jaxb/pom.xml @@ -95,8 +95,9 @@ test - org.easymock - easymock + org.mockito + mockito-core + ${cxf.mockito.version} test diff --git a/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/BareInInterceptorTest.java b/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/BareInInterceptorTest.java index ceb7eb747a3..885a1cae759 100644 --- a/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/BareInInterceptorTest.java +++ b/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/BareInInterceptorTest.java @@ -55,15 +55,14 @@ import org.apache.hello_world_soap_http.types.GreetMe; import org.apache.hello_world_soap_http.types.GreetMeResponse; -import org.easymock.IMocksControl; import org.junit.Before; import org.junit.Test; -import static org.easymock.EasyMock.createNiceControl; -import static org.easymock.EasyMock.expect; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class BareInInterceptorTest { @@ -83,14 +82,13 @@ public void setUp() throws Exception { BindingFactoryManager bfm = bus.getExtension(BindingFactoryManager.class); - IMocksControl control = createNiceControl(); - BindingFactory bf = control.createMock(BindingFactory.class); - Binding binding = control.createMock(Binding.class); - expect(bf.createBinding(null)).andStubReturn(binding); - expect(binding.getInFaultInterceptors()) - .andStubReturn(new ArrayList>()); - expect(binding.getOutFaultInterceptors()) - .andStubReturn(new ArrayList>()); + BindingFactory bf = mock(BindingFactory.class); + Binding binding = mock(Binding.class); + when(bf.createBinding(null)).thenReturn(binding); + when(binding.getInFaultInterceptors()) + .thenReturn(new ArrayList>()); + when(binding.getOutFaultInterceptors()) + .thenReturn(new ArrayList>()); bfm.registerBindingFactory("http://schemas.xmlsoap.org/wsdl/soap/", bf); diff --git a/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/BareOutInterceptorTest.java b/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/BareOutInterceptorTest.java index 40966c8c3e5..d670f6c3eab 100644 --- a/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/BareOutInterceptorTest.java +++ b/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/BareOutInterceptorTest.java @@ -37,15 +37,13 @@ import org.apache.hello_world_soap_http.types.GreetMe; import org.apache.hello_world_soap_http.types.GreetMeResponse; -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.assertEquals; import static org.junit.Assert.assertNull; - +import static org.mockito.Mockito.mock; public class BareOutInterceptorTest extends TestBase { @@ -63,10 +61,8 @@ public void setUp() throws Exception { writer = getXMLStreamWriter(baos); message.setContent(XMLStreamWriter.class, writer); message.getExchange().put(BindingOperationInfo.class, operation); - IMocksControl control = EasyMock.createNiceControl(); - InterceptorChain ic = control.createMock(InterceptorChain.class); + InterceptorChain ic = mock(InterceptorChain.class); message.setInterceptorChain(ic); - control.replay(); } @After diff --git a/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/DocLiteralInInterceptorTest.java b/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/DocLiteralInInterceptorTest.java index 770816438c3..be41117f780 100644 --- a/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/DocLiteralInInterceptorTest.java +++ b/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/DocLiteralInInterceptorTest.java @@ -54,15 +54,14 @@ import org.apache.hello_world_soap_http.types.GreetMe; import org.apache.hello_world_soap_http.types.GreetMeResponse; -import org.easymock.IMocksControl; import org.junit.Before; import org.junit.Test; -import static org.easymock.EasyMock.createNiceControl; -import static org.easymock.EasyMock.expect; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class DocLiteralInInterceptorTest { PhaseInterceptorChain chain; @@ -80,14 +79,13 @@ public void setUp() throws Exception { BindingFactoryManager bfm = bus.getExtension(BindingFactoryManager.class); - IMocksControl control = createNiceControl(); - BindingFactory bf = control.createMock(BindingFactory.class); - Binding binding = control.createMock(Binding.class); - expect(bf.createBinding(null)).andStubReturn(binding); - expect(binding.getInFaultInterceptors()) - .andStubReturn(new ArrayList>()); - expect(binding.getOutFaultInterceptors()) - .andStubReturn(new ArrayList>()); + BindingFactory bf = mock(BindingFactory.class); + Binding binding = mock(Binding.class); + when(bf.createBinding(null)).thenReturn(binding); + when(binding.getInFaultInterceptors()) + .thenReturn(new ArrayList>()); + when(binding.getOutFaultInterceptors()) + .thenReturn(new ArrayList>()); bfm.registerBindingFactory("http://schemas.xmlsoap.org/wsdl/soap/", bf); } diff --git a/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBDataBindingTest.java b/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBDataBindingTest.java index 52007caaef0..145405b01bf 100644 --- a/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBDataBindingTest.java +++ b/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/JAXBDataBindingTest.java @@ -70,8 +70,6 @@ import org.apache.hello_world_soap_http.types.GreetMe; import org.apache.hello_world_soap_http.types.GreetMeOneWay; -import org.easymock.EasyMock; -import org.easymock.IMocksControl; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -81,6 +79,8 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class JAXBDataBindingTest { @@ -89,7 +89,6 @@ public class JAXBDataBindingTest { private Definition def; private Service service; - private IMocksControl control; private Bus bus; private BindingFactoryManager bindingFactoryManager; private JAXBDataBinding jaxbDataBinding; @@ -106,16 +105,13 @@ public void setUp() throws Exception { def = wsdlReader.readWSDL(wsdlUrl); - control = EasyMock.createNiceControl(); - bus = control.createMock(Bus.class); - bindingFactoryManager = control.createMock(BindingFactoryManager.class); - destinationFactoryManager = control.createMock(DestinationFactoryManager.class); + bus = mock(Bus.class); + bindingFactoryManager = mock(BindingFactoryManager.class); + destinationFactoryManager = mock(DestinationFactoryManager.class); - EasyMock.expect(bus.getExtension(BindingFactoryManager.class)).andStubReturn(bindingFactoryManager); - EasyMock.expect(bus.getExtension(DestinationFactoryManager.class)) - .andStubReturn(destinationFactoryManager); - - control.replay(); + when(bus.getExtension(BindingFactoryManager.class)).thenReturn(bindingFactoryManager); + when(bus.getExtension(DestinationFactoryManager.class)) + .thenReturn(destinationFactoryManager); WSDLServiceBuilder wsdlServiceBuilder = new WSDLServiceBuilder(bus); for (Service serv : CastUtils.cast(def.getServices().values(), Service.class)) { diff --git a/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/TestBase.java b/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/TestBase.java index 06175fa3124..c6b3e6bf22b 100644 --- a/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/TestBase.java +++ b/rt/databinding/jaxb/src/test/java/org/apache/cxf/jaxb/TestBase.java @@ -52,12 +52,11 @@ import org.apache.hello_world_soap_http.types.GreetMe; import org.apache.hello_world_soap_http.types.GreetMeResponse; -import org.easymock.IMocksControl; import org.junit.After; import org.junit.Before; -import static org.easymock.EasyMock.createNiceControl; -import static org.easymock.EasyMock.expect; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class TestBase { @@ -77,14 +76,13 @@ public void setUp() throws Exception { BindingFactoryManager bfm = bus.getExtension(BindingFactoryManager.class); - IMocksControl control = createNiceControl(); - BindingFactory bf = control.createMock(BindingFactory.class); - Binding binding = control.createMock(Binding.class); - expect(bf.createBinding(null)).andStubReturn(binding); - expect(binding.getInFaultInterceptors()) - .andStubReturn(new ArrayList>()); - expect(binding.getOutFaultInterceptors()) - .andStubReturn(new ArrayList>()); + BindingFactory bf = mock(BindingFactory.class); + Binding binding = mock(Binding.class); + when(bf.createBinding(null)).thenReturn(binding); + when(binding.getInFaultInterceptors()) + .thenReturn(new ArrayList>()); + when(binding.getOutFaultInterceptors()) + .thenReturn(new ArrayList>()); bfm.registerBindingFactory("http://schemas.xmlsoap.org/wsdl/soap/", bf);