From 40b02ca3e9d96e7d035f5361556778f9e7cbbef6 Mon Sep 17 00:00:00 2001 From: Andriy Redko Date: Thu, 29 Jun 2023 10:23:23 -0400 Subject: [PATCH] CXF-8861: Get rid of EasyMock in cxf-rt-ws-policy (#1315) (cherry picked from commit a0796fa149ecfa93ffb384c3b4ac5a07f82ecdc6) --- rt/ws/policy/pom.xml | 5 +- .../AssertionBuilderRegistryImplTest.java | 32 +- .../cxf/ws/policy/AssertionInfoMapTest.java | 45 +-- .../ws/policy/EffectivePolicyImplTest.java | 246 +++++------- .../cxf/ws/policy/EndpointPolicyImplTest.java | 165 ++++---- .../apache/cxf/ws/policy/NormalizeTest.java | 22 +- .../ws/policy/PolicyDataEngineImplTest.java | 13 +- .../cxf/ws/policy/PolicyEngineTest.java | 373 ++++++------------ ...cyInterceptorProviderRegistryImplTest.java | 37 +- .../cxf/ws/policy/PolicyInterceptorsTest.java | 301 ++++++-------- .../cxf/ws/policy/PolicyRegistryImplTest.java | 6 +- ...icyVerificationInFaultInterceptorTest.java | 91 ++--- .../PolicyVerificationInInterceptorTest.java | 99 ++--- .../PolicyVerificationOutInterceptorTest.java | 60 +-- .../DomainExpressionBuilderRegistryTest.java | 37 +- ...EndpointReferenceDomainExpressionTest.java | 44 +-- .../ExternalAttachmentProviderTest.java | 95 ++--- .../external/PolicyAttachmentTest.java | 82 ++-- .../external/URIDomainExpressionTest.java | 101 ++--- .../reference/ReferenceResolverTest.java | 60 ++- .../Wsdl11AttachmentPolicyProviderTest.java | 48 +-- .../builder/jaxb/JaxbAssertionTest.java | 13 +- .../FirstAlternativeSelectorTest.java | 33 +- ...MinimalMaximalAlternativeSelectorTest.java | 34 +- 24 files changed, 749 insertions(+), 1293 deletions(-) diff --git a/rt/ws/policy/pom.xml b/rt/ws/policy/pom.xml index e46f701d876..2086dea1691 100644 --- a/rt/ws/policy/pom.xml +++ b/rt/ws/policy/pom.xml @@ -119,8 +119,9 @@ test - org.easymock - easymock + org.mockito + mockito-core + ${cxf.mockito.version} test diff --git a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/AssertionBuilderRegistryImplTest.java b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/AssertionBuilderRegistryImplTest.java index de2f96d21b8..cc0ab3214ed 100644 --- a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/AssertionBuilderRegistryImplTest.java +++ b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/AssertionBuilderRegistryImplTest.java @@ -27,40 +27,25 @@ import org.apache.neethi.Assertion; import org.apache.neethi.builders.PrimitiveAssertion; -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.assertFalse; 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 AssertionBuilderRegistryImplTest { - - private IMocksControl control; - - @Before - public void setUp() { - control = EasyMock.createNiceControl(); - } - - @After - public void tearDown() { - control.verify(); - } - @Test public void testBuildUnknownAssertion() { - Bus bus = control.createMock(Bus.class); + Bus bus = mock(Bus.class); - PolicyBuilder builder = control.createMock(PolicyBuilder.class); - EasyMock.expect(bus.getExtension(PolicyBuilder.class)).andReturn(builder).anyTimes(); + PolicyBuilder builder = mock(PolicyBuilder.class); + when(bus.getExtension(PolicyBuilder.class)).thenReturn(builder); AssertionBuilderRegistryImpl reg = new AssertionBuilderRegistryImpl() { protected void loadDynamic() { @@ -72,12 +57,11 @@ protected void loadDynamic() { QName[] qnames = new QName[11]; for (int i = 0; i < 11; i++) { qnames[i] = new QName("http://my.company.com", "type" + Integer.toString(i)); - elems[i] = control.createMock(Element.class); - EasyMock.expect(elems[i].getNamespaceURI()).andReturn(qnames[i].getNamespaceURI()).anyTimes(); - EasyMock.expect(elems[i].getLocalName()).andReturn(qnames[i].getLocalPart()).anyTimes(); + elems[i] = mock(Element.class); + when(elems[i].getNamespaceURI()).thenReturn(qnames[i].getNamespaceURI()); + when(elems[i].getLocalName()).thenReturn(qnames[i].getLocalPart()); } - control.replay(); reg.setBus(bus); assertFalse(reg.isIgnoreUnknownAssertions()); diff --git a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/AssertionInfoMapTest.java b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/AssertionInfoMapTest.java index 69307c66150..56f6c5ada9f 100644 --- a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/AssertionInfoMapTest.java +++ b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/AssertionInfoMapTest.java @@ -34,9 +34,6 @@ import org.apache.neethi.Policy; import org.apache.neethi.builders.PolicyContainingPrimitiveAssertion; -import org.easymock.EasyMock; -import org.easymock.IMocksControl; -import org.junit.Before; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -44,32 +41,26 @@ import static org.junit.Assert.assertSame; 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 AssertionInfoMapTest { - - private IMocksControl control; - - @Before - public void setUp() { - control = EasyMock.createNiceControl(); - } - @Test public void testAlternativeSupported() { - PolicyAssertion a1 = control.createMock(PolicyAssertion.class); + PolicyAssertion a1 = mock(PolicyAssertion.class); QName aqn = new QName("http://x.y.z", "a"); - EasyMock.expect(a1.getName()).andReturn(aqn).anyTimes(); - PolicyAssertion a2 = control.createMock(PolicyAssertion.class); - EasyMock.expect(a2.getName()).andReturn(aqn).anyTimes(); - PolicyAssertion b = control.createMock(PolicyAssertion.class); + when(a1.getName()).thenReturn(aqn); + PolicyAssertion a2 = mock(PolicyAssertion.class); + when(a2.getName()).thenReturn(aqn); + PolicyAssertion b = mock(PolicyAssertion.class); QName bqn = new QName("http://x.y.z", "b"); - EasyMock.expect(b.getName()).andReturn(bqn).anyTimes(); - PolicyAssertion c = control.createMock(PolicyAssertion.class); + when(b.getName()).thenReturn(bqn); + PolicyAssertion c = mock(PolicyAssertion.class); QName cqn = new QName("http://x.y.z", "c"); - EasyMock.expect(c.getName()).andReturn(cqn).anyTimes(); + when(c.getName()).thenReturn(cqn); AssertionInfoMap aim = new AssertionInfoMap(CastUtils.cast(Collections.EMPTY_LIST, PolicyAssertion.class)); AssertionInfo ai1 = new AssertionInfo(a1); @@ -85,14 +76,14 @@ public void testAlternativeSupported() { ai2.setAsserted(true); bi.setAsserted(true); ci.setAsserted(true); - EasyMock.expect(a1.equal(a1)).andReturn(true).anyTimes(); - EasyMock.expect(a2.equal(a2)).andReturn(true).anyTimes(); - EasyMock.expect(b.equal(b)).andReturn(true).anyTimes(); - EasyMock.expect(c.equal(c)).andReturn(true).anyTimes(); + when(a1.equal(a1)).thenReturn(true); + when(a2.equal(a2)).thenReturn(true); + when(b.equal(b)).thenReturn(true); + when(c.equal(c)).thenReturn(true); - EasyMock.expect(a2.isAsserted(aim)).andReturn(true).anyTimes(); - EasyMock.expect(b.isAsserted(aim)).andReturn(true).anyTimes(); - EasyMock.expect(c.isAsserted(aim)).andReturn(true).anyTimes(); + when(a2.isAsserted(aim)).thenReturn(true); + when(b.isAsserted(aim)).thenReturn(true); + when(c.isAsserted(aim)).thenReturn(true); List alt1 = new ArrayList<>(); @@ -103,10 +94,8 @@ public void testAlternativeSupported() { alt2.add(a2); alt2.add(c); - control.replay(); assertFalse(aim.supportsAlternative(alt1, new ArrayList<>())); assertTrue(aim.supportsAlternative(alt2, new ArrayList<>())); - control.verify(); } @Test diff --git a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EffectivePolicyImplTest.java b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EffectivePolicyImplTest.java index 5ff1b2f9e88..8a39bce4985 100644 --- a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EffectivePolicyImplTest.java +++ b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EffectivePolicyImplTest.java @@ -19,7 +19,6 @@ package org.apache.cxf.ws.policy; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -40,32 +39,25 @@ import org.apache.neethi.Assertion; import org.apache.neethi.Policy; -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.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.fail; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; /** * */ public class EffectivePolicyImplTest { - - private IMocksControl control; private Message msg = new MessageImpl(); - @Before - public void setUp() { - control = EasyMock.createNiceControl(); - Integer.valueOf(4); - } - private List> createMockInterceptorList() { - Interceptor i = control.createMock(Interceptor.class); + @SuppressWarnings("unchecked") + Interceptor i = mock(Interceptor.class); Interceptor m = i; List> a = new ArrayList<>(); a.add(m); @@ -79,99 +71,62 @@ public void testAccessors() { assertNull(effectivePolicy.getChosenAlternative()); assertNull(effectivePolicy.getInterceptors()); - Policy p = control.createMock(Policy.class); - Assertion a = control.createMock(Assertion.class); + Policy p = mock(Policy.class); + Assertion a = mock(Assertion.class); List la = Collections.singletonList(a); List> li = createMockInterceptorList(); - control.replay(); effectivePolicy.setPolicy(p); assertSame(p, effectivePolicy.getPolicy()); effectivePolicy.setChosenAlternative(la); assertSame(la, effectivePolicy.getChosenAlternative()); effectivePolicy.setInterceptors(li); assertSame(li, effectivePolicy.getInterceptors()); - control.verify(); } @Test public void testInitialiseFromEndpointPolicy() throws NoSuchMethodException { - Method m = EffectivePolicyImpl.class.getDeclaredMethod("initialiseInterceptors", - new Class[] {PolicyEngine.class, Message.class}); - EffectivePolicyImpl effectivePolicy = EasyMock.createMockBuilder(EffectivePolicyImpl.class) - .addMockedMethod(m).createMock(control); - EndpointPolicyImpl endpointPolicy = control.createMock(EndpointPolicyImpl.class); - Policy p = control.createMock(Policy.class); - EasyMock.expect(endpointPolicy.getPolicy()).andReturn(p); + EffectivePolicyImpl effectivePolicy = spy(new EffectivePolicyImpl()); + EndpointPolicyImpl endpointPolicy = mock(EndpointPolicyImpl.class); + Policy p = mock(Policy.class); + when(endpointPolicy.getPolicy()).thenReturn(p); Collection chosenAlternative = new ArrayList<>(); - EasyMock.expect(endpointPolicy.getChosenAlternative()).andReturn(chosenAlternative); + when(endpointPolicy.getChosenAlternative()).thenReturn(chosenAlternative); PolicyEngineImpl pe = new PolicyEngineImpl(); effectivePolicy.initialiseInterceptors(pe, false, msg); - EasyMock.expectLastCall(); - control.replay(); effectivePolicy.initialise(endpointPolicy, pe, false, null); - control.verify(); } @Test public void testInitialise() throws NoSuchMethodException { - Method m1 = EffectivePolicyImpl.class.getDeclaredMethod("initialisePolicy", - new Class[] {EndpointInfo.class, - BindingOperationInfo.class, - PolicyEngine.class, - boolean.class, - boolean.class, - Assertor.class, - Message.class}); - Method m2 = EffectivePolicyImpl.class.getDeclaredMethod("chooseAlternative", - new Class[] {PolicyEngine.class, Assertor.class, Message.class}); - Method m3 = EffectivePolicyImpl.class.getDeclaredMethod("initialiseInterceptors", - new Class[] {PolicyEngine.class, Message.class}); - EffectivePolicyImpl effectivePolicy = EasyMock.createMockBuilder(EffectivePolicyImpl.class) - .addMockedMethods(m1, m2, m3).createMock(control); - EndpointInfo ei = control.createMock(EndpointInfo.class); - BindingOperationInfo boi = control.createMock(BindingOperationInfo.class); - PolicyEngineImpl pe = new PolicyEngineImpl(); - Assertor a = control.createMock(Assertor.class); + Bus bus = mock(Bus.class); + EffectivePolicyImpl effectivePolicy = spy(new EffectivePolicyImpl()); + EndpointInfo ei = mock(EndpointInfo.class); + BindingOperationInfo boi = mock(BindingOperationInfo.class); + PolicyEngineImpl pe = new PolicyEngineImpl(bus); + Assertor a = mock(Assertor.class); boolean requestor = true; - effectivePolicy.initialisePolicy(ei, boi, pe, requestor, requestor, a, null); - EasyMock.expectLastCall().andReturn(a); + when(effectivePolicy.initialisePolicy(ei, boi, pe, requestor, requestor, a, null)).thenReturn(a); effectivePolicy.chooseAlternative(pe, a, null); - EasyMock.expectLastCall(); effectivePolicy.initialiseInterceptors(pe, false, msg); - EasyMock.expectLastCall(); - control.replay(); effectivePolicy.initialise(ei, boi, pe, a, requestor, requestor, null); - control.verify(); } @Test public void testInitialiseFault() throws NoSuchMethodException { - Method m1 = EffectivePolicyImpl.class.getDeclaredMethod("initialisePolicy", - new Class[] {EndpointInfo.class, BindingOperationInfo.class, - BindingFaultInfo.class, PolicyEngine.class, Message.class}); - Method m2 = EffectivePolicyImpl.class.getDeclaredMethod("chooseAlternative", - new Class[] {PolicyEngine.class, Assertor.class, Message.class}); - Method m3 = EffectivePolicyImpl.class.getDeclaredMethod("initialiseInterceptors", - new Class[] {PolicyEngine.class, Message.class}); - EffectivePolicyImpl effectivePolicy = EasyMock.createMockBuilder(EffectivePolicyImpl.class) - .addMockedMethods(m1, m2, m3).createMock(control); - EndpointInfo ei = control.createMock(EndpointInfo.class); - BindingFaultInfo bfi = control.createMock(BindingFaultInfo.class); - PolicyEngineImpl pe = new PolicyEngineImpl(); - Assertor a = control.createMock(Assertor.class); + Bus bus = mock(Bus.class); + EffectivePolicyImpl effectivePolicy = spy(new EffectivePolicyImpl()); + EndpointInfo ei = mock(EndpointInfo.class); + BindingFaultInfo bfi = mock(BindingFaultInfo.class); + PolicyEngineImpl pe = new PolicyEngineImpl(bus); + Assertor a = mock(Assertor.class); effectivePolicy.initialisePolicy(ei, null, bfi, pe, null); - EasyMock.expectLastCall(); effectivePolicy.chooseAlternative(pe, a, null); - EasyMock.expectLastCall(); effectivePolicy.initialiseInterceptors(pe, false, msg); - EasyMock.expectLastCall(); - control.replay(); effectivePolicy.initialise(ei, null, bfi, pe, a, null); - control.verify(); } @Test @@ -185,67 +140,63 @@ public void testInitialiseServerPolicy() { } private void doTestInitialisePolicy(boolean requestor) { - EndpointInfo ei = control.createMock(EndpointInfo.class); - BindingOperationInfo boi = control.createMock(BindingOperationInfo.class); - PolicyEngineImpl engine = control.createMock(PolicyEngineImpl.class); - BindingMessageInfo bmi = control.createMock(BindingMessageInfo.class); + EndpointInfo ei = mock(EndpointInfo.class); + BindingOperationInfo boi = mock(BindingOperationInfo.class); + PolicyEngineImpl engine = mock(PolicyEngineImpl.class); + BindingMessageInfo bmi = mock(BindingMessageInfo.class); if (requestor) { - EasyMock.expect(boi.getInput()).andReturn(bmi); + when(boi.getInput()).thenReturn(bmi); } else { - EasyMock.expect(boi.getOutput()).andReturn(bmi); + when(boi.getOutput()).thenReturn(bmi); } - EndpointPolicy effectivePolicy = control.createMock(EndpointPolicy.class); + EndpointPolicy effectivePolicy = mock(EndpointPolicy.class); if (requestor) { - EasyMock.expect(engine.getClientEndpointPolicy(ei, (Conduit)null, null)).andReturn(effectivePolicy); + when(engine.getClientEndpointPolicy(ei, (Conduit)null, null)).thenReturn(effectivePolicy); } else { - EasyMock.expect(engine.getServerEndpointPolicy(ei, (Destination)null, null)).andReturn(effectivePolicy); + when(engine.getServerEndpointPolicy(ei, (Destination)null, null)).thenReturn(effectivePolicy); } - Policy ep = control.createMock(Policy.class); - EasyMock.expect(effectivePolicy.getPolicy()).andReturn(ep); - Policy op = control.createMock(Policy.class); - EasyMock.expect(engine.getAggregatedOperationPolicy(boi, null)).andReturn(op); - Policy merged = control.createMock(Policy.class); - EasyMock.expect(ep.merge(op)).andReturn(merged); - Policy mp = control.createMock(Policy.class); - EasyMock.expect(engine.getAggregatedMessagePolicy(bmi, null)).andReturn(mp); - EasyMock.expect(merged.merge(mp)).andReturn(merged); - EasyMock.expect(merged.normalize(null, true)).andReturn(merged); - - control.replay(); + Policy ep = mock(Policy.class); + when(effectivePolicy.getPolicy()).thenReturn(ep); + Policy op = mock(Policy.class); + when(engine.getAggregatedOperationPolicy(boi, null)).thenReturn(op); + Policy merged = mock(Policy.class); + when(ep.merge(op)).thenReturn(merged); + Policy mp = mock(Policy.class); + when(engine.getAggregatedMessagePolicy(bmi, null)).thenReturn(mp); + when(merged.merge(mp)).thenReturn(merged); + when(merged.normalize(null, true)).thenReturn(merged); + EffectivePolicyImpl epi = new EffectivePolicyImpl(); epi.initialisePolicy(ei, boi, engine, requestor, requestor, null, null); assertSame(merged, epi.getPolicy()); - control.verify(); } @Test public void testInitialiseServerFaultPolicy() { Message m = new MessageImpl(); - EndpointInfo ei = control.createMock(EndpointInfo.class); - BindingFaultInfo bfi = control.createMock(BindingFaultInfo.class); - PolicyEngineImpl engine = control.createMock(PolicyEngineImpl.class); - - BindingOperationInfo boi = control.createMock(BindingOperationInfo.class); - EasyMock.expect(bfi.getBindingOperation()).andReturn(boi).anyTimes(); - EndpointPolicy endpointPolicy = control.createMock(EndpointPolicy.class); - EasyMock.expect(engine.getServerEndpointPolicy(ei, (Destination)null, m)).andReturn(endpointPolicy); - Policy ep = control.createMock(Policy.class); - EasyMock.expect(endpointPolicy.getPolicy()).andReturn(ep); - Policy op = control.createMock(Policy.class); - EasyMock.expect(engine.getAggregatedOperationPolicy(boi, m)).andReturn(op); - Policy merged = control.createMock(Policy.class); - EasyMock.expect(ep.merge(op)).andReturn(merged); - Policy fp = control.createMock(Policy.class); - EasyMock.expect(engine.getAggregatedFaultPolicy(bfi, m)).andReturn(fp); - EasyMock.expect(merged.merge(fp)).andReturn(merged); - EasyMock.expect(merged.normalize(null, true)).andReturn(merged); - - control.replay(); + EndpointInfo ei = mock(EndpointInfo.class); + BindingFaultInfo bfi = mock(BindingFaultInfo.class); + PolicyEngineImpl engine = mock(PolicyEngineImpl.class); + + BindingOperationInfo boi = mock(BindingOperationInfo.class); + when(bfi.getBindingOperation()).thenReturn(boi); + EndpointPolicy endpointPolicy = mock(EndpointPolicy.class); + when(engine.getServerEndpointPolicy(ei, (Destination)null, m)).thenReturn(endpointPolicy); + Policy ep = mock(Policy.class); + when(endpointPolicy.getPolicy()).thenReturn(ep); + Policy op = mock(Policy.class); + when(engine.getAggregatedOperationPolicy(boi, m)).thenReturn(op); + Policy merged = mock(Policy.class); + when(ep.merge(op)).thenReturn(merged); + Policy fp = mock(Policy.class); + when(engine.getAggregatedFaultPolicy(bfi, m)).thenReturn(fp); + when(merged.merge(fp)).thenReturn(merged); + when(merged.normalize(null, true)).thenReturn(merged); + EffectivePolicyImpl epi = new EffectivePolicyImpl(); epi.initialisePolicy(ei, boi, bfi, engine, m); assertSame(merged, epi.getPolicy()); - control.verify(); } @Test @@ -254,30 +205,26 @@ public void testChooseAlternative() { EffectivePolicyImpl epi = new EffectivePolicyImpl(); Policy policy = new Policy(); epi.setPolicy(policy); - PolicyEngineImpl engine = control.createMock(PolicyEngineImpl.class); - Assertor assertor = control.createMock(Assertor.class); - AlternativeSelector selector = control.createMock(AlternativeSelector.class); - EasyMock.expect(engine.getAlternativeSelector()).andReturn(selector); - EasyMock.expect(selector.selectAlternative(policy, engine, assertor, null, m)).andReturn(null); + PolicyEngineImpl engine = mock(PolicyEngineImpl.class); + Assertor assertor = mock(Assertor.class); + AlternativeSelector selector = mock(AlternativeSelector.class); + when(engine.getAlternativeSelector()).thenReturn(selector); + when(selector.selectAlternative(policy, engine, assertor, null, m)).thenReturn(null); - control.replay(); try { epi.chooseAlternative(engine, assertor, m); fail("Expected PolicyException not thrown."); } catch (PolicyException ex) { // expected } - control.verify(); - control.reset(); - EasyMock.expect(engine.getAlternativeSelector()).andReturn(selector); + when(engine.getAlternativeSelector()).thenReturn(selector); Collection alternative = new ArrayList<>(); - EasyMock.expect(selector.selectAlternative(policy, engine, assertor, null, m)).andReturn(alternative); - control.replay(); + when(selector.selectAlternative(policy, engine, assertor, null, m)).thenReturn(alternative); + epi.chooseAlternative(engine, assertor, m); Collection choice = epi.getChosenAlternative(); assertSame(choice, alternative); - control.verify(); } @Test @@ -305,74 +252,67 @@ private void testInitialiseInterceptors(boolean useIn, boolean fault) { List alternative = new ArrayList<>(); epi.setChosenAlternative(alternative); - PolicyEngineImpl engine = control.createMock(PolicyEngineImpl.class); - PolicyInterceptorProviderRegistry reg = control.createMock(PolicyInterceptorProviderRegistry.class); + PolicyEngineImpl engine = mock(PolicyEngineImpl.class); + PolicyInterceptorProviderRegistry reg = mock(PolicyInterceptorProviderRegistry.class); setupPolicyInterceptorProviderRegistry(engine, reg); - control.replay(); epi.initialiseInterceptors(engine, useIn, fault, msg); assertEquals(0, epi.getInterceptors().size()); - control.verify(); - control.reset(); setupPolicyInterceptorProviderRegistry(engine, reg); List> il = new ArrayList<>(); setupRegistryInterceptors(useIn, fault, reg, null, il); - PolicyAssertion a = control.createMock(PolicyAssertion.class); + PolicyAssertion a = mock(PolicyAssertion.class); alternative.add(a); - control.replay(); + epi.initialiseInterceptors(engine, useIn, fault, msg); assertEquals(0, epi.getInterceptors().size()); - control.verify(); - control.reset(); setupPolicyInterceptorProviderRegistry(engine, reg); QName qn = new QName("http://x.y.z", "a"); - EasyMock.expect(a.getName()).andReturn(qn); + when(a.getName()).thenReturn(qn); il = new ArrayList<>(); setupRegistryInterceptors(useIn, fault, reg, qn, il); - control.replay(); + epi.initialiseInterceptors(engine, useIn, fault, msg); assertEquals(0, epi.getInterceptors().size()); - control.verify(); - control.reset(); setupPolicyInterceptorProviderRegistry(engine, reg); - EasyMock.expect(a.getName()).andReturn(qn); - Interceptor pi = control.createMock(Interceptor.class); + when(a.getName()).thenReturn(qn); + @SuppressWarnings("unchecked") + Interceptor pi = mock(Interceptor.class); il = new ArrayList<>(); il.add(pi); setupRegistryInterceptors(useIn, fault, reg, qn, il); - control.replay(); + epi.initialiseInterceptors(engine, useIn, fault, msg); assertEquals(1, epi.getInterceptors().size()); assertSame(pi, epi.getInterceptors().get(0)); - control.verify(); } private void setupRegistryInterceptors(boolean useIn, boolean fault, PolicyInterceptorProviderRegistry reg, QName qn, List> m) { if (useIn && !fault) { - EasyMock.expect(reg.getInInterceptorsForAssertion(qn)) - .andReturn(m); + when(reg.getInInterceptorsForAssertion(qn)) + .thenReturn(m); } else if (!useIn && !fault) { - EasyMock.expect(reg.getOutInterceptorsForAssertion(qn)) - .andReturn(m); + when(reg.getOutInterceptorsForAssertion(qn)) + .thenReturn(m); } else if (useIn && fault) { - EasyMock.expect(reg.getInFaultInterceptorsForAssertion(qn)) - .andReturn(m); + when(reg.getInFaultInterceptorsForAssertion(qn)) + .thenReturn(m); } else if (!useIn && fault) { - EasyMock.expect(reg.getOutFaultInterceptorsForAssertion(qn)) - .andReturn(m); + when(reg.getOutFaultInterceptorsForAssertion(qn)) + .thenReturn(m); } } private void setupPolicyInterceptorProviderRegistry(PolicyEngineImpl engine, PolicyInterceptorProviderRegistry reg) { - Bus bus = control.createMock(Bus.class); - EasyMock.expect(engine.getBus()).andReturn(bus).anyTimes(); - EasyMock.expect(bus.getExtension(PolicyInterceptorProviderRegistry.class)).andReturn(reg); + Bus bus = mock(Bus.class); + when(engine.getBus()).thenReturn(bus); + when(bus.getExtension(PolicyInterceptorProviderRegistry.class)).thenReturn(reg); } } \ No newline at end of file diff --git a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EndpointPolicyImplTest.java b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EndpointPolicyImplTest.java index 8184a9f89c5..57fb08a209d 100644 --- a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EndpointPolicyImplTest.java +++ b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/EndpointPolicyImplTest.java @@ -19,7 +19,6 @@ package org.apache.cxf.ws.policy; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -43,9 +42,6 @@ import org.apache.neethi.Policy; import org.apache.neethi.PolicyOperator; -import org.easymock.EasyMock; -import org.easymock.IMocksControl; -import org.junit.Before; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -53,14 +49,16 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; /** * */ public class EndpointPolicyImplTest { - - private IMocksControl control; - final class TestEndpointPolicy extends EndpointPolicyImpl { @Override protected EndpointPolicyImpl createEndpointPolicy() { @@ -72,13 +70,9 @@ void finalizeConfig(Message m) { } }; - @Before - public void setUp() { - control = EasyMock.createNiceControl(); - } - private List> createMockInterceptorList() { - Interceptor i = control.createMock(Interceptor.class); + @SuppressWarnings("unchecked") + Interceptor i = mock(Interceptor.class); Interceptor m = i; List> a = new ArrayList<>(); a.add(m); @@ -94,11 +88,11 @@ public void testAccessors() { assertNull(epi.getInterceptors(m)); assertNull(epi.getFaultInterceptors(m)); - Policy p = control.createMock(Policy.class); - Assertion a = control.createMock(Assertion.class); + Policy p = mock(Policy.class); + Assertion a = mock(Assertion.class); List la = Collections.singletonList(a); List> li = createMockInterceptorList(); - control.replay(); + epi.setPolicy(p); assertSame(p, epi.getPolicy()); epi.setChosenAlternative(la); @@ -111,93 +105,82 @@ public void testAccessors() { assertSame(la, epi.getVocabulary(m)); epi.setFaultVocabulary(la); assertSame(la, epi.getFaultVocabulary(m)); - control.verify(); } @Test public void testInitialize() throws NoSuchMethodException { Message m = new MessageImpl(); - Method m1 = EndpointPolicyImpl.class.getDeclaredMethod("initializePolicy", new Class[] {Message.class}); - Method m2 = EndpointPolicyImpl.class.getDeclaredMethod("checkExactlyOnes", new Class[] {}); - Method m3 = EndpointPolicyImpl.class.getDeclaredMethod("chooseAlternative", new Class[] {Message.class}); - Method m4 = EndpointPolicyImpl.class.getDeclaredMethod("initializeVocabulary", new Class[] {Message.class}); - Method m5 = EndpointPolicyImpl.class.getDeclaredMethod("initializeInterceptors", new Class[] {Message.class}); - EndpointPolicyImpl epi = EasyMock.createMockBuilder(EndpointPolicyImpl.class) - .addMockedMethods(m1, m2, m3, m4, m5).createMock(control); + + EndpointInfo ei = mock(EndpointInfo.class); + PolicyEngineImpl engine = mock(PolicyEngineImpl.class); + ServiceInfo si = mock(ServiceInfo.class); + when(ei.getService()).thenReturn(si); + when(engine.getAggregatedServicePolicy(si, m)).thenReturn(new Policy()); + when(engine.getAggregatedEndpointPolicy(ei, m)).thenReturn(new Policy()); + + EndpointPolicyImpl epi = spy(new EndpointPolicyImpl(ei, engine, false, null)); epi.initializePolicy(m); - EasyMock.expectLastCall(); epi.checkExactlyOnes(); - EasyMock.expectLastCall(); epi.chooseAlternative(m); - EasyMock.expectLastCall(); - control.replay(); epi.initialize(m); - control.verify(); } @Test public void testInitializePolicy() { - EndpointInfo ei = control.createMock(EndpointInfo.class); - PolicyEngineImpl engine = control.createMock(PolicyEngineImpl.class); - ServiceInfo si = control.createMock(ServiceInfo.class); - EasyMock.expect(ei.getService()).andReturn(si); - Policy sp = control.createMock(Policy.class); - EasyMock.expect(engine.getAggregatedServicePolicy(si, null)).andReturn(sp); - Policy ep = control.createMock(Policy.class); - EasyMock.expect(engine.getAggregatedEndpointPolicy(ei, null)).andReturn(ep); - Policy merged = control.createMock(Policy.class); - EasyMock.expect(sp.merge(ep)).andReturn(merged); - EasyMock.expect(merged.normalize(null, true)).andReturn(merged); - - control.replay(); + EndpointInfo ei = mock(EndpointInfo.class); + PolicyEngineImpl engine = mock(PolicyEngineImpl.class); + ServiceInfo si = mock(ServiceInfo.class); + when(ei.getService()).thenReturn(si); + Policy sp = mock(Policy.class); + when(engine.getAggregatedServicePolicy(si, null)).thenReturn(sp); + Policy ep = mock(Policy.class); + when(engine.getAggregatedEndpointPolicy(ei, null)).thenReturn(ep); + Policy merged = mock(Policy.class); + when(sp.merge(ep)).thenReturn(merged); + when(merged.normalize(null, true)).thenReturn(merged); + EndpointPolicyImpl epi = new EndpointPolicyImpl(ei, engine, true, null); epi.initializePolicy(null); assertSame(merged, epi.getPolicy()); - control.verify(); } @Test public void testChooseAlternative() { Policy policy = new Policy(); - PolicyEngineImpl engine = control.createMock(PolicyEngineImpl.class); - Assertor assertor = control.createMock(Assertor.class); - AlternativeSelector selector = control.createMock(AlternativeSelector.class); + PolicyEngineImpl engine = mock(PolicyEngineImpl.class); + Assertor assertor = mock(Assertor.class); + AlternativeSelector selector = mock(AlternativeSelector.class); Message m = new MessageImpl(); EndpointPolicyImpl epi = new EndpointPolicyImpl(null, engine, true, assertor); epi.setPolicy(policy); - EasyMock.expect(engine.isEnabled()).andReturn(true).anyTimes(); - EasyMock.expect(engine.getAlternativeSelector()).andReturn(selector); - EasyMock.expect(selector.selectAlternative(policy, engine, assertor, null, m)).andReturn(null); + when(engine.isEnabled()).thenReturn(true); + when(engine.getAlternativeSelector()).thenReturn(selector); + when(selector.selectAlternative(policy, engine, assertor, null, m)).thenReturn(null); - control.replay(); try { epi.chooseAlternative(m); fail("Expected PolicyException not thrown."); } catch (PolicyException ex) { // expected } - control.verify(); - control.reset(); - EasyMock.expect(engine.isEnabled()).andReturn(true).anyTimes(); - EasyMock.expect(engine.getAlternativeSelector()).andReturn(selector); + when(engine.isEnabled()).thenReturn(true); + when(engine.getAlternativeSelector()).thenReturn(selector); Collection alternative = new ArrayList<>(); - EasyMock.expect(selector.selectAlternative(policy, engine, assertor, null, m)).andReturn(alternative); - control.replay(); + when(selector.selectAlternative(policy, engine, assertor, null, m)).thenReturn(alternative); + epi.chooseAlternative(m); Collection choice = epi.getChosenAlternative(); assertSame(choice, alternative); - control.verify(); - control.reset(); - EasyMock.expect(engine.isEnabled()).andReturn(false).anyTimes(); - EasyMock.expect(engine.getAlternativeSelector()).andReturn(null).anyTimes(); - control.replay(); + when(engine.isEnabled()).thenReturn(false); + when(engine.getAlternativeSelector()).thenReturn(null); + try { epi.chooseAlternative(m); } catch (Exception ex) { @@ -206,7 +189,6 @@ public void testChooseAlternative() { } choice = epi.getChosenAlternative(); assertTrue("not an empty list", choice != null && choice.isEmpty()); - control.verify(); } private MessageImpl createMessage() { @@ -222,12 +204,13 @@ public void testUpdatePolicy() { Policy p1 = new Policy(); QName aqn1 = new QName("http://x.y.z", "a"); - p1.addAssertion(mockAssertion(aqn1, 5, true)); + PolicyAssertion a1 = mockAssertion(aqn1, true); + p1.addAssertion(a1); Policy p2 = new Policy(); QName aqn2 = new QName("http://x.y.z", "b"); - p2.addAssertion(mockAssertion(aqn2, 5, true)); - control.replay(); + PolicyAssertion a2 = mockAssertion(aqn2, true); + p2.addAssertion(a2); epi.setPolicy(p1.normalize(null, true)); @@ -250,6 +233,13 @@ public void testUpdatePolicy() { QName n2 = assertions2.get(0).getName(); assertTrue("Policy was not merged", n1.equals(aqn1) && n2.equals(aqn2) || n1.equals(aqn2) && n2.equals(aqn1)); + + verify(a1, times(1)).getName(); + verify(a1, times(2)).getType(); + verify(a1, times(1)).normalize(); + verify(a2, times(1)).getName(); + verify(a2, times(2)).getType(); + verify(a2, times(1)).normalize(); } @Test @@ -283,10 +273,10 @@ public void testUpdatePolicyWithEmptyExactlyOneAndAll() { private void doTestUpdateWithEmptyPolicy(Policy emptyPolicy) { Policy p1 = new Policy(); QName aqn1 = new QName("http://x.y.z", "a"); - p1.addAssertion(mockAssertion(aqn1, 5, true)); + PolicyAssertion a = mockAssertion(aqn1, true); + p1.addAssertion(a); EndpointPolicyImpl epi = new TestEndpointPolicy(); - control.replay(); epi.setPolicy(p1.normalize(true)); @@ -303,14 +293,18 @@ private void doTestUpdateWithEmptyPolicy(Policy emptyPolicy) { QName n1 = assertions1.get(0).getName(); assertEquals("Policy was not merged", n1, aqn1); + + verify(a, times(1)).getName(); + verify(a, times(2)).getType(); + verify(a, times(1)).normalize(); } - private PolicyAssertion mockAssertion(QName name, int howMany, boolean normalize) { - PolicyAssertion a = control.createMock(PolicyAssertion.class); - EasyMock.expect(a.getName()).andReturn(name).times(howMany); + private PolicyAssertion mockAssertion(QName name, boolean normalize) { + PolicyAssertion a = mock(PolicyAssertion.class); + when(a.getName()).thenReturn(name); if (normalize) { - EasyMock.expect(a.getType()).andReturn(Constants.TYPE_ASSERTION).times(howMany); - EasyMock.expect(a.normalize()).andReturn(a).times(howMany); + when(a.getType()).thenReturn(Constants.TYPE_ASSERTION); + when(a.normalize()).thenReturn(a); } return a; } @@ -327,31 +321,32 @@ public void testInitialiseInterceptorsClient() { private void doTestInitializeInterceptors(boolean requestor) { - EndpointInfo ei = control.createMock(EndpointInfo.class); - PolicyEngineImpl engine = control.createMock(PolicyEngineImpl.class); + EndpointInfo ei = mock(EndpointInfo.class); + PolicyEngineImpl engine = mock(PolicyEngineImpl.class); EndpointPolicyImpl epi = new EndpointPolicyImpl(ei, engine, requestor, null); Collection v = new ArrayList<>(); Collection fv = new ArrayList<>(); QName aqn = new QName("http://x.y.z", "a"); - v.add(mockAssertion(aqn, requestor ? 2 : 1, false)); - v.add(mockAssertion(aqn, requestor ? 2 : 1, false)); + PolicyAssertion a1 = mockAssertion(aqn, false); + PolicyAssertion a2 = mockAssertion(aqn, false); + v.add(a1); + v.add(a2); fv.addAll(v); epi.setVocabulary(v); epi.setChosenAlternative(v); epi.setFaultVocabulary(fv); - PolicyInterceptorProviderRegistry reg = control.createMock(PolicyInterceptorProviderRegistry.class); + PolicyInterceptorProviderRegistry reg = mock(PolicyInterceptorProviderRegistry.class); setupPolicyInterceptorProviderRegistry(engine, reg); List> li = createMockInterceptorList(); Interceptor api = li.get(0); - EasyMock.expect(reg.getInInterceptorsForAssertion(aqn)).andReturn(li).anyTimes(); + when(reg.getInInterceptorsForAssertion(aqn)).thenReturn(li); if (requestor) { - EasyMock.expect(reg.getInFaultInterceptorsForAssertion(aqn)).andReturn(li).anyTimes(); + when(reg.getInFaultInterceptorsForAssertion(aqn)).thenReturn(li); } - control.replay(); Message m = new MessageImpl(); epi.initializeInterceptors(m); assertEquals(1, epi.getInterceptors(m).size()); @@ -362,14 +357,16 @@ private void doTestInitializeInterceptors(boolean requestor) { } else { assertNull(epi.getFaultInterceptors(m)); } - control.verify(); + + verify(a1, times(requestor ? 2 : 1)).getName(); + verify(a2, times(requestor ? 2 : 1)).getName(); } private void setupPolicyInterceptorProviderRegistry(PolicyEngineImpl engine, PolicyInterceptorProviderRegistry reg) { - Bus bus = control.createMock(Bus.class); - EasyMock.expect(engine.getBus()).andReturn(bus).anyTimes(); - EasyMock.expect(bus.getExtension(PolicyInterceptorProviderRegistry.class)).andReturn(reg).anyTimes(); + Bus bus = mock(Bus.class); + when(engine.getBus()).thenReturn(bus); + when(bus.getExtension(PolicyInterceptorProviderRegistry.class)).thenReturn(reg); } } \ No newline at end of file diff --git a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/NormalizeTest.java b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/NormalizeTest.java index 0a94978dcdf..5fc4c857ee8 100644 --- a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/NormalizeTest.java +++ b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/NormalizeTest.java @@ -29,30 +29,13 @@ import org.apache.neethi.Policy; import org.apache.neethi.util.PolicyComparator; -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.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; public class NormalizeTest { - - private IMocksControl control; - - - @Before - public void setUp() { - control = EasyMock.createNiceControl(); - } - - @After - public void tearDown() { - control.verify(); - } - @Test public void testNormalize() throws Exception { Bus bus = createBus(Constants.URI_POLICY_13_NS); @@ -93,8 +76,7 @@ private PolicyBuilderImpl createBuilder(Bus bus) { } private Bus createBus(String policyNamespace) { - Bus bus = control.createMock(Bus.class); - control.replay(); + Bus bus = mock(Bus.class); return bus; } diff --git a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyDataEngineImplTest.java b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyDataEngineImplTest.java index 19ae064de33..db4e8d46c01 100644 --- a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyDataEngineImplTest.java +++ b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyDataEngineImplTest.java @@ -29,11 +29,11 @@ import org.apache.cxf.policy.PolicyCalculator; import org.apache.cxf.ws.policy.builder.jaxb.JaxbAssertion; -import org.easymock.EasyMock; -import org.easymock.IMocksControl; import org.junit.Test; import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class PolicyDataEngineImplTest { private static final QName TEST_POLICY_NAME = new QName("http://test", "TestPolicy"); @@ -101,13 +101,10 @@ private void checkAssertWithMap(AssertionInfoMap assertionInfoMap) { PolicyDataEngineImpl pde = new PolicyDataEngineImpl(null); pde.setPolicyEngine(new PolicyEngineImpl()); TestPolicy confPol = new TestPolicy(); - IMocksControl control = EasyMock.createControl(); PolicyCalculator policyCalculator = new TestPolicyCalculator(); - Message message = control.createMock(Message.class); - EasyMock.expect(message.get(TestPolicy.class)).andReturn(confPol); - EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(assertionInfoMap); - control.replay(); + Message message = mock(Message.class); + when(message.get(TestPolicy.class)).thenReturn(confPol); + when(message.get(AssertionInfoMap.class)).thenReturn(assertionInfoMap); pde.assertMessage(message, confPol, policyCalculator); - control.verify(); } } \ No newline at end of file diff --git a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyEngineTest.java b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyEngineTest.java index 16b60b3a2f4..a3fe860e736 100644 --- a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyEngineTest.java +++ b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyEngineTest.java @@ -19,7 +19,6 @@ package org.apache.cxf.ws.policy; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -48,13 +47,9 @@ import org.apache.neethi.Assertion; import org.apache.neethi.Constants; import org.apache.neethi.Policy; -import org.apache.neethi.PolicyComponent; import org.apache.neethi.PolicyReference; import org.apache.neethi.PolicyRegistry; -import org.easymock.EasyMock; -import org.easymock.IMocksControl; -import org.junit.Before; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -63,21 +58,21 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; /** * */ public class PolicyEngineTest { - private IMocksControl control; private PolicyEngineImpl engine; private Message msg = new MessageImpl(); - @Before - public void setUp() { - control = EasyMock.createNiceControl(); - } - private EndpointInfo createMockEndpointInfo() throws Exception { EndpointInfo ei = new EndpointInfo(); ei.setName(new QName("mock", "mock")); @@ -105,10 +100,10 @@ public void testAccessors() throws Exception { engine.setBus(bus); List providers = CastUtils.cast(Collections.EMPTY_LIST, PolicyProvider.class); engine.setPolicyProviders(providers); - PolicyRegistry reg = control.createMock(PolicyRegistry.class); + PolicyRegistry reg = mock(PolicyRegistry.class); engine.setRegistry(reg); engine.setEnabled(true); - AlternativeSelector selector = control.createMock(AlternativeSelector.class); + AlternativeSelector selector = mock(AlternativeSelector.class); engine.setAlternativeSelector(selector); assertSame(bus, engine.getBus()); assertSame(reg, engine.getRegistry()); @@ -120,21 +115,17 @@ public void testAccessors() throws Exception { @Test public void testGetEffectiveClientRequestPolicy() throws Exception { - Method m = PolicyEngineImpl.class.getDeclaredMethod("createOutPolicyInfo", new Class[] {}); - engine = EasyMock.createMockBuilder(PolicyEngineImpl.class) - .addMockedMethod(m).createMock(control); + engine = spy(new PolicyEngineImpl()); engine.init(); EndpointInfo ei = createMockEndpointInfo(); BindingOperationInfo boi = createMockBindingOperationInfo(); - AssertingConduit conduit = control.createMock(AssertingConduit.class); - EffectivePolicyImpl epi = control.createMock(EffectivePolicyImpl.class); - EasyMock.expect(engine.createOutPolicyInfo()).andReturn(epi); + AssertingConduit conduit = mock(AssertingConduit.class); + EffectivePolicyImpl epi = mock(EffectivePolicyImpl.class); + when(engine.createOutPolicyInfo()).thenReturn(epi); epi.initialise(ei, boi, engine, conduit, true, true, msg); - EasyMock.expectLastCall(); - control.replay(); + assertSame(epi, engine.getEffectiveClientRequestPolicy(ei, boi, conduit, msg)); assertSame(epi, engine.getEffectiveClientRequestPolicy(ei, boi, conduit, msg)); - control.verify(); } @Test @@ -142,31 +133,26 @@ public void testSetEffectiveClientRequestPolicy() throws Exception { engine = new PolicyEngineImpl(); EndpointInfo ei = createMockEndpointInfo(); BindingOperationInfo boi = createMockBindingOperationInfo(); - EffectivePolicy effectivePolicy = control.createMock(EffectivePolicy.class); - control.replay(); + EffectivePolicy effectivePolicy = mock(EffectivePolicy.class); + engine.setEffectiveClientRequestPolicy(ei, boi, effectivePolicy); assertSame(effectivePolicy, engine.getEffectiveClientRequestPolicy(ei, boi, (Conduit)null, msg)); - control.verify(); } @Test public void testGetEffectiveServerResponsePolicy() throws Exception { - Method m = PolicyEngineImpl.class.getDeclaredMethod("createOutPolicyInfo", new Class[] {}); - engine = EasyMock.createMockBuilder(PolicyEngineImpl.class) - .addMockedMethod(m).createMock(control); + engine = spy(new PolicyEngineImpl()); engine.init(); EndpointInfo ei = createMockEndpointInfo(); BindingOperationInfo boi = createMockBindingOperationInfo(); - AssertingDestination destination = control.createMock(AssertingDestination.class); - EffectivePolicyImpl epi = control.createMock(EffectivePolicyImpl.class); - EasyMock.expect(engine.createOutPolicyInfo()).andReturn(epi); + AssertingDestination destination = mock(AssertingDestination.class); + EffectivePolicyImpl epi = mock(EffectivePolicyImpl.class); + when(engine.createOutPolicyInfo()).thenReturn(epi); epi.initialise(ei, boi, engine, destination, false, false, null); - EasyMock.expectLastCall(); - control.replay(); + assertSame(epi, engine.getEffectiveServerResponsePolicy(ei, boi, destination, null, msg)); assertSame(epi, engine.getEffectiveServerResponsePolicy(ei, boi, destination, null, msg)); - control.verify(); } @Test @@ -174,31 +160,26 @@ public void testSetEffectiveServerResponsePolicy() throws Exception { engine = new PolicyEngineImpl(); EndpointInfo ei = createMockEndpointInfo(); BindingOperationInfo boi = createMockBindingOperationInfo(); - EffectivePolicy effectivePolicy = control.createMock(EffectivePolicy.class); - control.replay(); + EffectivePolicy effectivePolicy = mock(EffectivePolicy.class); + engine.setEffectiveServerResponsePolicy(ei, boi, effectivePolicy); assertSame(effectivePolicy, engine.getEffectiveServerResponsePolicy(ei, boi, (Destination)null, null, msg)); - control.verify(); } @Test public void testGetEffectiveServerFaultPolicy() throws Exception { - Method m = PolicyEngineImpl.class.getDeclaredMethod("createOutPolicyInfo", new Class[] {}); - engine = EasyMock.createMockBuilder(PolicyEngineImpl.class) - .addMockedMethod(m).createMock(control); + engine = spy(new PolicyEngineImpl()); engine.init(); EndpointInfo ei = createMockEndpointInfo(); BindingFaultInfo bfi = new BindingFaultInfo(null, null); - AssertingDestination destination = control.createMock(AssertingDestination.class); - EffectivePolicyImpl epi = control.createMock(EffectivePolicyImpl.class); - EasyMock.expect(engine.createOutPolicyInfo()).andReturn(epi); + AssertingDestination destination = mock(AssertingDestination.class); + EffectivePolicyImpl epi = mock(EffectivePolicyImpl.class); + when(engine.createOutPolicyInfo()).thenReturn(epi); epi.initialise(ei, null, bfi, engine, destination, msg); - EasyMock.expectLastCall(); - control.replay(); + assertSame(epi, engine.getEffectiveServerFaultPolicy(ei, null, bfi, destination, msg)); assertSame(epi, engine.getEffectiveServerFaultPolicy(ei, null, bfi, destination, msg)); - control.verify(); } @Test @@ -206,27 +187,23 @@ public void testSetEffectiveServerFaultPolicy() throws Exception { engine = new PolicyEngineImpl(); EndpointInfo ei = createMockEndpointInfo(); BindingFaultInfo bfi = new BindingFaultInfo(null, null); - EffectivePolicy epi = control.createMock(EffectivePolicy.class); + EffectivePolicy epi = mock(EffectivePolicy.class); engine.setEffectiveServerFaultPolicy(ei, bfi, epi); assertSame(epi, engine.getEffectiveServerFaultPolicy(ei, null, bfi, (Destination)null, msg)); } @Test public void testGetEffectiveServerRequestPolicyInfo() throws Exception { - Method m = PolicyEngineImpl.class.getDeclaredMethod("createOutPolicyInfo", new Class[] {}); - engine = EasyMock.createMockBuilder(PolicyEngineImpl.class) - .addMockedMethod(m).createMock(control); + engine = spy(new PolicyEngineImpl()); engine.init(); EndpointInfo ei = createMockEndpointInfo(); BindingOperationInfo boi = createMockBindingOperationInfo(); - EffectivePolicyImpl epi = control.createMock(EffectivePolicyImpl.class); - EasyMock.expect(engine.createOutPolicyInfo()).andReturn(epi); + EffectivePolicyImpl epi = mock(EffectivePolicyImpl.class); + when(engine.createOutPolicyInfo()).thenReturn(epi); epi.initialise(ei, boi, engine, false, true, msg); - EasyMock.expectLastCall(); - control.replay(); + assertSame(epi, engine.getEffectiveServerRequestPolicy(ei, boi, msg)); assertSame(epi, engine.getEffectiveServerRequestPolicy(ei, boi, msg)); - control.verify(); } @Test @@ -234,29 +211,23 @@ public void testSetEffectiveServerRequestPolicy() throws Exception { engine = new PolicyEngineImpl(); EndpointInfo ei = createMockEndpointInfo(); BindingOperationInfo boi = createMockBindingOperationInfo(); - EffectivePolicy effectivePolicy = control.createMock(EffectivePolicy.class); - control.replay(); + EffectivePolicy effectivePolicy = mock(EffectivePolicy.class); engine.setEffectiveServerRequestPolicy(ei, boi, effectivePolicy); assertSame(effectivePolicy, engine.getEffectiveServerRequestPolicy(ei, boi, msg)); - control.verify(); } @Test public void testGetEffectiveClientResponsePolicy() throws Exception { - Method m = PolicyEngineImpl.class.getDeclaredMethod("createOutPolicyInfo", new Class[] {}); - engine = EasyMock.createMockBuilder(PolicyEngineImpl.class) - .addMockedMethod(m).createMock(control); + engine = spy(new PolicyEngineImpl()); engine.init(); EndpointInfo ei = createMockEndpointInfo(); BindingOperationInfo boi = createMockBindingOperationInfo(); - EffectivePolicyImpl epi = control.createMock(EffectivePolicyImpl.class); - EasyMock.expect(engine.createOutPolicyInfo()).andReturn(epi); + EffectivePolicyImpl epi = mock(EffectivePolicyImpl.class); + when(engine.createOutPolicyInfo()).thenReturn(epi); epi.initialise(ei, boi, engine, true, false, msg); - EasyMock.expectLastCall(); - control.replay(); + assertSame(epi, engine.getEffectiveClientResponsePolicy(ei, boi, msg)); assertSame(epi, engine.getEffectiveClientResponsePolicy(ei, boi, msg)); - control.verify(); } @Test @@ -264,29 +235,24 @@ public void testSetEffectiveClientResponsePolicy() throws Exception { engine = new PolicyEngineImpl(); EndpointInfo ei = createMockEndpointInfo(); BindingOperationInfo boi = createMockBindingOperationInfo(); - EffectivePolicy epi = control.createMock(EffectivePolicy.class); - control.replay(); + EffectivePolicy epi = mock(EffectivePolicy.class); + engine.setEffectiveClientResponsePolicy(ei, boi, epi); assertSame(epi, engine.getEffectiveClientResponsePolicy(ei, boi, msg)); - control.verify(); } @Test public void testGetEffectiveClientFaultPolicy() throws Exception { - Method m = PolicyEngineImpl.class.getDeclaredMethod("createOutPolicyInfo", new Class[] {}); - engine = EasyMock.createMockBuilder(PolicyEngineImpl.class) - .addMockedMethod(m).createMock(control); + engine = spy(new PolicyEngineImpl()); engine.init(); EndpointInfo ei = createMockEndpointInfo(); BindingFaultInfo bfi = new BindingFaultInfo(null, null); - EffectivePolicyImpl epi = control.createMock(EffectivePolicyImpl.class); - EasyMock.expect(engine.createOutPolicyInfo()).andReturn(epi); + EffectivePolicyImpl epi = mock(EffectivePolicyImpl.class); + when(engine.createOutPolicyInfo()).thenReturn(epi); epi.initialisePolicy(ei, null, bfi, engine, msg); - EasyMock.expectLastCall(); - control.replay(); + assertSame(epi, engine.getEffectiveClientFaultPolicy(ei, null, bfi, msg)); assertSame(epi, engine.getEffectiveClientFaultPolicy(ei, null, bfi, msg)); - control.verify(); } @Test @@ -294,84 +260,56 @@ public void testSetEffectiveClientFaultPolicy() throws Exception { engine = new PolicyEngineImpl(); EndpointInfo ei = createMockEndpointInfo(); BindingFaultInfo bfi = new BindingFaultInfo(null, null); - EffectivePolicy epi = control.createMock(EffectivePolicy.class); + EffectivePolicy epi = mock(EffectivePolicy.class); engine.setEffectiveClientFaultPolicy(ei, bfi, epi); assertSame(epi, engine.getEffectiveClientFaultPolicy(ei, null, bfi, msg)); } @Test public void testGetEndpointPolicyClientSide() throws Exception { - Method m = PolicyEngineImpl.class.getDeclaredMethod("createEndpointPolicyInfo", - new Class[] {EndpointInfo.class, boolean.class, Assertor.class, Message.class}); - engine = EasyMock.createMockBuilder(PolicyEngineImpl.class) - .addMockedMethod(m).createMock(control); + engine = spy(new PolicyEngineImpl(mock(Bus.class))); engine.init(); EndpointInfo ei = createMockEndpointInfo(); - AssertingConduit conduit = control.createMock(AssertingConduit.class); - EndpointPolicyImpl epi = control.createMock(EndpointPolicyImpl.class); - EasyMock.expect(engine.createEndpointPolicyInfo(ei, true, conduit, msg)).andReturn(epi); - control.replay(); + AssertingConduit conduit = mock(AssertingConduit.class); + EndpointPolicyImpl epi = mock(EndpointPolicyImpl.class); + when(engine.createEndpointPolicyInfo(ei, true, conduit, msg)).thenReturn(epi); assertSame(epi, engine.getClientEndpointPolicy(ei, conduit, msg)); - control.verify(); } @Test public void testGetEndpointPolicyServerSide() throws Exception { - Method m = PolicyEngineImpl.class.getDeclaredMethod("createEndpointPolicyInfo", - new Class[] {EndpointInfo.class, boolean.class, Assertor.class, Message.class}); - engine = EasyMock.createMockBuilder(PolicyEngineImpl.class) - .addMockedMethod(m).createMock(control); + engine = spy(new PolicyEngineImpl(mock(Bus.class))); engine.init(); EndpointInfo ei = createMockEndpointInfo(); - AssertingDestination destination = control.createMock(AssertingDestination.class); - EndpointPolicyImpl epi = control.createMock(EndpointPolicyImpl.class); - EasyMock.expect(engine.createEndpointPolicyInfo(ei, false, destination, msg)).andReturn(epi); - control.replay(); + AssertingDestination destination = mock(AssertingDestination.class); + EndpointPolicyImpl epi = mock(EndpointPolicyImpl.class); + when(engine.createEndpointPolicyInfo(ei, false, destination, msg)).thenReturn(epi); assertSame(epi, engine.getServerEndpointPolicy(ei, destination, msg)); - control.verify(); } @Test public void testCreateEndpointPolicyInfo() throws Exception { - Method m1 = PolicyEngineImpl.class.getDeclaredMethod("createEndpointPolicyInfo", - new Class[] {EndpointInfo.class, boolean.class, Assertor.class, Message.class}); - engine = EasyMock.createMockBuilder(PolicyEngineImpl.class) - .addMockedMethod(m1).createMock(control); + engine = spy(new PolicyEngineImpl(mock(Bus.class))); engine.init(); EndpointInfo ei = createMockEndpointInfo(); - Assertor assertor = control.createMock(Assertor.class); - EndpointPolicyImpl epi = control.createMock(EndpointPolicyImpl.class); - EasyMock.expect(engine.createEndpointPolicyInfo(ei, false, assertor, msg)).andReturn(epi); - control.replay(); + Assertor assertor = mock(Assertor.class); + EndpointPolicyImpl epi = mock(EndpointPolicyImpl.class); + when(engine.createEndpointPolicyInfo(ei, false, assertor, msg)).thenReturn(epi); assertSame(epi, engine.createEndpointPolicyInfo(ei, false, assertor, msg)); - control.verify(); } @Test public void testEndpointPolicyWithEqualPolicies() throws Exception { engine = new PolicyEngineImpl(); EndpointInfo ei = createMockEndpointInfo(); - ServiceInfo si = control.createMock(ServiceInfo.class); + ServiceInfo si = mock(ServiceInfo.class); ei.setService(si); - si.getExtensor(Policy.class); - EasyMock.expectLastCall().andReturn(null).times(2); - EndpointPolicyImpl epi = control.createMock(EndpointPolicyImpl.class); - control.replay(); + EndpointPolicyImpl epi = mock(EndpointPolicyImpl.class); engine.setServerEndpointPolicy(ei, epi); engine.setClientEndpointPolicy(ei, epi); assertSame(epi, engine.getClientEndpointPolicy(ei, (Conduit)null, msg)); assertSame(epi, engine.getServerEndpointPolicy(ei, (Destination)null, msg)); - - control.reset(); - ei.setService(si); - Policy p = new Policy(); - si.getExtensor(Policy.class); - EasyMock.expectLastCall().andReturn(p).times(2); - epi.getPolicy(); - EasyMock.expectLastCall().andReturn(p).times(2); - control.replay(); - assertSame(epi, engine.getServerEndpointPolicy(ei, (Destination)null, msg)); } @@ -388,17 +326,16 @@ public void testAddBusInterceptors() { private void doTestAddBusInterceptors(boolean enabled) { engine = new PolicyEngineImpl(enabled); - Bus bus = control.createMock(Bus.class); + Bus bus = mock(Bus.class); List> out = new ArrayList<>(); List> in = new ArrayList<>(); List> inFault = new ArrayList<>(); List> outFault = new ArrayList<>(); if (enabled) { - EasyMock.expect(bus.getOutInterceptors()).andReturn(out).times(1); - EasyMock.expect(bus.getInInterceptors()).andReturn(in).times(1); - EasyMock.expect(bus.getInFaultInterceptors()).andReturn(inFault).times(2); - EasyMock.expect(bus.getOutFaultInterceptors()).andReturn(outFault); - control.replay(); + when(bus.getOutInterceptors()).thenReturn(out); + when(bus.getInInterceptors()).thenReturn(in); + when(bus.getInFaultInterceptors()).thenReturn(inFault); + when(bus.getOutFaultInterceptors()).thenReturn(outFault); } engine.setBus(bus); @@ -423,7 +360,6 @@ private void doTestAddBusInterceptors(boolean enabled) { assertEquals(0, outFault.size()); } if (enabled) { - control.verify(); assertNotNull(engine.getAlternativeSelector()); } } @@ -431,35 +367,27 @@ private void doTestAddBusInterceptors(boolean enabled) { @Test public void testGetAggregatedServicePolicy() { engine = new PolicyEngineImpl(); - ServiceInfo si = control.createMock(ServiceInfo.class); + ServiceInfo si = mock(ServiceInfo.class); - control.replay(); Policy p = engine.getAggregatedServicePolicy(si, null); assertTrue(p.isEmpty()); - control.verify(); - control.reset(); - PolicyProvider provider1 = control.createMock(PolicyProvider.class); + PolicyProvider provider1 = mock(PolicyProvider.class); engine.getPolicyProviders().add(provider1); - Policy p1 = control.createMock(Policy.class); - EasyMock.expect(provider1.getEffectivePolicy(si, null)).andReturn(p1); + Policy p1 = mock(Policy.class); + when(provider1.getEffectivePolicy(si, null)).thenReturn(p1); - control.replay(); assertSame(p1, engine.getAggregatedServicePolicy(si, null)); - control.verify(); - control.reset(); - PolicyProvider provider2 = control.createMock(PolicyProvider.class); + PolicyProvider provider2 = mock(PolicyProvider.class); engine.getPolicyProviders().add(provider2); - Policy p2 = control.createMock(Policy.class); - Policy p3 = control.createMock(Policy.class); - EasyMock.expect(provider1.getEffectivePolicy(si, null)).andReturn(p1); - EasyMock.expect(provider2.getEffectivePolicy(si, null)).andReturn(p2); - EasyMock.expect(p1.merge(p2)).andReturn(p3); + Policy p2 = mock(Policy.class); + Policy p3 = mock(Policy.class); + when(provider1.getEffectivePolicy(si, null)).thenReturn(p1); + when(provider2.getEffectivePolicy(si, null)).thenReturn(p2); + when(p1.merge(p2)).thenReturn(p3); - control.replay(); assertSame(p3, engine.getAggregatedServicePolicy(si, null)); - control.verify(); } @Test @@ -467,33 +395,25 @@ public void testGetAggregatedEndpointPolicy() throws Exception { engine = new PolicyEngineImpl(); EndpointInfo ei = createMockEndpointInfo(); - control.replay(); Policy p = engine.getAggregatedEndpointPolicy(ei, null); assertTrue(p.isEmpty()); - control.verify(); - control.reset(); - PolicyProvider provider1 = control.createMock(PolicyProvider.class); + PolicyProvider provider1 = mock(PolicyProvider.class); engine.getPolicyProviders().add(provider1); - Policy p1 = control.createMock(Policy.class); - EasyMock.expect(provider1.getEffectivePolicy(ei, null)).andReturn(p1); + Policy p1 = mock(Policy.class); + when(provider1.getEffectivePolicy(ei, null)).thenReturn(p1); - control.replay(); assertSame(p1, engine.getAggregatedEndpointPolicy(ei, null)); - control.verify(); - control.reset(); - PolicyProvider provider2 = control.createMock(PolicyProvider.class); + PolicyProvider provider2 = mock(PolicyProvider.class); engine.getPolicyProviders().add(provider2); - Policy p2 = control.createMock(Policy.class); - Policy p3 = control.createMock(Policy.class); - EasyMock.expect(provider1.getEffectivePolicy(ei, null)).andReturn(p1); - EasyMock.expect(provider2.getEffectivePolicy(ei, null)).andReturn(p2); - EasyMock.expect(p1.merge(p2)).andReturn(p3); + Policy p2 = mock(Policy.class); + Policy p3 = mock(Policy.class); + when(provider1.getEffectivePolicy(ei, null)).thenReturn(p1); + when(provider2.getEffectivePolicy(ei, null)).thenReturn(p2); + when(p1.merge(p2)).thenReturn(p3); - control.replay(); assertSame(p3, engine.getAggregatedEndpointPolicy(ei, null)); - control.verify(); } @Test @@ -501,137 +421,101 @@ public void testGetAggregatedOperationPolicy() throws Exception { engine = new PolicyEngineImpl(); BindingOperationInfo boi = createMockBindingOperationInfo(); - control.replay(); Policy p = engine.getAggregatedOperationPolicy(boi, null); assertTrue(p.isEmpty()); - control.verify(); - control.reset(); - PolicyProvider provider1 = control.createMock(PolicyProvider.class); + PolicyProvider provider1 = mock(PolicyProvider.class); engine.getPolicyProviders().add(provider1); - Policy p1 = control.createMock(Policy.class); - EasyMock.expect(provider1.getEffectivePolicy(boi, null)).andReturn(p1); + Policy p1 = mock(Policy.class); + when(provider1.getEffectivePolicy(boi, null)).thenReturn(p1); - control.replay(); assertSame(p1, engine.getAggregatedOperationPolicy(boi, null)); - control.verify(); - control.reset(); - PolicyProvider provider2 = control.createMock(PolicyProvider.class); + PolicyProvider provider2 = mock(PolicyProvider.class); engine.getPolicyProviders().add(provider2); - Policy p2 = control.createMock(Policy.class); - Policy p3 = control.createMock(Policy.class); - EasyMock.expect(provider1.getEffectivePolicy(boi, null)).andReturn(p1); - EasyMock.expect(provider2.getEffectivePolicy(boi, null)).andReturn(p2); - EasyMock.expect(p1.merge(p2)).andReturn(p3); + Policy p2 = mock(Policy.class); + Policy p3 = mock(Policy.class); + when(provider1.getEffectivePolicy(boi, null)).thenReturn(p1); + when(provider2.getEffectivePolicy(boi, null)).thenReturn(p2); + when(p1.merge(p2)).thenReturn(p3); - control.replay(); assertSame(p3, engine.getAggregatedOperationPolicy(boi, null)); - control.verify(); } @Test public void testGetAggregatedMessagePolicy() { engine = new PolicyEngineImpl(); - BindingMessageInfo bmi = control.createMock(BindingMessageInfo.class); + BindingMessageInfo bmi = mock(BindingMessageInfo.class); - control.replay(); Policy p = engine.getAggregatedMessagePolicy(bmi, null); assertTrue(p.isEmpty()); - control.verify(); - control.reset(); - PolicyProvider provider1 = control.createMock(PolicyProvider.class); + PolicyProvider provider1 = mock(PolicyProvider.class); engine.getPolicyProviders().add(provider1); - Policy p1 = control.createMock(Policy.class); - EasyMock.expect(provider1.getEffectivePolicy(bmi, null)).andReturn(p1); + Policy p1 = mock(Policy.class); + when(provider1.getEffectivePolicy(bmi, null)).thenReturn(p1); - control.replay(); assertSame(p1, engine.getAggregatedMessagePolicy(bmi, null)); - control.verify(); - control.reset(); - PolicyProvider provider2 = control.createMock(PolicyProvider.class); + PolicyProvider provider2 = mock(PolicyProvider.class); engine.getPolicyProviders().add(provider2); - Policy p2 = control.createMock(Policy.class); - Policy p3 = control.createMock(Policy.class); - EasyMock.expect(provider1.getEffectivePolicy(bmi, null)).andReturn(p1); - EasyMock.expect(provider2.getEffectivePolicy(bmi, null)).andReturn(p2); - EasyMock.expect(p1.merge(p2)).andReturn(p3); + Policy p2 = mock(Policy.class); + Policy p3 = mock(Policy.class); + when(provider1.getEffectivePolicy(bmi, null)).thenReturn(p1); + when(provider2.getEffectivePolicy(bmi, null)).thenReturn(p2); + when(p1.merge(p2)).thenReturn(p3); - control.replay(); assertSame(p3, engine.getAggregatedMessagePolicy(bmi, null)); - control.verify(); } @Test public void testGetAggregatedFaultPolicy() { engine = new PolicyEngineImpl(); - BindingFaultInfo bfi = control.createMock(BindingFaultInfo.class); + BindingFaultInfo bfi = mock(BindingFaultInfo.class); - control.replay(); Policy p = engine.getAggregatedFaultPolicy(bfi, null); assertTrue(p.isEmpty()); - control.verify(); - control.reset(); - PolicyProvider provider1 = control.createMock(PolicyProvider.class); + PolicyProvider provider1 = mock(PolicyProvider.class); engine.getPolicyProviders().add(provider1); - Policy p1 = control.createMock(Policy.class); - EasyMock.expect(provider1.getEffectivePolicy(bfi, null)).andReturn(p1); + Policy p1 = mock(Policy.class); + when(provider1.getEffectivePolicy(bfi, null)).thenReturn(p1); - control.replay(); assertSame(p1, engine.getAggregatedFaultPolicy(bfi, null)); - control.verify(); - control.reset(); - PolicyProvider provider2 = control.createMock(PolicyProvider.class); + PolicyProvider provider2 = mock(PolicyProvider.class); engine.getPolicyProviders().add(provider2); - Policy p2 = control.createMock(Policy.class); - Policy p3 = control.createMock(Policy.class); - EasyMock.expect(provider1.getEffectivePolicy(bfi, null)).andReturn(p1); - EasyMock.expect(provider2.getEffectivePolicy(bfi, null)).andReturn(p2); - EasyMock.expect(p1.merge(p2)).andReturn(p3); + Policy p2 = mock(Policy.class); + Policy p3 = mock(Policy.class); + when(provider1.getEffectivePolicy(bfi, null)).thenReturn(p1); + when(provider2.getEffectivePolicy(bfi, null)).thenReturn(p2); + when(p1.merge(p2)).thenReturn(p3); - control.replay(); assertSame(p3, engine.getAggregatedFaultPolicy(bfi, null)); - control.verify(); } @Test public void testGetAssertions() throws NoSuchMethodException { - Method m = PolicyEngineImpl.class.getDeclaredMethod("addAssertions", - new Class[] {PolicyComponent.class, boolean.class, Collection.class}); - engine = EasyMock.createMockBuilder(PolicyEngineImpl.class) - .addMockedMethod(m).createMock(control); - PolicyAssertion a = control.createMock(PolicyAssertion.class); - EasyMock.expect(a.getType()).andReturn(Constants.TYPE_ASSERTION); - EasyMock.expect(a.isOptional()).andReturn(true); - - control.replay(); + engine = spy(new PolicyEngineImpl()); + PolicyAssertion a = mock(PolicyAssertion.class); + when(a.getType()).thenReturn(Constants.TYPE_ASSERTION); + when(a.isOptional()).thenReturn(true); + assertTrue(engine.getAssertions(a, false).isEmpty()); - control.verify(); - control.reset(); - EasyMock.expect(a.getType()).andReturn(Constants.TYPE_ASSERTION); - // EasyMock.expect(a.isOptional()).andReturn(false); + when(a.getType()).thenReturn(Constants.TYPE_ASSERTION); + // when(a.isOptional()).thenReturn(false); - control.replay(); Collection ca = engine.getAssertions(a, true); assertEquals(1, ca.size()); assertSame(a, ca.iterator().next()); - control.verify(); - control.reset(); - Policy p = control.createMock(Policy.class); - EasyMock.expect(p.getType()).andReturn(Constants.TYPE_POLICY); - engine.addAssertions(EasyMock.eq(p), EasyMock.eq(false), - CastUtils.cast(EasyMock.isA(Collection.class), Assertion.class)); - EasyMock.expectLastCall(); + Policy p = mock(Policy.class); + when(p.getType()).thenReturn(Constants.TYPE_POLICY); - control.replay(); assertTrue(engine.getAssertions(p, false).isEmpty()); - control.verify(); + verify(engine).addAssertions(eq(p), eq(false), + CastUtils.cast(isA(Collection.class), Assertion.class)); } @Test @@ -639,22 +523,17 @@ public void testAddAssertions() { engine = new PolicyEngineImpl(); Collection assertions = new ArrayList<>(); - Assertion a = control.createMock(Assertion.class); - EasyMock.expect(a.getType()).andReturn(Constants.TYPE_ASSERTION); - EasyMock.expect(a.isOptional()).andReturn(true); + Assertion a = mock(Assertion.class); + when(a.getType()).thenReturn(Constants.TYPE_ASSERTION); + when(a.isOptional()).thenReturn(true); - control.replay(); engine.addAssertions(a, false, assertions); assertTrue(assertions.isEmpty()); - control.verify(); - control.reset(); - EasyMock.expect(a.getType()).andReturn(Constants.TYPE_ASSERTION); - control.replay(); + when(a.getType()).thenReturn(Constants.TYPE_ASSERTION); engine.addAssertions(a, true, assertions); assertEquals(1, assertions.size()); assertSame(a, assertions.iterator().next()); - control.verify(); assertions.clear(); Policy p = new Policy(); diff --git a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyInterceptorProviderRegistryImplTest.java b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyInterceptorProviderRegistryImplTest.java index 786378c097d..3baca6ed2a3 100644 --- a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyInterceptorProviderRegistryImplTest.java +++ b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyInterceptorProviderRegistryImplTest.java @@ -28,14 +28,13 @@ import org.apache.cxf.interceptor.Interceptor; 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.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; /** * @@ -44,13 +43,7 @@ public class PolicyInterceptorProviderRegistryImplTest { private static final QName ASSERTION = new QName("testns", "test"); private static final QName WRONG_ASSERTION = new QName("testns", "wrong"); - private IMocksControl control; - @Before - public void setUp() { - control = EasyMock.createNiceControl(); - Integer.valueOf(4); - } @Test public void testConstructors() { @@ -59,15 +52,16 @@ public void testConstructors() { assertEquals(PolicyInterceptorProviderRegistry.class, reg.getRegistrationType()); } + @SuppressWarnings("unchecked") @Test public void testRegister() { PolicyInterceptorProviderRegistryImpl reg = new PolicyInterceptorProviderRegistryImpl(); - PolicyInterceptorProvider pp = control.createMock(PolicyInterceptorProvider.class); - Interceptor pi1 = control.createMock(Interceptor.class); - Interceptor pi2 = control.createMock(Interceptor.class); - Interceptor pif = control.createMock(Interceptor.class); - Interceptor po = control.createMock(Interceptor.class); - Interceptor pof = control.createMock(Interceptor.class); + PolicyInterceptorProvider pp = mock(PolicyInterceptorProvider.class); + Interceptor pi1 = mock(Interceptor.class); + Interceptor pi2 = mock(Interceptor.class); + Interceptor pif = mock(Interceptor.class); + Interceptor po = mock(Interceptor.class); + Interceptor pof = mock(Interceptor.class); List> pil = new ArrayList<>(); pil.add(pi1); pil.add(pi2); @@ -77,21 +71,20 @@ public void testRegister() { pol.add(po); List> pofl = new ArrayList<>(); pofl.add(pof); - EasyMock.expect(pp.getInInterceptors()).andReturn(pil); - EasyMock.expect(pp.getInFaultInterceptors()).andReturn(pifl); - EasyMock.expect(pp.getOutInterceptors()).andReturn(pol); - EasyMock.expect(pp.getOutFaultInterceptors()).andReturn(pofl); + when(pp.getInInterceptors()).thenReturn(pil); + when(pp.getInFaultInterceptors()).thenReturn(pifl); + when(pp.getOutInterceptors()).thenReturn(pol); + when(pp.getOutFaultInterceptors()).thenReturn(pofl); Collection assertionTypes = new ArrayList<>(); assertionTypes.add(ASSERTION); - EasyMock.expect(pp.getAssertionTypes()).andReturn(assertionTypes); - control.replay(); + when(pp.getAssertionTypes()).thenReturn(assertionTypes); + reg.register(pp); assertEquals(pil, reg.getInInterceptorsForAssertion(ASSERTION)); assertEquals(pifl, reg.getInFaultInterceptorsForAssertion(ASSERTION)); assertEquals(pol, reg.getOutInterceptorsForAssertion(ASSERTION)); assertEquals(pofl, reg.getOutFaultInterceptorsForAssertion(ASSERTION)); assertTrue(reg.getInInterceptorsForAssertion(WRONG_ASSERTION).isEmpty()); - control.verify(); } @Test diff --git a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyInterceptorsTest.java b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyInterceptorsTest.java index d70b515e0a6..2e7e61a8678 100644 --- a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyInterceptorsTest.java +++ b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyInterceptorsTest.java @@ -19,7 +19,6 @@ package org.apache.cxf.ws.policy; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -43,12 +42,17 @@ import org.apache.neethi.Assertion; import org.apache.neethi.Policy; -import org.easymock.EasyMock; -import org.easymock.IMocksControl; import org.junit.Before; import org.junit.Test; import static org.junit.Assert.assertSame; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; /** * @@ -56,7 +60,6 @@ public class PolicyInterceptorsTest { private static final QName ASSERTION_QNAME = new QName("http://apache.cxf", "test"); - private IMocksControl control; private Message message; private Exchange exchange; private BindingOperationInfo boi; @@ -69,12 +72,12 @@ public class PolicyInterceptorsTest { @Before public void setUp() { - control = EasyMock.createNiceControl(); - bus = control.createMock(Bus.class); + bus = mock(Bus.class); } private List> createMockInterceptorList() { - Interceptor i = control.createMock(Interceptor.class); + @SuppressWarnings("unchecked") + Interceptor i = mock(Interceptor.class); Interceptor m = i; List> a = new ArrayList<>(); a.add(m); @@ -87,24 +90,21 @@ public void testClientPolicyOutInterceptor() { doTestBasics(interceptor, true, true); - control.reset(); setupMessage(true, true, true, true, true, true); - EffectivePolicy effectivePolicy = control.createMock(EffectivePolicy.class); - EasyMock.expect(pe.getEffectiveClientRequestPolicy(ei, boi, conduit, message)) - .andReturn(effectivePolicy); + EffectivePolicy effectivePolicy = mock(EffectivePolicy.class); + when(pe.getEffectiveClientRequestPolicy(ei, boi, conduit, message)) + .thenReturn(effectivePolicy); List> li = createMockInterceptorList(); - EasyMock.expect(effectivePolicy.getInterceptors()) - .andReturn(li); - InterceptorChain ic = control.createMock(InterceptorChain.class); - EasyMock.expect(message.getInterceptorChain()).andReturn(ic); + when(effectivePolicy.getInterceptors()) + .thenReturn(li); + InterceptorChain ic = mock(InterceptorChain.class); + when(message.getInterceptorChain()).thenReturn(ic); ic.add(li.get(0)); - EasyMock.expectLastCall(); + Collection assertions = CastUtils.cast(Collections.EMPTY_LIST, Assertion.class); - EasyMock.expect(effectivePolicy.getChosenAlternative()).andReturn(assertions); - control.replay(); + when(effectivePolicy.getChosenAlternative()).thenReturn(assertions); interceptor.handleMessage(message); - control.verify(); } @Test @@ -113,25 +113,26 @@ public void testClientPolicyInInterceptor() { doTestBasics(interceptor, true, false); - control.reset(); setupMessage(true, true, true, true, true, true); - EffectivePolicy effectivePolicy = control.createMock(EffectivePolicy.class); - EasyMock.expect(pe.getEffectiveClientResponsePolicy(ei, boi, message)).andReturn(effectivePolicy); - EasyMock.expect(effectivePolicy.getPolicy()).andReturn(new Policy()).times(2); - Interceptor i = control.createMock(Interceptor.class); + EffectivePolicy effectivePolicy = mock(EffectivePolicy.class); + when(pe.getEffectiveClientResponsePolicy(ei, boi, message)).thenReturn(effectivePolicy); + when(effectivePolicy.getPolicy()).thenReturn(new Policy()); + + @SuppressWarnings("unchecked") + Interceptor i = mock(Interceptor.class); List> lst = new ArrayList<>(); lst.add(i); - EasyMock.expect(effectivePolicy.getInterceptors()).andReturn(lst); - InterceptorChain ic = control.createMock(InterceptorChain.class); - EasyMock.expect(message.getInterceptorChain()).andReturn(ic).anyTimes(); + when(effectivePolicy.getInterceptors()).thenReturn(lst); + + InterceptorChain ic = mock(InterceptorChain.class); + when(message.getInterceptorChain()).thenReturn(ic); ic.add(i); - EasyMock.expectLastCall(); - message.put(EasyMock.eq(AssertionInfoMap.class), EasyMock.isA(AssertionInfoMap.class)); - EasyMock.expectLastCall(); + ic.add(PolicyVerificationInInterceptor.INSTANCE); - control.replay(); interceptor.handleMessage(message); - control.verify(); + + verify(effectivePolicy, times(2)).getPolicy(); + verify(message, times(1)).put(eq(AssertionInfoMap.class), isA(AssertionInfoMap.class)); } @Test @@ -140,23 +141,20 @@ public void testClientPolicyInFaultInterceptor() { doTestBasics(interceptor, true, false); - control.reset(); setupMessage(true, true, false, false, true, true); - EndpointPolicy endpointPolicy = control.createMock(EndpointPolicy.class); - EasyMock.expect(pe.getClientEndpointPolicy(ei, conduit, message)).andReturn(endpointPolicy); + EndpointPolicy endpointPolicy = mock(EndpointPolicy.class); + when(pe.getClientEndpointPolicy(ei, conduit, message)).thenReturn(endpointPolicy); List> li = createMockInterceptorList(); - EasyMock.expect(endpointPolicy.getFaultInterceptors(message)) - .andReturn(li); - InterceptorChain ic = control.createMock(InterceptorChain.class); - EasyMock.expect(message.getInterceptorChain()).andReturn(ic); + when(endpointPolicy.getFaultInterceptors(message)) + .thenReturn(li); + InterceptorChain ic = mock(InterceptorChain.class); + when(message.getInterceptorChain()).thenReturn(ic); ic.add(li.get(0)); - EasyMock.expectLastCall(); + Collection assertions = CastUtils.cast(Collections.EMPTY_LIST, Assertion.class); - EasyMock.expect(endpointPolicy.getFaultVocabulary(message)).andReturn(assertions); - control.replay(); + when(endpointPolicy.getFaultVocabulary(message)).thenReturn(assertions); interceptor.handleMessage(message); - control.verify(); } @Test @@ -165,23 +163,21 @@ public void testServerPolicyInInterceptor() { doTestBasics(interceptor, false, false); - control.reset(); setupMessage(false, false, false, false, true, true); - EndpointPolicy endpointPolicy = control.createMock(EndpointPolicyImpl.class); - EasyMock.expect(pe.getServerEndpointPolicy(ei, destination, message)).andReturn(endpointPolicy); + EndpointPolicy endpointPolicy = mock(EndpointPolicyImpl.class); + when(pe.getServerEndpointPolicy(ei, destination, message)).thenReturn(endpointPolicy); List> li = createMockInterceptorList(); - EasyMock.expect(endpointPolicy.getInterceptors(message)) - .andReturn(li); - InterceptorChain ic = control.createMock(InterceptorChain.class); - EasyMock.expect(message.getInterceptorChain()).andReturn(ic); + when(endpointPolicy.getInterceptors(message)) + .thenReturn(li); + InterceptorChain ic = mock(InterceptorChain.class); + when(message.getInterceptorChain()).thenReturn(ic); ic.add(li.get(0)); - EasyMock.expectLastCall(); + Collection assertions = CastUtils.cast(Collections.EMPTY_LIST, Assertion.class); - EasyMock.expect(endpointPolicy.getVocabulary(message)).andReturn(assertions); - control.replay(); + when(endpointPolicy.getVocabulary(message)).thenReturn(assertions); + interceptor.handleMessage(message); - control.verify(); } @Test @@ -190,94 +186,79 @@ public void testServerPolicyOutInterceptor() { doTestBasics(interceptor, false, true); - control.reset(); setupMessage(false, false, true, true, true, true); - EffectivePolicy effectivePolicy = control.createMock(EffectivePolicy.class); - EasyMock.expect(pe.getEffectiveServerResponsePolicy(ei, boi, destination, null, message)) - .andReturn(effectivePolicy); + EffectivePolicy effectivePolicy = mock(EffectivePolicy.class); + when(pe.getEffectiveServerResponsePolicy(ei, boi, destination, null, message)) + .thenReturn(effectivePolicy); List> li = createMockInterceptorList(); - EasyMock.expect(effectivePolicy.getInterceptors()) - .andReturn(li); - InterceptorChain ic = control.createMock(InterceptorChain.class); - EasyMock.expect(message.getInterceptorChain()).andReturn(ic); + when(effectivePolicy.getInterceptors()) + .thenReturn(li); + InterceptorChain ic = mock(InterceptorChain.class); + when(message.getInterceptorChain()).thenReturn(ic); ic.add(li.get(0)); - EasyMock.expectLastCall(); + Collection assertions = CastUtils.cast(Collections.EMPTY_LIST, Assertion.class); - EasyMock.expect(effectivePolicy.getChosenAlternative()).andReturn(assertions); - control.replay(); + when(effectivePolicy.getChosenAlternative()).thenReturn(assertions); + interceptor.handleMessage(message); - control.verify(); } @Test public void testServerPolicyOutFaultInterceptor() throws NoSuchMethodException { - Method m = AbstractPolicyInterceptor.class.getDeclaredMethod("getBindingFaultInfo", - new Class[] {Message.class, Exception.class, BindingOperationInfo.class}); - - ServerPolicyOutFaultInterceptor interceptor = - EasyMock.createMockBuilder(ServerPolicyOutFaultInterceptor.class) - .addMockedMethod(m).createMock(control); + ServerPolicyOutFaultInterceptor interceptor = spy(new ServerPolicyOutFaultInterceptor()); doTestBasics(interceptor, false, true); - control.reset(); setupMessage(false, false, true, true, true, true); - Exception ex = control.createMock(Exception.class); - EasyMock.expect(exchange.get(Exception.class)).andReturn(ex); - EasyMock.expect(interceptor.getBindingFaultInfo(message, ex, boi)).andReturn(null); - control.replay(); + Exception ex = mock(Exception.class); + when(exchange.get(Exception.class)).thenReturn(ex); + when(interceptor.getBindingFaultInfo(message, ex, boi)).thenReturn(null); interceptor.handleMessage(message); - control.verify(); - control.reset(); setupMessage(false, false, true, true, true, true); - // Exception ex = control.createMock(Exception.class); - EasyMock.expect(exchange.get(Exception.class)).andReturn(ex); - BindingFaultInfo bfi = control.createMock(BindingFaultInfo.class); - EasyMock.expect(interceptor.getBindingFaultInfo(message, ex, boi)).andReturn(bfi); - EffectivePolicy effectivePolicy = control.createMock(EffectivePolicyImpl.class); - EasyMock.expect(pe.getEffectiveServerFaultPolicy(ei, boi, bfi, destination, message)) - .andReturn(effectivePolicy); + // Exception ex = mock(Exception.class); + when(exchange.get(Exception.class)).thenReturn(ex); + BindingFaultInfo bfi = mock(BindingFaultInfo.class); + when(interceptor.getBindingFaultInfo(message, ex, boi)).thenReturn(bfi); + EffectivePolicy effectivePolicy = mock(EffectivePolicyImpl.class); + when(pe.getEffectiveServerFaultPolicy(ei, boi, bfi, destination, message)) + .thenReturn(effectivePolicy); List> li = createMockInterceptorList(); - EasyMock.expect(effectivePolicy.getInterceptors()) - .andReturn(li); - InterceptorChain ic = control.createMock(InterceptorChain.class); - EasyMock.expect(message.getInterceptorChain()).andReturn(ic); + when(effectivePolicy.getInterceptors()) + .thenReturn(li); + InterceptorChain ic = mock(InterceptorChain.class); + when(message.getInterceptorChain()).thenReturn(ic); ic.add(li.get(0)); - EasyMock.expectLastCall(); + Collection assertions = CastUtils.cast(Collections.EMPTY_LIST, Assertion.class); - EasyMock.expect(effectivePolicy.getChosenAlternative()).andReturn(assertions); - control.replay(); + when(effectivePolicy.getChosenAlternative()).thenReturn(assertions); interceptor.handleMessage(message); - control.verify(); } @Test public void testServerPolicyOutFaultInterceptorGetBindingFaultInfo() { ServerPolicyOutFaultInterceptor interceptor = new ServerPolicyOutFaultInterceptor(); - message = control.createMock(Message.class); + message = mock(Message.class); Exception ex = new UnsupportedOperationException(new RuntimeException()); - boi = control.createMock(BindingOperationInfo.class); - EasyMock.expect(message.get(BindingFaultInfo.class)).andReturn(null); - BindingFaultInfo bfi = control.createMock(BindingFaultInfo.class); + boi = mock(BindingOperationInfo.class); + when(message.get(BindingFaultInfo.class)).thenReturn(null); + BindingFaultInfo bfi = mock(BindingFaultInfo.class); Collection bfis = CastUtils.cast(Collections.EMPTY_LIST); - EasyMock.expect(boi.getFaults()).andReturn(bfis); - BindingOperationInfo wrappedBoi = control.createMock(BindingOperationInfo.class); - EasyMock.expect(boi.getWrappedOperation()).andReturn(wrappedBoi).times(2); + when(boi.getFaults()).thenReturn(bfis); + BindingOperationInfo wrappedBoi = mock(BindingOperationInfo.class); + when(boi.getWrappedOperation()).thenReturn(wrappedBoi); Collection wrappedBfis = CastUtils.cast(Collections.singletonList(bfi)); - EasyMock.expect(wrappedBoi.getFaults()).andReturn(wrappedBfis); - FaultInfo fi = control.createMock(FaultInfo.class); - EasyMock.expect(bfi.getFaultInfo()).andReturn(fi); - EasyMock.expect(fi.getProperty(Class.class.getName(), Class.class)) - .andReturn(RuntimeException.class); + when(wrappedBoi.getFaults()).thenReturn(wrappedBfis); + FaultInfo fi = mock(FaultInfo.class); + when(bfi.getFaultInfo()).thenReturn(fi); + when(fi.getProperty(Class.class.getName(), Class.class)) + .thenReturn(RuntimeException.class); message.put(BindingFaultInfo.class, bfi); - EasyMock.expectLastCall(); - control.replay(); assertSame(bfi, interceptor.getBindingFaultInfo(message, ex, boi)); - control.verify(); + verify(boi, times(2)).getWrappedOperation(); } @Test @@ -286,13 +267,10 @@ public void testClientPolicyInInterceptorPolicyOverride() { doTestBasics(interceptor, true, false); - control.reset(); setupMessage(true, true, true, true, true, true); coachPolicyOverride(true, false); - control.replay(); interceptor.handleMessage(message); - control.verify(); } @Test @@ -301,13 +279,10 @@ public void testClientPolicyOutInterceptorPolicyOverride() { doTestBasics(interceptor, true, true); - control.reset(); setupMessage(true, true, true, true, true, true); coachPolicyOverride(false, false); - control.replay(); interceptor.handleMessage(message); - control.verify(); } @Test @@ -316,13 +291,10 @@ public void testServerPolicyInInterceptorPolicyOverride() { doTestBasics(interceptor, false, false); - control.reset(); setupMessage(false, false, false, false, true, true); coachPolicyOverride(true, false); - control.replay(); interceptor.handleMessage(message); - control.verify(); } @Test @@ -331,13 +303,10 @@ public void testServerPolicyOutInterceptorPolicyOverride() { doTestBasics(interceptor, false, true); - control.reset(); setupMessage(false, false, true, true, true, true); coachPolicyOverride(false, false); - control.replay(); interceptor.handleMessage(message); - control.verify(); } @@ -347,13 +316,10 @@ public void testClientPolicyInFaultInterceptorPolicyOverride() { doTestBasics(interceptor, true, false); - control.reset(); setupMessage(true, true, false, false, true, true); coachPolicyOverride(true, true); - control.replay(); interceptor.handleMessage(message); - control.verify(); } @Test @@ -361,38 +327,24 @@ public void testServerPolicyOutFaultInterceptorPolicyOverride() { ServerPolicyOutFaultInterceptor interceptor = new ServerPolicyOutFaultInterceptor(); doTestBasics(interceptor, false, true); - control.reset(); setupMessage(false, false, true, true, true, true); coachPolicyOverride(false, true); - control.replay(); interceptor.handleMessage(message); - control.verify(); } private void doTestBasics(Interceptor interceptor, boolean isClient, boolean usesOperationInfo) { setupMessage(!isClient, isClient, usesOperationInfo, !usesOperationInfo, false, false); - control.replay(); interceptor.handleMessage(message); - control.verify(); - control.reset(); setupMessage(isClient, isClient, usesOperationInfo, !usesOperationInfo, false, false); - control.replay(); interceptor.handleMessage(message); - control.verify(); - control.reset(); setupMessage(isClient, isClient, usesOperationInfo, usesOperationInfo, false, false); - control.replay(); interceptor.handleMessage(message); - control.verify(); - control.reset(); setupMessage(isClient, isClient, usesOperationInfo, usesOperationInfo, true, false); - control.replay(); interceptor.handleMessage(message); - control.verify(); } void setupMessage(boolean setupRequestor, @@ -402,88 +354,85 @@ void setupMessage(boolean setupRequestor, Boolean setupEndpoint, Boolean setupEngine) { - message = control.createMock(Message.class); + message = mock(Message.class); - exchange = control.createMock(Exchange.class); - EasyMock.expect(message.get(Message.REQUESTOR_ROLE)) - .andReturn(isClient ? Boolean.TRUE : Boolean.FALSE).anyTimes(); + exchange = mock(Exchange.class); + when(message.get(Message.REQUESTOR_ROLE)) + .thenReturn(isClient ? Boolean.TRUE : Boolean.FALSE); - EasyMock.expect(message.getExchange()).andReturn(exchange); + when(message.getExchange()).thenReturn(exchange); - EasyMock.expect(exchange.getBus()).andReturn(bus).anyTimes(); + when(exchange.getBus()).thenReturn(bus); if (usesOperationInfo) { if (null == boi && setupOperation) { - boi = control.createMock(BindingOperationInfo.class); + boi = mock(BindingOperationInfo.class); } - EasyMock.expect(exchange.getBindingOperationInfo()).andReturn(setupOperation ? boi : null) - .anyTimes(); + when(exchange.getBindingOperationInfo()).thenReturn(setupOperation ? boi : null); if (!setupOperation) { return; } } if (null == endpoint && setupEndpoint) { - endpoint = control.createMock(Endpoint.class); + endpoint = mock(Endpoint.class); } - EasyMock.expect(exchange.getEndpoint()).andReturn(setupEndpoint ? endpoint : null); + when(exchange.getEndpoint()).thenReturn(setupEndpoint ? endpoint : null); if (!setupEndpoint) { return; } if (null == ei) { - ei = control.createMock(EndpointInfo.class); + ei = mock(EndpointInfo.class); } - EasyMock.expect(endpoint.getEndpointInfo()).andReturn(ei); + when(endpoint.getEndpointInfo()).thenReturn(ei); if (null == pe && setupEngine) { - pe = control.createMock(PolicyEngineImpl.class); + pe = mock(PolicyEngineImpl.class); } - EasyMock.expect(bus.getExtension(PolicyEngine.class)).andReturn(setupEngine ? pe : null); + when(bus.getExtension(PolicyEngine.class)).thenReturn(setupEngine ? pe : null); if (!setupEngine) { return; } if (isClient) { - conduit = control.createMock(Conduit.class); - EasyMock.expect(exchange.getConduit(message)).andReturn(conduit).anyTimes(); + conduit = mock(Conduit.class); + when(exchange.getConduit(message)).thenReturn(conduit); } else { - destination = control.createMock(Destination.class); - EasyMock.expect(exchange.getDestination()).andReturn(destination).anyTimes(); + destination = mock(Destination.class); + when(exchange.getDestination()).thenReturn(destination); } } private void coachPolicyOverride(boolean in, boolean fault) { - Assertion assertion = control.createMock(Assertion.class); - EasyMock.expect(assertion.getName()).andReturn(ASSERTION_QNAME); + Assertion assertion = mock(Assertion.class); + when(assertion.getName()).thenReturn(ASSERTION_QNAME); Collection assertions = new ArrayList<>(); assertions.add(assertion); - Policy policyOverride = control.createMock(Policy.class); - EasyMock.expect(message.getContextualProperty(PolicyConstants.POLICY_OVERRIDE)) - .andReturn(policyOverride); - AlternativeSelector selector = control.createMock(AlternativeSelector.class); - EasyMock.expect(selector.selectAlternative(policyOverride, pe, null, null, message)).andReturn(assertions); - EasyMock.expect(pe.getAlternativeSelector()).andReturn(selector); - EasyMock.expect(pe.getBus()).andReturn(bus).anyTimes(); - PolicyInterceptorProviderRegistry reg = control - .createMock(PolicyInterceptorProviderRegistry.class); - EasyMock.expect(bus.getExtension(PolicyInterceptorProviderRegistry.class)).andReturn(reg); + Policy policyOverride = mock(Policy.class); + when(message.getContextualProperty(PolicyConstants.POLICY_OVERRIDE)) + .thenReturn(policyOverride); + AlternativeSelector selector = mock(AlternativeSelector.class); + when(selector.selectAlternative(policyOverride, pe, null, null, message)).thenReturn(assertions); + when(pe.getAlternativeSelector()).thenReturn(selector); + when(pe.getBus()).thenReturn(bus); + PolicyInterceptorProviderRegistry reg = mock(PolicyInterceptorProviderRegistry.class); + when(bus.getExtension(PolicyInterceptorProviderRegistry.class)).thenReturn(reg); List> li = createMockInterceptorList(); if (in && fault) { - EasyMock.expect(reg.getInFaultInterceptorsForAssertion(ASSERTION_QNAME)).andReturn(li); + when(reg.getInFaultInterceptorsForAssertion(ASSERTION_QNAME)).thenReturn(li); } else if (!in && fault) { - EasyMock.expect(reg.getOutFaultInterceptorsForAssertion(ASSERTION_QNAME)).andReturn(li); + when(reg.getOutFaultInterceptorsForAssertion(ASSERTION_QNAME)).thenReturn(li); } else if (in && !fault) { - EasyMock.expect(reg.getInInterceptorsForAssertion(ASSERTION_QNAME)).andReturn(li); + when(reg.getInInterceptorsForAssertion(ASSERTION_QNAME)).thenReturn(li); } else if (!in && !fault) { - EasyMock.expect(reg.getOutInterceptorsForAssertion(ASSERTION_QNAME)).andReturn(li); + when(reg.getOutInterceptorsForAssertion(ASSERTION_QNAME)).thenReturn(li); } - InterceptorChain ic = control.createMock(InterceptorChain.class); - EasyMock.expect(message.getInterceptorChain()).andReturn(ic).anyTimes(); + InterceptorChain ic = mock(InterceptorChain.class); + when(message.getInterceptorChain()).thenReturn(ic); ic.add(li.get(0)); - EasyMock.expectLastCall(); } } \ No newline at end of file diff --git a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyRegistryImplTest.java b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyRegistryImplTest.java index 9934c31383c..42ab51fdaa7 100644 --- a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyRegistryImplTest.java +++ b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyRegistryImplTest.java @@ -21,12 +21,11 @@ import org.apache.neethi.Policy; -import org.easymock.EasyMock; -import org.easymock.IMocksControl; import org.junit.Test; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; +import static org.mockito.Mockito.mock; /** * @@ -36,8 +35,7 @@ public class PolicyRegistryImplTest { @Test public void testAll() { PolicyRegistryImpl reg = new PolicyRegistryImpl(); - IMocksControl control = EasyMock.createNiceControl(); - Policy policy = control.createMock(Policy.class); + Policy policy = mock(Policy.class); String key = "key"; assertNull(reg.lookup(key)); reg.register(key, policy); diff --git a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInFaultInterceptorTest.java b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInFaultInterceptorTest.java index e0cbcfb5e20..13985f30fcd 100644 --- a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInFaultInterceptorTest.java +++ b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInFaultInterceptorTest.java @@ -19,8 +19,6 @@ package org.apache.cxf.ws.policy; -import java.lang.reflect.Method; - import org.apache.cxf.Bus; import org.apache.cxf.endpoint.Endpoint; import org.apache.cxf.message.Exchange; @@ -30,17 +28,17 @@ import org.apache.cxf.service.model.EndpointInfo; import org.apache.neethi.Policy; -import org.easymock.EasyMock; -import org.easymock.IMocksControl; import org.junit.Before; import org.junit.Test; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + /** * */ public class PolicyVerificationInFaultInterceptorTest { - private IMocksControl control; private Bus bus; private Message message; private Exchange exchange; @@ -54,67 +52,40 @@ public class PolicyVerificationInFaultInterceptorTest { @Before public void setUp() { - control = EasyMock.createNiceControl(); - bus = control.createMock(Bus.class); + bus = mock(Bus.class); } @Test public void testHandleMessage() throws NoSuchMethodException { - Method m = AbstractPolicyInterceptor.class.getDeclaredMethod("getTransportAssertions", - new Class[] {Message.class}); - - PolicyVerificationInFaultInterceptor interceptor = - EasyMock.createMockBuilder(PolicyVerificationInFaultInterceptor.class) - .addMockedMethod(m).createMock(control); + PolicyVerificationInFaultInterceptor interceptor = new PolicyVerificationInFaultInterceptor(); setupMessage(false, false, false, false, false, false); - control.replay(); interceptor.handleMessage(message); - control.verify(); - control.reset(); setupMessage(true, false, false, false, false, false); - control.replay(); interceptor.handleMessage(message); - control.verify(); - control.reset(); setupMessage(true, true, false, false, false, false); - control.replay(); interceptor.handleMessage(message); - control.verify(); - control.reset(); setupMessage(true, true, true, false, false, false); - control.replay(); interceptor.handleMessage(message); - control.verify(); - control.reset(); setupMessage(true, true, true, true, false, false); - control.replay(); interceptor.handleMessage(message); - control.verify(); - control.reset(); setupMessage(true, true, true, true, true, false); - control.replay(); interceptor.handleMessage(message); - control.verify(); - control.reset(); setupMessage(true, true, true, true, true, true); interceptor.getTransportAssertions(message); - EasyMock.expectLastCall(); - EffectivePolicyImpl effectivePolicy = control.createMock(EffectivePolicyImpl.class); - EasyMock.expect(engine.getEffectiveClientFaultPolicy(ei, boi, bfi, message)).andReturn(effectivePolicy); - Policy policy = control.createMock(Policy.class); - EasyMock.expect(effectivePolicy.getPolicy()).andReturn(policy); - aim.checkEffectivePolicy(policy); - EasyMock.expectLastCall().andReturn(null); - control.replay(); + + EffectivePolicyImpl effectivePolicy = mock(EffectivePolicyImpl.class); + when(engine.getEffectiveClientFaultPolicy(ei, boi, bfi, message)).thenReturn(effectivePolicy); + Policy policy = mock(Policy.class); + when(effectivePolicy.getPolicy()).thenReturn(policy); + when(aim.checkEffectivePolicy(policy)).thenReturn(null); interceptor.handleMessage(message); - control.verify(); } void setupMessage(boolean requestor, @@ -125,65 +96,65 @@ void setupMessage(boolean requestor, boolean setupBindingFaultInfo) { if (null == message) { - message = control.createMock(Message.class); + message = mock(Message.class); } if (setupAssertionInfoMap && null == aim) { - aim = control.createMock(AssertionInfoMap.class); + aim = mock(AssertionInfoMap.class); } - EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim); + when(message.get(AssertionInfoMap.class)).thenReturn(aim); if (!setupAssertionInfoMap) { return; } if (null == exchange) { - exchange = control.createMock(Exchange.class); + exchange = mock(Exchange.class); } - EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn( + when(message.get(Message.REQUESTOR_ROLE)).thenReturn( requestor ? Boolean.TRUE : Boolean.FALSE); if (!requestor) { return; } - EasyMock.expect(message.getExchange()).andReturn(exchange); + when(message.getExchange()).thenReturn(exchange); if (setupOperationInfo && null == boi) { - boi = control.createMock(BindingOperationInfo.class); + boi = mock(BindingOperationInfo.class); } - EasyMock.expect(exchange.getBindingOperationInfo()).andReturn(boi); + when(exchange.getBindingOperationInfo()).thenReturn(boi); if (!setupOperationInfo) { return; } if (setupEndpoint && null == endpoint) { - endpoint = control.createMock(Endpoint.class); + endpoint = mock(Endpoint.class); } - EasyMock.expect(exchange.getEndpoint()).andReturn(endpoint); + when(exchange.getEndpoint()).thenReturn(endpoint); if (!setupEndpoint) { return; } if (null == ei) { - ei = control.createMock(EndpointInfo.class); + ei = mock(EndpointInfo.class); } - EasyMock.expect(endpoint.getEndpointInfo()).andReturn(ei); + when(endpoint.getEndpointInfo()).thenReturn(ei); - EasyMock.expect(exchange.getBus()).andReturn(bus); + when(exchange.getBus()).thenReturn(bus); if (setupPolicyEngine && null == engine) { - engine = control.createMock(PolicyEngine.class); + engine = mock(PolicyEngine.class); } - EasyMock.expect(bus.getExtension(PolicyEngine.class)).andReturn(engine); + when(bus.getExtension(PolicyEngine.class)).thenReturn(engine); if (!setupPolicyEngine) { return; } if (null == ex) { - ex = control.createMock(Exception.class); + ex = mock(Exception.class); } - EasyMock.expect(message.getContent(Exception.class)).andReturn(null); - EasyMock.expect(exchange.get(Exception.class)).andReturn(ex); + when(message.getContent(Exception.class)).thenReturn(null); + when(exchange.get(Exception.class)).thenReturn(ex); if (setupBindingFaultInfo && null == bfi) { - bfi = control.createMock(BindingFaultInfo.class); + bfi = mock(BindingFaultInfo.class); } - EasyMock.expect(message.get(BindingFaultInfo.class)).andReturn(bfi); + when(message.get(BindingFaultInfo.class)).thenReturn(bfi); } } diff --git a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInInterceptorTest.java b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInInterceptorTest.java index 2ddac058da2..80ca56df117 100644 --- a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInInterceptorTest.java +++ b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationInInterceptorTest.java @@ -19,8 +19,6 @@ package org.apache.cxf.ws.policy; -import java.lang.reflect.Method; - import org.apache.cxf.Bus; import org.apache.cxf.endpoint.Endpoint; import org.apache.cxf.message.Exchange; @@ -29,17 +27,17 @@ import org.apache.cxf.service.model.EndpointInfo; import org.apache.neethi.Policy; -import org.easymock.EasyMock; -import org.easymock.IMocksControl; import org.junit.Before; import org.junit.Test; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + /** * */ public class PolicyVerificationInInterceptorTest { - private IMocksControl control; private Bus bus; private Message message; private Exchange exchange; @@ -51,8 +49,7 @@ public class PolicyVerificationInInterceptorTest { @Before public void setUp() { - control = EasyMock.createNiceControl(); - bus = control.createMock(Bus.class); + bus = mock(Bus.class); } @Test @@ -61,68 +58,44 @@ public void testHandleMessageNoOp() throws NoSuchMethodException { PolicyVerificationInInterceptor interceptor = new PolicyVerificationInInterceptor(); setupMessage(false, false, false, false); - control.replay(); interceptor.handleMessage(message); - control.verify(); - control.reset(); setupMessage(true, false, false, false); - control.replay(); interceptor.handleMessage(message); - control.verify(); - control.reset(); + setupMessage(true, true, false, false); - control.replay(); interceptor.handleMessage(message); - control.verify(); - control.reset(); setupMessage(true, true, true, false); - control.replay(); interceptor.handleMessage(message); - control.verify(); - } @Test public void testHandleMessage() throws NoSuchMethodException { - - control.reset(); - Method m = AbstractPolicyInterceptor.class.getDeclaredMethod("getTransportAssertions", - new Class[] {Message.class}); - PolicyVerificationInInterceptor interceptor = - EasyMock.createMockBuilder(PolicyVerificationInInterceptor.class) - .addMockedMethod(m).createMock(control); + PolicyVerificationInInterceptor interceptor = new PolicyVerificationInInterceptor(); setupMessage(true, true, true, true); - EasyMock.expect(message.get(Message.PARTIAL_RESPONSE_MESSAGE)).andReturn(Boolean.FALSE); + when(message.get(Message.PARTIAL_RESPONSE_MESSAGE)).thenReturn(Boolean.FALSE); interceptor.getTransportAssertions(message); - EasyMock.expectLastCall(); - EffectivePolicy effectivePolicy = control.createMock(EffectivePolicy.class); - EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.TRUE); - EasyMock.expect(engine.getEffectiveClientResponsePolicy(ei, boi, message)).andReturn(effectivePolicy); - Policy policy = control.createMock(Policy.class); - EasyMock.expect(effectivePolicy.getPolicy()).andReturn(policy); - aim.checkEffectivePolicy(policy); - EasyMock.expectLastCall().andReturn(null); - control.replay(); + + EffectivePolicy effectivePolicy = mock(EffectivePolicy.class); + when(message.get(Message.REQUESTOR_ROLE)).thenReturn(Boolean.TRUE); + when(engine.getEffectiveClientResponsePolicy(ei, boi, message)).thenReturn(effectivePolicy); + Policy policy = mock(Policy.class); + when(effectivePolicy.getPolicy()).thenReturn(policy); + when(aim.checkEffectivePolicy(policy)).thenReturn(null); interceptor.handleMessage(message); - control.verify(); - control.reset(); setupMessage(true, true, true, true); - EasyMock.expect(message.get(Message.PARTIAL_RESPONSE_MESSAGE)).andReturn(Boolean.FALSE); + when(message.get(Message.PARTIAL_RESPONSE_MESSAGE)).thenReturn(Boolean.FALSE); interceptor.getTransportAssertions(message); - EasyMock.expectLastCall(); - effectivePolicy = control.createMock(EffectivePolicy.class); - EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.FALSE); - EasyMock.expect(engine.getEffectiveServerRequestPolicy(ei, boi, message)).andReturn(effectivePolicy); - policy = control.createMock(Policy.class); - EasyMock.expect(effectivePolicy.getPolicy()).andReturn(policy); - aim.checkEffectivePolicy(policy); - EasyMock.expectLastCall().andReturn(null); - control.replay(); + + effectivePolicy = mock(EffectivePolicy.class); + when(message.get(Message.REQUESTOR_ROLE)).thenReturn(Boolean.FALSE); + when(engine.getEffectiveServerRequestPolicy(ei, boi, message)).thenReturn(effectivePolicy); + policy = mock(Policy.class); + when(effectivePolicy.getPolicy()).thenReturn(policy); + when(aim.checkEffectivePolicy(policy)).thenReturn(null); interceptor.handleMessage(message); - control.verify(); } void setupMessage(boolean setupBindingOperationInfo, @@ -130,42 +103,42 @@ void setupMessage(boolean setupBindingOperationInfo, boolean setupPolicyEngine, boolean setupAssertionInfoMap) { if (null == message) { - message = control.createMock(Message.class); + message = mock(Message.class); } if (null == exchange) { - exchange = control.createMock(Exchange.class); + exchange = mock(Exchange.class); } if (setupAssertionInfoMap && null == aim) { - aim = control.createMock(AssertionInfoMap.class); + aim = mock(AssertionInfoMap.class); } - EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim); + when(message.get(AssertionInfoMap.class)).thenReturn(aim); if (aim == null) { return; } - EasyMock.expect(exchange.getBus()).andReturn(bus).anyTimes(); - EasyMock.expect(message.getExchange()).andReturn(exchange); + when(exchange.getBus()).thenReturn(bus); + when(message.getExchange()).thenReturn(exchange); if (setupBindingOperationInfo && null == boi) { - boi = control.createMock(BindingOperationInfo.class); + boi = mock(BindingOperationInfo.class); } - EasyMock.expect(exchange.getBindingOperationInfo()).andReturn(boi); + when(exchange.getBindingOperationInfo()).thenReturn(boi); if (!setupBindingOperationInfo) { return; } if (setupEndpoint && null == endpoint) { - endpoint = control.createMock(Endpoint.class); + endpoint = mock(Endpoint.class); } - EasyMock.expect(exchange.getEndpoint()).andReturn(endpoint); + when(exchange.getEndpoint()).thenReturn(endpoint); if (!setupEndpoint) { return; } - ei = control.createMock(EndpointInfo.class); - EasyMock.expect(endpoint.getEndpointInfo()).andReturn(ei); + ei = mock(EndpointInfo.class); + when(endpoint.getEndpointInfo()).thenReturn(ei); if (setupPolicyEngine && null == engine) { - engine = control.createMock(PolicyEngine.class); + engine = mock(PolicyEngine.class); } - EasyMock.expect(bus.getExtension(PolicyEngine.class)).andReturn(engine); + when(bus.getExtension(PolicyEngine.class)).thenReturn(engine); if (!setupPolicyEngine) { return; } diff --git a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationOutInterceptorTest.java b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationOutInterceptorTest.java index 853414882ab..49b8e625ca3 100644 --- a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationOutInterceptorTest.java +++ b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/PolicyVerificationOutInterceptorTest.java @@ -19,64 +19,46 @@ package org.apache.cxf.ws.policy; -import java.lang.reflect.Method; - +import org.apache.cxf.message.Exchange; import org.apache.cxf.message.Message; +import org.apache.cxf.transport.Destination; -import org.easymock.EasyMock; -import org.easymock.IMocksControl; -import org.junit.Before; import org.junit.Test; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + /** * */ public class PolicyVerificationOutInterceptorTest { - - private IMocksControl control; - - @Before - public void setUp() { - control = EasyMock.createNiceControl(); - } - @Test public void testHandleMessage() throws NoSuchMethodException { - Method m = AbstractPolicyInterceptor.class.getDeclaredMethod("getTransportAssertions", - new Class[] {Message.class}); - PolicyVerificationOutInterceptor interceptor = - EasyMock.createMockBuilder(PolicyVerificationOutInterceptor.class) - .addMockedMethod(m).createMock(control); + PolicyVerificationOutInterceptor interceptor = new PolicyVerificationOutInterceptor(); - Message message = control.createMock(Message.class); - EasyMock.expect(message.get(Message.PARTIAL_RESPONSE_MESSAGE)).andReturn(Boolean.TRUE); - control.replay(); + Destination destination = mock(Destination.class); + Exchange exchange = mock(Exchange.class); + when(exchange.getDestination()).thenReturn(destination); + Message message = mock(Message.class); + when(message.get(Message.PARTIAL_RESPONSE_MESSAGE)).thenReturn(Boolean.TRUE); + when(message.getExchange()).thenReturn(exchange); interceptor.handleMessage(message); - control.verify(); - control.reset(); - EasyMock.expect(message.get(Message.PARTIAL_RESPONSE_MESSAGE)).andReturn(null); - EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(null); - control.replay(); + when(message.get(Message.PARTIAL_RESPONSE_MESSAGE)).thenReturn(null); + when(message.get(AssertionInfoMap.class)).thenReturn(null); interceptor.handleMessage(message); - control.verify(); - control.reset(); - EasyMock.expect(message.get(Message.PARTIAL_RESPONSE_MESSAGE)).andReturn(null); - AssertionInfoMap aim = control.createMock(AssertionInfoMap.class); - EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim); + when(message.get(Message.PARTIAL_RESPONSE_MESSAGE)).thenReturn(null); + AssertionInfoMap aim = mock(AssertionInfoMap.class); + when(message.get(AssertionInfoMap.class)).thenReturn(aim); interceptor.getTransportAssertions(message); - EasyMock.expectLastCall(); - EffectivePolicy ep = control.createMock(EffectivePolicy.class); - EasyMock.expect(message.get(EffectivePolicy.class)).andReturn(ep); - EasyMock.expect(ep.getPolicy()).andReturn(null); - aim.checkEffectivePolicy(null); + EffectivePolicy ep = mock(EffectivePolicy.class); + when(message.get(EffectivePolicy.class)).thenReturn(ep); + when(ep.getPolicy()).thenReturn(null); - EasyMock.expectLastCall().andReturn(null); + when(aim.checkEffectivePolicy(null)).thenReturn(null); - control.replay(); interceptor.handleMessage(message); - control.verify(); } } diff --git a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/DomainExpressionBuilderRegistryTest.java b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/DomainExpressionBuilderRegistryTest.java index 78f6964e8dd..b36a72cb036 100644 --- a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/DomainExpressionBuilderRegistryTest.java +++ b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/DomainExpressionBuilderRegistryTest.java @@ -28,64 +28,49 @@ import org.apache.cxf.ws.policy.PolicyException; -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.assertSame; import static org.junit.Assert.fail; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; /** * */ public class DomainExpressionBuilderRegistryTest { - - private IMocksControl control; - - - @Before - public void setUp() { - control = EasyMock.createNiceControl(); - } - @Test public void testNoBuilder() { DomainExpressionBuilderRegistry reg = new DomainExpressionBuilderRegistry(); assertEquals(DomainExpressionBuilderRegistry.class, reg.getRegistrationType()); - Element e = control.createMock(Element.class); - EasyMock.expect(e.getNamespaceURI()).andReturn("http://a.b.c"); - EasyMock.expect(e.getLocalName()).andReturn("x"); + Element e = mock(Element.class); + when(e.getNamespaceURI()).thenReturn("http://a.b.c"); + when(e.getLocalName()).thenReturn("x"); - control.replay(); try { reg.build(e); fail("Expected PolicyException not thrown."); } catch (PolicyException ex) { // expected } - control.verify(); - } @Test public void testBuild() { - DomainExpressionBuilder builder = control.createMock(DomainExpressionBuilder.class); + DomainExpressionBuilder builder = mock(DomainExpressionBuilder.class); Map builders = new HashMap<>(); QName qn = new QName("http://a.b.c", "x"); builders.put(qn, builder); DomainExpressionBuilderRegistry reg = new DomainExpressionBuilderRegistry(builders); - Element e = control.createMock(Element.class); - EasyMock.expect(e.getNamespaceURI()).andReturn("http://a.b.c"); - EasyMock.expect(e.getLocalName()).andReturn("x"); - DomainExpression de = control.createMock(DomainExpression.class); - EasyMock.expect(builder.build(e)).andReturn(de); + Element e = mock(Element.class); + when(e.getNamespaceURI()).thenReturn("http://a.b.c"); + when(e.getLocalName()).thenReturn("x"); + DomainExpression de = mock(DomainExpression.class); + when(builder.build(e)).thenReturn(de); - control.replay(); assertSame(de, reg.build(e)); - control.verify(); } } \ No newline at end of file diff --git a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/EndpointReferenceDomainExpressionTest.java b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/EndpointReferenceDomainExpressionTest.java index 2e74128b815..33238282ce8 100644 --- a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/EndpointReferenceDomainExpressionTest.java +++ b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/EndpointReferenceDomainExpressionTest.java @@ -27,23 +27,19 @@ import org.apache.cxf.ws.addressing.AttributedURIType; import org.apache.cxf.ws.addressing.EndpointReferenceType; -import org.easymock.EasyMock; -import org.easymock.IMocksControl; -import org.junit.Before; import org.junit.Test; 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 EndpointReferenceDomainExpressionTest { - - private IMocksControl control; - // Avoid spurious failures on EasyMock detecting finalize calls // by using data members rather than local variables for these. private ServiceInfo si; @@ -51,46 +47,36 @@ public class EndpointReferenceDomainExpressionTest { private BindingMessageInfo bmi; private BindingFaultInfo bfi; - @Before - public void setUp() { - control = EasyMock.createNiceControl(); - } - @Test public void testEndpointReferenceDomainExpression() { - EndpointReferenceType epr = control.createMock(EndpointReferenceType.class); + EndpointReferenceType epr = mock(EndpointReferenceType.class); EndpointReferenceDomainExpression eprde = new EndpointReferenceDomainExpression(); assertNull(eprde.getEndpointReference()); eprde.setEndpointReference(epr); assertSame(epr, eprde.getEndpointReference()); - si = control.createMock(ServiceInfo.class); - boi = control.createMock(BindingOperationInfo.class); - bmi = control.createMock(BindingMessageInfo.class); - bfi = control.createMock(BindingFaultInfo.class); + si = mock(ServiceInfo.class); + boi = mock(BindingOperationInfo.class); + bmi = mock(BindingMessageInfo.class); + bfi = mock(BindingFaultInfo.class); assertFalse(eprde.appliesTo(si)); assertFalse(eprde.appliesTo(boi)); assertFalse(eprde.appliesTo(bmi)); assertFalse(eprde.appliesTo(bfi)); - EndpointInfo ei = control.createMock(EndpointInfo.class); - EasyMock.expect(ei.getAddress()).andReturn("http://localhost:8080/GreeterPort"); - AttributedURIType auri = control.createMock(AttributedURIType.class); - EasyMock.expect(epr.getAddress()).andReturn(auri); - EasyMock.expect(auri.getValue()).andReturn("http://localhost:8080/Greeter"); - control.replay(); + EndpointInfo ei = mock(EndpointInfo.class); + when(ei.getAddress()).thenReturn("http://localhost:8080/GreeterPort"); + AttributedURIType auri = mock(AttributedURIType.class); + when(epr.getAddress()).thenReturn(auri); + when(auri.getValue()).thenReturn("http://localhost:8080/Greeter"); assertFalse(eprde.appliesTo(ei)); - control.verify(); - control.reset(); - EasyMock.expect(ei.getAddress()).andReturn("http://localhost:8080/GreeterPort"); - EasyMock.expect(epr.getAddress()).andReturn(auri); - EasyMock.expect(auri.getValue()).andReturn("http://localhost:8080/GreeterPort"); - control.replay(); + when(ei.getAddress()).thenReturn("http://localhost:8080/GreeterPort"); + when(epr.getAddress()).thenReturn(auri); + when(auri.getValue()).thenReturn("http://localhost:8080/GreeterPort"); assertTrue(eprde.appliesTo(ei)); - control.verify(); bfi = null; bmi = null; diff --git a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/ExternalAttachmentProviderTest.java b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/ExternalAttachmentProviderTest.java index 551494e4db9..7eac52f1fdc 100644 --- a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/ExternalAttachmentProviderTest.java +++ b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/ExternalAttachmentProviderTest.java @@ -43,9 +43,6 @@ import org.springframework.core.io.Resource; import org.springframework.core.io.UrlResource; -import org.easymock.EasyMock; -import org.easymock.IMocksControl; -import org.junit.Before; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -53,7 +50,9 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; - +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; /** @@ -64,22 +63,17 @@ public class ExternalAttachmentProviderTest { private static final QName TEST_ASSERTION_TYPE = new QName("http://a.b.c", "x"); - private IMocksControl control; private Policy policy; private Assertion assertion; private PolicyAttachment attachment; private Collection attachments = new ArrayList<>(); - @Before - public void setUp() { - control = EasyMock.createNiceControl(); - } @Test public void testBasic() { ExternalAttachmentProvider eap = new ExternalAttachmentProvider(); assertNull(eap.getLocation()); - Resource uri = control.createMock(Resource.class); + Resource uri = mock(Resource.class); eap.setLocation(uri); assertSame(uri, eap.getLocation()); @@ -88,81 +82,56 @@ public void testBasic() { @Test public void testGetEffectiveFaultPolicy() { ExternalAttachmentProvider eap = new ExternalAttachmentProvider(); - BindingFaultInfo bfi = control.createMock(BindingFaultInfo.class); + BindingFaultInfo bfi = mock(BindingFaultInfo.class); setUpAttachment(bfi, false, eap); - control.replay(); assertNull(eap.getEffectivePolicy(bfi, null)); - control.verify(); - control.reset(); setUpAttachment(bfi, true, eap); - control.replay(); assertSame(assertion, eap.getEffectivePolicy(bfi, null).getAssertions().get(0)); - control.verify(); } @Test public void testGetEffectiveMessagePolicy() { ExternalAttachmentProvider eap = new ExternalAttachmentProvider(); - BindingMessageInfo bmi = control.createMock(BindingMessageInfo.class); + BindingMessageInfo bmi = mock(BindingMessageInfo.class); setUpAttachment(bmi, false, eap); - control.replay(); assertNull(eap.getEffectivePolicy(bmi, null)); - control.verify(); - control.reset(); setUpAttachment(bmi, true, eap); - control.replay(); assertSame(assertion, eap.getEffectivePolicy(bmi, null).getAssertions().get(0)); - control.verify(); } @Test public void testGetEffectiveOperationPolicy() { - BindingOperationInfo boi = control.createMock(BindingOperationInfo.class); + BindingOperationInfo boi = mock(BindingOperationInfo.class); ExternalAttachmentProvider eap = new ExternalAttachmentProvider(); setUpAttachment(boi, false, eap); - control.replay(); assertNull(eap.getEffectivePolicy(boi, null)); - control.verify(); - control.reset(); setUpAttachment(boi, true, eap); - control.replay(); assertSame(assertion, eap.getEffectivePolicy(boi, null).getAssertions().get(0)); - control.verify(); } @Test public void testGetEffectiveEndpointPolicy() { ExternalAttachmentProvider eap = new ExternalAttachmentProvider(); - EndpointInfo ei = control.createMock(EndpointInfo.class); + EndpointInfo ei = mock(EndpointInfo.class); setUpAttachment(ei, false, eap); - control.replay(); assertNull(eap.getEffectivePolicy(ei, null)); - control.verify(); - control.reset(); setUpAttachment(ei, true, eap); - control.replay(); assertSame(assertion, eap.getEffectivePolicy(ei, null).getAssertions().get(0)); - control.verify(); } @Test public void testGetEffectiveServicePolicy() { ExternalAttachmentProvider eap = new ExternalAttachmentProvider(); - ServiceInfo si = control.createMock(ServiceInfo.class); + ServiceInfo si = mock(ServiceInfo.class); setUpAttachment(si, false, eap); - control.replay(); assertNull(eap.getEffectivePolicy(si, null)); - control.verify(); - control.reset(); setUpAttachment(si, true, eap); - control.replay(); assertSame(assertion, eap.getEffectivePolicy(si, null).getAssertions().get(0)); - control.verify(); } @Test @@ -203,16 +172,15 @@ public void testReadDocumentAttachmentElementWithoutAppliesTo() throws Malformed @Test public void testReadDocumentUnknownDomainExpression() throws MalformedURLException { - Bus bus = control.createMock(Bus.class); + Bus bus = mock(Bus.class); - DomainExpressionBuilderRegistry debr = control.createMock(DomainExpressionBuilderRegistry.class); - EasyMock.expect(bus.getExtension(DomainExpressionBuilderRegistry.class)).andReturn(debr); - EasyMock.expect(debr.build(EasyMock.isA(Element.class))) - .andThrow(new PolicyException(new Exception())); + DomainExpressionBuilderRegistry debr = mock(DomainExpressionBuilderRegistry.class); + when(bus.getExtension(DomainExpressionBuilderRegistry.class)).thenReturn(debr); + when(debr.build(isA(Element.class))) + .thenThrow(new PolicyException(new Exception())); URL url = ExternalAttachmentProviderTest.class.getResource("resources/attachments3.xml"); String uri = url.toExternalForm(); - control.replay(); ExternalAttachmentProvider eap = new ExternalAttachmentProvider(bus); eap.setLocation(new UrlResource(uri)); try { @@ -221,25 +189,23 @@ public void testReadDocumentUnknownDomainExpression() throws MalformedURLExcepti } catch (PolicyException ex) { // expected } - control.verify(); } @Test public void testReadDocumentEPRDomainExpression() throws MalformedURLException { - Bus bus = control.createMock(Bus.class); + Bus bus = mock(Bus.class); - DomainExpressionBuilderRegistry debr = control.createMock(DomainExpressionBuilderRegistry.class); - EasyMock.expect(bus.getExtension(DomainExpressionBuilderRegistry.class)).andReturn(debr); - DomainExpression de = control.createMock(DomainExpression.class); - EasyMock.expect(debr.build(EasyMock.isA(Element.class))).andReturn(de); - PolicyBuilder pb = control.createMock(PolicyBuilder.class); - EasyMock.expect(bus.getExtension(PolicyBuilder.class)).andReturn(pb).anyTimes(); - Policy p = control.createMock(Policy.class); - EasyMock.expect(pb.getPolicy(EasyMock.isA(Element.class))).andReturn(p); + DomainExpressionBuilderRegistry debr = mock(DomainExpressionBuilderRegistry.class); + when(bus.getExtension(DomainExpressionBuilderRegistry.class)).thenReturn(debr); + DomainExpression de = mock(DomainExpression.class); + when(debr.build(isA(Element.class))).thenReturn(de); + PolicyBuilder pb = mock(PolicyBuilder.class); + when(bus.getExtension(PolicyBuilder.class)).thenReturn(pb); + Policy p = mock(Policy.class); + when(pb.getPolicy(isA(Element.class))).thenReturn(p); - control.replay(); ExternalAttachmentProvider eap = new ExternalAttachmentProvider(bus); URL url = ExternalAttachmentProviderTest.class.getResource("resources/attachments4.xml"); String uri = url.toExternalForm(); @@ -250,32 +216,31 @@ public void testReadDocumentEPRDomainExpression() throws MalformedURLException { assertSame(p, pa.getPolicy()); assertEquals(1, pa.getDomainExpressions().size()); assertSame(de, pa.getDomainExpressions().iterator().next()); - control.verify(); } void setUpAttachment(Object subject, boolean applies, ExternalAttachmentProvider eap) { attachments.clear(); - attachment = control.createMock(PolicyAttachment.class); + attachment = mock(PolicyAttachment.class); attachments.add(attachment); policy = new Policy(); assertion = new PrimitiveAssertion(TEST_ASSERTION_TYPE); policy.addAssertion(assertion); eap.setAttachments(attachments); if (subject instanceof ServiceInfo) { - EasyMock.expect(attachment.appliesTo((ServiceInfo)subject)).andReturn(applies); + when(attachment.appliesTo((ServiceInfo)subject)).thenReturn(applies); } else if (subject instanceof EndpointInfo) { - EasyMock.expect(attachment.appliesTo((EndpointInfo)subject)).andReturn(applies); + when(attachment.appliesTo((EndpointInfo)subject)).thenReturn(applies); } else if (subject instanceof BindingOperationInfo) { - EasyMock.expect(attachment.appliesTo((BindingOperationInfo)subject)).andReturn(applies); + when(attachment.appliesTo((BindingOperationInfo)subject)).thenReturn(applies); } else if (subject instanceof BindingMessageInfo) { - EasyMock.expect(attachment.appliesTo((BindingMessageInfo)subject)).andReturn(applies); + when(attachment.appliesTo((BindingMessageInfo)subject)).thenReturn(applies); } else if (subject instanceof BindingFaultInfo) { - EasyMock.expect(attachment.appliesTo((BindingFaultInfo)subject)).andReturn(applies); + when(attachment.appliesTo((BindingFaultInfo)subject)).thenReturn(applies); } else { System.err.println("subject class: " + subject.getClass()); } if (applies) { - EasyMock.expect(attachment.getPolicy()).andReturn(policy); + when(attachment.getPolicy()).thenReturn(policy); } } diff --git a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/PolicyAttachmentTest.java b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/PolicyAttachmentTest.java index 4d2add7ec8c..c48c41d068a 100644 --- a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/PolicyAttachmentTest.java +++ b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/PolicyAttachmentTest.java @@ -30,36 +30,26 @@ import org.apache.cxf.service.model.ServiceInfo; import org.apache.neethi.Policy; -import org.easymock.EasyMock; -import org.easymock.IMocksControl; -import org.junit.Before; import org.junit.Test; 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 PolicyAttachmentTest { - - private IMocksControl control; - - - @Before - public void setUp() { - control = EasyMock.createNiceControl(); - } - @Test public void testBasic() { PolicyAttachment pa = new PolicyAttachment(); assertNull(pa.getDomainExpressions()); assertNull(pa.getPolicy()); - Policy p = control.createMock(Policy.class); + Policy p = mock(Policy.class); Collection des = CastUtils.cast(Collections.emptyList(), DomainExpression.class); pa.setPolicy(p); @@ -70,87 +60,83 @@ public void testBasic() { @Test public void testAppliesToService() { - ServiceInfo si1 = control.createMock(ServiceInfo.class); - ServiceInfo si2 = control.createMock(ServiceInfo.class); - DomainExpression de = control.createMock(DomainExpression.class); + ServiceInfo si1 = mock(ServiceInfo.class); + ServiceInfo si2 = mock(ServiceInfo.class); + DomainExpression de = mock(DomainExpression.class); Collection des = Collections.singletonList(de); PolicyAttachment pa = new PolicyAttachment(); pa.setDomainExpressions(des); - EasyMock.expect(de.appliesTo(si1)).andReturn(false); - EasyMock.expect(de.appliesTo(si2)).andReturn(true); - control.replay(); + when(de.appliesTo(si1)).thenReturn(false); + when(de.appliesTo(si2)).thenReturn(true); + assertFalse(pa.appliesTo(si1)); assertTrue(pa.appliesTo(si2)); - control.verify(); } @Test public void testAppliesToEndpoint() { - EndpointInfo ei1 = control.createMock(EndpointInfo.class); - EndpointInfo ei2 = control.createMock(EndpointInfo.class); - DomainExpression de = control.createMock(DomainExpression.class); + EndpointInfo ei1 = mock(EndpointInfo.class); + EndpointInfo ei2 = mock(EndpointInfo.class); + DomainExpression de = mock(DomainExpression.class); Collection des = Collections.singletonList(de); PolicyAttachment pa = new PolicyAttachment(); pa.setDomainExpressions(des); - EasyMock.expect(de.appliesTo(ei1)).andReturn(false); - EasyMock.expect(de.appliesTo(ei2)).andReturn(true); - control.replay(); + when(de.appliesTo(ei1)).thenReturn(false); + when(de.appliesTo(ei2)).thenReturn(true); + assertFalse(pa.appliesTo(ei1)); assertTrue(pa.appliesTo(ei2)); - control.verify(); + } @Test public void testAppliesToOperation() { - BindingOperationInfo boi1 = control.createMock(BindingOperationInfo.class); - BindingOperationInfo boi2 = control.createMock(BindingOperationInfo.class); - DomainExpression de = control.createMock(DomainExpression.class); + BindingOperationInfo boi1 = mock(BindingOperationInfo.class); + BindingOperationInfo boi2 = mock(BindingOperationInfo.class); + DomainExpression de = mock(DomainExpression.class); Collection des = Collections.singletonList(de); PolicyAttachment pa = new PolicyAttachment(); pa.setDomainExpressions(des); - EasyMock.expect(de.appliesTo(boi1)).andReturn(false); - EasyMock.expect(de.appliesTo(boi2)).andReturn(true); - control.replay(); + when(de.appliesTo(boi1)).thenReturn(false); + when(de.appliesTo(boi2)).thenReturn(true); + assertFalse(pa.appliesTo(boi1)); assertTrue(pa.appliesTo(boi2)); - control.verify(); } @Test public void testAppliesToMessage() { - BindingMessageInfo bmi1 = control.createMock(BindingMessageInfo.class); - BindingMessageInfo bmi2 = control.createMock(BindingMessageInfo.class); - DomainExpression de = control.createMock(DomainExpression.class); + BindingMessageInfo bmi1 = mock(BindingMessageInfo.class); + BindingMessageInfo bmi2 = mock(BindingMessageInfo.class); + DomainExpression de = mock(DomainExpression.class); Collection des = Collections.singletonList(de); PolicyAttachment pa = new PolicyAttachment(); pa.setDomainExpressions(des); - EasyMock.expect(de.appliesTo(bmi1)).andReturn(false); - EasyMock.expect(de.appliesTo(bmi2)).andReturn(true); - control.replay(); + when(de.appliesTo(bmi1)).thenReturn(false); + when(de.appliesTo(bmi2)).thenReturn(true); + assertFalse(pa.appliesTo(bmi1)); assertTrue(pa.appliesTo(bmi2)); - control.verify(); } @Test public void testAppliesToFault() { - BindingFaultInfo bfi1 = control.createMock(BindingFaultInfo.class); - BindingFaultInfo bfi2 = control.createMock(BindingFaultInfo.class); - DomainExpression de = control.createMock(DomainExpression.class); + BindingFaultInfo bfi1 = mock(BindingFaultInfo.class); + BindingFaultInfo bfi2 = mock(BindingFaultInfo.class); + DomainExpression de = mock(DomainExpression.class); Collection des = Collections.singletonList(de); PolicyAttachment pa = new PolicyAttachment(); pa.setDomainExpressions(des); - EasyMock.expect(de.appliesTo(bfi1)).andReturn(false); - EasyMock.expect(de.appliesTo(bfi2)).andReturn(true); - control.replay(); + when(de.appliesTo(bfi1)).thenReturn(false); + when(de.appliesTo(bfi2)).thenReturn(true); + assertFalse(pa.appliesTo(bfi1)); assertTrue(pa.appliesTo(bfi2)); - control.verify(); } diff --git a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/URIDomainExpressionTest.java b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/URIDomainExpressionTest.java index 5937585b591..809f95a2223 100644 --- a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/URIDomainExpressionTest.java +++ b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/URIDomainExpressionTest.java @@ -33,12 +33,12 @@ import org.apache.cxf.service.model.OperationInfo; import org.apache.cxf.service.model.ServiceInfo; -import org.easymock.EasyMock; -import org.easymock.IMocksControl; import org.junit.Assert; -import org.junit.Before; import org.junit.Test; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + public class URIDomainExpressionTest { private static final String TARGET_NAMESPACE = "http://org.apache.cxf/targetNamespace"; @@ -63,8 +63,6 @@ public class URIDomainExpressionTest { private static final String FAULT_NAME = "testFault"; private static final QName FAULT_QNAME = new QName(TARGET_NAMESPACE, FAULT_NAME); - private IMocksControl control; - private ServiceInfo si; private EndpointInfo ei; private BindingOperationInfo boi; @@ -72,17 +70,10 @@ public class URIDomainExpressionTest { private BindingFaultInfo bfi; private MessageInfo mi; - @Before - public void setUp() { - control = EasyMock.createNiceControl(); - } - @Test public void testServiceInfo() { mockInfoObjects(); - control.replay(); - String expression = TARGET_NAMESPACE + "#wsdl11.definitions()"; URIDomainExpression ude = new URIDomainExpression(expression); Assert.assertTrue("Expected true for expression: " + expression, ude.appliesTo(si)); @@ -102,16 +93,12 @@ public void testServiceInfo() { expression = TARGET_NAMESPACE + "wrong" + "#wsdl11.portType(" + INTERFACE_NAME + ")"; ude = new URIDomainExpression(expression); Assert.assertFalse("Expected false for expression: " + expression, ude.appliesTo(si)); - - control.reset(); } @Test public void testEndpointInfo() { mockInfoObjects(); - control.replay(); - String expression = TARGET_NAMESPACE + "#wsdl11.port(" + SERVICE_NAME + "/" + PORT_NAME + ")"; URIDomainExpression ude = new URIDomainExpression(expression); Assert.assertTrue("Expected true for expression: " + expression, ude.appliesTo(ei)); @@ -119,16 +106,12 @@ public void testEndpointInfo() { expression = TARGET_NAMESPACE + "#wsdl11.port(" + SERVICE_NAME + "/" + PORT_NAME + "wrong" + ")"; ude = new URIDomainExpression(expression); Assert.assertFalse("Expected false for expression: " + expression, ude.appliesTo(boi)); - - control.reset(); } @Test public void testBindingOperationInfo() { mockInfoObjects(); - control.replay(); - String expression = TARGET_NAMESPACE + "#wsdl11.binding(" + BINDING_NAME + ")"; URIDomainExpression ude = new URIDomainExpression(expression); Assert.assertTrue("Expected true for expression: " + expression, ude.appliesTo(boi)); @@ -145,16 +128,12 @@ public void testBindingOperationInfo() { + OPERATION_NAME + "wrong" + ")"; ude = new URIDomainExpression(expression); Assert.assertFalse("Expected false for expression: " + expression, ude.appliesTo(boi)); - - control.reset(); } @Test public void testBindingMessageInfo() { mockInfoObjects(); - control.replay(); - String expression = TARGET_NAMESPACE + "#wsdl11.message(" + MESSAGE_NAME + ")"; URIDomainExpression ude = new URIDomainExpression(expression); Assert.assertTrue("Expected true for expression: " + expression, ude.appliesTo(bmi)); @@ -163,11 +142,8 @@ public void testBindingMessageInfo() { ude = new URIDomainExpression(expression); Assert.assertFalse("Expected false for expression: " + expression, ude.appliesTo(bmi)); - control.reset(); - mockInfoObjects(); - EasyMock.expect(mi.getType()).andReturn(Type.INPUT).anyTimes(); - control.replay(); + when(mi.getType()).thenReturn(Type.INPUT); expression = TARGET_NAMESPACE + "#wsdl11.bindingOperation.input(" + BINDING_NAME + "/" + OPERATION_NAME + ")"; ude = new URIDomainExpression(expression); @@ -178,11 +154,8 @@ public void testBindingMessageInfo() { ude = new URIDomainExpression(expression); Assert.assertTrue("Expected true for expression: " + expression, ude.appliesTo(bmi)); - control.reset(); - mockInfoObjects(); - EasyMock.expect(mi.getType()).andReturn(Type.OUTPUT).anyTimes(); - control.replay(); + when(mi.getType()).thenReturn(Type.OUTPUT); expression = TARGET_NAMESPACE + "#wsdl11.bindingOperation.output(" + BINDING_NAME + "/" + OPERATION_NAME + ")"; ude = new URIDomainExpression(expression); @@ -192,16 +165,12 @@ public void testBindingMessageInfo() { + OPERATION_NAME + ")"; ude = new URIDomainExpression(expression); Assert.assertTrue("Expected true for expression: " + expression, ude.appliesTo(bmi)); - - control.reset(); } @Test public void testBindingOperationFault() { mockInfoObjects(); - control.replay(); - String expression = TARGET_NAMESPACE + "#wsdl11.bindingOperation.fault(" + BINDING_NAME + "/" + OPERATION_NAME + "/" + FAULT_NAME + ")"; URIDomainExpression ude = new URIDomainExpression(expression); @@ -216,49 +185,47 @@ public void testBindingOperationFault() { + "/" + OPERATION_NAME + "/" + FAULT_NAME + "wrong" + ")"; ude = new URIDomainExpression(expression); Assert.assertFalse("Expected false for expression: " + expression, ude.appliesTo(bfi)); - - control.reset(); } private void mockInfoObjects() { - si = control.createMock(ServiceInfo.class); - ei = control.createMock(EndpointInfo.class); - boi = control.createMock(BindingOperationInfo.class); - bmi = control.createMock(BindingMessageInfo.class); - bfi = control.createMock(BindingFaultInfo.class); + si = mock(ServiceInfo.class); + ei = mock(EndpointInfo.class); + boi = mock(BindingOperationInfo.class); + bmi = mock(BindingMessageInfo.class); + bfi = mock(BindingFaultInfo.class); - InterfaceInfo ii = control.createMock(InterfaceInfo.class); + InterfaceInfo ii = mock(InterfaceInfo.class); - EasyMock.expect(si.getTargetNamespace()).andReturn(TARGET_NAMESPACE).anyTimes(); - EasyMock.expect(si.getName()).andReturn(SERVICE_QNAME).anyTimes(); - EasyMock.expect(si.getInterface()).andReturn(ii).anyTimes(); - EasyMock.expect(ii.getName()).andReturn(INTERFACE_QNAME).anyTimes(); + when(si.getTargetNamespace()).thenReturn(TARGET_NAMESPACE); + when(si.getName()).thenReturn(SERVICE_QNAME); + when(si.getInterface()).thenReturn(ii); + when(ii.getName()).thenReturn(INTERFACE_QNAME); - EasyMock.expect(ei.getName()).andReturn(PORT_QNAME).anyTimes(); - EasyMock.expect(ei.getService()).andReturn(si).anyTimes(); + when(ei.getName()).thenReturn(PORT_QNAME); + when(ei.getService()).thenReturn(si); - BindingInfo bi = control.createMock(BindingInfo.class); - OperationInfo oi = control.createMock(OperationInfo.class); + BindingInfo bi = mock(BindingInfo.class); + OperationInfo oi = mock(OperationInfo.class); - EasyMock.expect(boi.getName()).andReturn(OPERATION_QNAME).anyTimes(); - EasyMock.expect(boi.getBinding()).andReturn(bi).anyTimes(); - EasyMock.expect(bi.getName()).andReturn(BINDING_QNAME).anyTimes(); - EasyMock.expect(boi.getOperationInfo()).andReturn(oi).anyTimes(); - EasyMock.expect(oi.getInterface()).andReturn(ii).anyTimes(); - EasyMock.expect(oi.getName()).andReturn(OPERATION_QNAME).anyTimes(); + when(boi.getName()).thenReturn(OPERATION_QNAME); + when(boi.getBinding()).thenReturn(bi); + when(bi.getName()).thenReturn(BINDING_QNAME); + when(boi.getOperationInfo()).thenReturn(oi); + when(oi.getInterface()).thenReturn(ii); + when(oi.getName()).thenReturn(OPERATION_QNAME); - mi = control.createMock(MessageInfo.class); + mi = mock(MessageInfo.class); - EasyMock.expect(bmi.getMessageInfo()).andReturn(mi).anyTimes(); - EasyMock.expect(mi.getName()).andReturn(MESSAGE_QNAME).anyTimes(); - EasyMock.expect(bmi.getBindingOperation()).andReturn(boi).anyTimes(); + when(bmi.getMessageInfo()).thenReturn(mi); + when(mi.getName()).thenReturn(MESSAGE_QNAME); + when(bmi.getBindingOperation()).thenReturn(boi); - FaultInfo fi = control.createMock(FaultInfo.class); + FaultInfo fi = mock(FaultInfo.class); - bfi = control.createMock(BindingFaultInfo.class); - EasyMock.expect(bfi.getBindingOperation()).andReturn(boi).anyTimes(); - EasyMock.expect(bfi.getFaultInfo()).andReturn(fi).anyTimes(); - EasyMock.expect(fi.getFaultName()).andReturn(FAULT_QNAME).anyTimes(); + bfi = mock(BindingFaultInfo.class); + when(bfi.getBindingOperation()).thenReturn(boi); + when(bfi.getFaultInfo()).thenReturn(fi); + when(fi.getFaultName()).thenReturn(FAULT_QNAME); } } diff --git a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/reference/ReferenceResolverTest.java b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/reference/ReferenceResolverTest.java index dfd84ff0983..e1d368aceb0 100644 --- a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/reference/ReferenceResolverTest.java +++ b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/reference/ReferenceResolverTest.java @@ -35,61 +35,50 @@ import org.apache.neethi.Constants; import org.apache.neethi.Policy; -import org.easymock.EasyMock; -import org.easymock.IMocksControl; -import org.junit.Before; import org.junit.Test; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; +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 ReferenceResolverTest { - - private IMocksControl control; - - @Before - public void setUp() { - control = EasyMock.createNiceControl(); - } - @Test public void testLocalServiceModelReferenceResolver() { - DescriptionInfo di = control.createMock(DescriptionInfo.class); - PolicyBuilder builder = control.createMock(PolicyBuilder.class); + DescriptionInfo di = mock(DescriptionInfo.class); + PolicyBuilder builder = mock(PolicyBuilder.class); LocalServiceModelReferenceResolver resolver = new LocalServiceModelReferenceResolver(di, builder); List extensions = new ArrayList<>(); - EasyMock.expect(di.getExtensors(UnknownExtensibilityElement.class)).andReturn(extensions); + when(di.getExtensors(UnknownExtensibilityElement.class)).thenReturn(extensions); - control.replay(); assertNull(resolver.resolveReference("A")); - control.verify(); - control.reset(); - UnknownExtensibilityElement extension = control.createMock(UnknownExtensibilityElement.class); + UnknownExtensibilityElement extension = mock(UnknownExtensibilityElement.class); extensions.add(extension); - EasyMock.expect(di.getExtensors(UnknownExtensibilityElement.class)).andReturn(extensions); - Element e = control.createMock(Element.class); + when(di.getExtensors(UnknownExtensibilityElement.class)).thenReturn(extensions); + Element e = mock(Element.class); QName qn = new QName(Constants.URI_POLICY_NS, Constants.ELEM_POLICY); - EasyMock.expect(extension.getElementType()).andReturn(qn).anyTimes(); - EasyMock.expect(extension.getElement()).andReturn(e).times(1); - Document ownerDocument = control.createMock(Document.class); - EasyMock.expect(e.getOwnerDocument()).andReturn(ownerDocument); - EasyMock.expect(e.getAttributeNS(PolicyConstants.WSU_NAMESPACE_URI, + when(extension.getElementType()).thenReturn(qn); + when(extension.getElement()).thenReturn(e); + Document ownerDocument = mock(Document.class); + when(e.getOwnerDocument()).thenReturn(ownerDocument); + when(e.getAttributeNS(PolicyConstants.WSU_NAMESPACE_URI, PolicyConstants.WSU_ID_ATTR_NAME)) - .andReturn("A"); - Policy p = control.createMock(Policy.class); - EasyMock.expect(builder.getPolicy(e)).andReturn(p); + .thenReturn("A"); + Policy p = mock(Policy.class); + when(builder.getPolicy(e)).thenReturn(p); - control.replay(); assertSame(p, resolver.resolveReference("A")); - control.verify(); - + verify(extension, times(1)).getElement(); } @Test @@ -107,17 +96,14 @@ private void doTestRemoteResolver(String policyNs) { URL url = ReferenceResolverTest.class.getResource("referring.wsdl"); String baseURI = url.toString(); - PolicyBuilder builder = control.createMock(PolicyBuilder.class); + PolicyBuilder builder = mock(PolicyBuilder.class); RemoteReferenceResolver resolver = new RemoteReferenceResolver(baseURI, builder); assertNull(resolver.resolveReference("referred.wsdl#PolicyB")); - Policy p = control.createMock(Policy.class); - EasyMock.expect(builder.getPolicy(EasyMock.isA(Element.class))).andReturn(p); + Policy p = mock(Policy.class); + when(builder.getPolicy(isA(Element.class))).thenReturn(p); - control.replay(); assertSame(p, resolver.resolveReference("referred.wsdl#PolicyA")); - control.verify(); - control.reset(); } } \ No newline at end of file diff --git a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/wsdl11/Wsdl11AttachmentPolicyProviderTest.java b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/wsdl11/Wsdl11AttachmentPolicyProviderTest.java index 9b71f1016a9..e5bdc11dba4 100644 --- a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/wsdl11/Wsdl11AttachmentPolicyProviderTest.java +++ b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/wsdl11/Wsdl11AttachmentPolicyProviderTest.java @@ -50,9 +50,6 @@ import org.apache.neethi.PolicyComponent; import org.apache.neethi.util.PolicyComparator; -import org.easymock.EasyMock; -import org.easymock.IMocksControl; -import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; @@ -64,6 +61,9 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; /** * @@ -76,24 +76,19 @@ public class Wsdl11AttachmentPolicyProviderTest { private static EndpointInfo[] endpoints; private Wsdl11AttachmentPolicyProvider app; private Bus bus; - private IMocksControl control = EasyMock.createNiceControl(); - @BeforeClass public static void oneTimeSetUp() throws Exception { - - IMocksControl control = EasyMock.createNiceControl(); - Bus bus = control.createMock(Bus.class); + Bus bus = mock(Bus.class); WSDLManager manager = new WSDLManagerImpl(); WSDLServiceBuilder builder = new WSDLServiceBuilder(bus); - DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class); - EasyMock.expect(bus.getExtension(DestinationFactoryManager.class)).andReturn(dfm).anyTimes(); - EasyMock.expect(dfm.getDestinationFactory(EasyMock.isA(String.class))).andReturn(null).anyTimes(); - BindingFactoryManager bfm = control.createMock(BindingFactoryManager.class); - EasyMock.expect(bus.getExtension(BindingFactoryManager.class)).andReturn(bfm).anyTimes(); - EasyMock.expect(bfm.getBindingFactory(EasyMock.isA(String.class))).andReturn(null).anyTimes(); - control.replay(); + DestinationFactoryManager dfm = mock(DestinationFactoryManager.class); + when(bus.getExtension(DestinationFactoryManager.class)).thenReturn(dfm); + when(dfm.getDestinationFactory(isA(String.class))).thenReturn(null); + BindingFactoryManager bfm = mock(BindingFactoryManager.class); + when(bus.getExtension(BindingFactoryManager.class)).thenReturn(bfm); + when(bfm.getBindingFactory(isA(String.class))).thenReturn(null); int n = 19; services = new ServiceInfo[n]; @@ -111,9 +106,6 @@ public static void oneTimeSetUp() throws Exception { endpoints[i] = services[i].getEndpoints().iterator().next(); assertNotNull(endpoints[i]); } - - control.verify(); - } @AfterClass @@ -125,10 +117,8 @@ public static void oneTimeTearDown() { @Before public void setUp() { - control = EasyMock.createNiceControl(); - bus = control.createMock(Bus.class); - bus.getExtension(ConfiguredBeanLocator.class); - EasyMock.expectLastCall().andReturn(null).anyTimes(); + bus = mock(Bus.class); + when(bus.getExtension(ConfiguredBeanLocator.class)).thenReturn(null); AssertionBuilderRegistry abr = new AssertionBuilderRegistryImpl(); abr.setIgnoreUnknownAssertions(false); @@ -139,23 +129,13 @@ public void setUp() { abr.registerBuilder(new QName("http://cxf.apache.org/test/assertions", "C"), ab); PolicyBuilderImpl pb = new PolicyBuilderImpl(); - bus.getExtension(PolicyBuilder.class); - EasyMock.expectLastCall().andReturn(pb).anyTimes(); - bus.getExtension(PolicyEngine.class); - EasyMock.expectLastCall().andReturn(null).anyTimes(); + when(bus.getExtension(PolicyBuilder.class)).thenReturn(pb); + when(bus.getExtension(PolicyEngine.class)).thenReturn(null); pb.setAssertionBuilderRegistry(abr); app = new Wsdl11AttachmentPolicyProvider(); app.setBuilder(pb); app.setRegistry(new PolicyRegistryImpl()); - control.replay(); - - } - - - @After - public void tearDown() { - control.verify(); } @Test diff --git a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/builder/jaxb/JaxbAssertionTest.java b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/builder/jaxb/JaxbAssertionTest.java index eab0efb1a61..a772449ab0e 100644 --- a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/builder/jaxb/JaxbAssertionTest.java +++ b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/builder/jaxb/JaxbAssertionTest.java @@ -33,8 +33,6 @@ import org.apache.neethi.Policy; import org.apache.neethi.PolicyComponent; -import org.easymock.EasyMock; -import org.easymock.IMocksControl; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -42,6 +40,8 @@ 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; /** * @@ -85,15 +85,12 @@ public void testEqual() { pc = new ExactlyOne(); assertFalse(assertion.equal(pc)); - IMocksControl ctrl = EasyMock.createNiceControl(); - PrimitiveAssertion xpa = ctrl.createMock(PrimitiveAssertion.class); + PrimitiveAssertion xpa = mock(PrimitiveAssertion.class); QName oqn = new QName("http://cxf.apache.org/test/assertions/blah", "OtherType"); - EasyMock.expect(xpa.getName()).andReturn(oqn); - EasyMock.expect(xpa.getType()).andReturn(Constants.TYPE_ASSERTION); + when(xpa.getName()).thenReturn(oqn); + when(xpa.getType()).thenReturn(Constants.TYPE_ASSERTION); - ctrl.replay(); assertFalse(assertion.equal(xpa)); - ctrl.verify(); FooType odata = new FooType(); odata.setName(data.getName()); diff --git a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/selector/FirstAlternativeSelectorTest.java b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/selector/FirstAlternativeSelectorTest.java index f074b2d96d4..95846c4feae 100644 --- a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/selector/FirstAlternativeSelectorTest.java +++ b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/selector/FirstAlternativeSelectorTest.java @@ -34,32 +34,24 @@ import org.apache.neethi.ExactlyOne; import org.apache.neethi.Policy; -import org.easymock.EasyMock; -import org.easymock.IMocksControl; -import org.junit.Before; import org.junit.Test; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; /** * */ public class FirstAlternativeSelectorTest { - - private IMocksControl control; - - @Before - public void setUp() { - control = EasyMock.createNiceControl(); - } @Test public void testChooseAlternative() { AlternativeSelector selector = new FirstAlternativeSelector(); - PolicyEngine engine = control.createMock(PolicyEngine.class); - Assertor assertor = control.createMock(Assertor.class); + PolicyEngine engine = mock(PolicyEngine.class); + Assertor assertor = mock(Assertor.class); Policy policy = new Policy(); ExactlyOne ea = new ExactlyOne(); @@ -72,35 +64,26 @@ public void testChooseAlternative() { policy.addPolicyComponent(ea); Message m = new MessageImpl(); - EasyMock.expect(engine.supportsAlternative(firstAlternative, assertor, m)).andReturn(false); - control.replay(); - + when(engine.supportsAlternative(firstAlternative, assertor, m)).thenReturn(false); assertNull(selector.selectAlternative(policy, engine, assertor, null, m)); - control.verify(); - control.reset(); - EasyMock.expect(engine.supportsAlternative(firstAlternative, assertor, m)).andReturn(true); - control.replay(); + when(engine.supportsAlternative(firstAlternative, assertor, m)).thenReturn(true); Collection chosen = selector.selectAlternative(policy, engine, assertor, null, m); assertSame(1, chosen.size()); assertSame(chosen.size(), firstAlternative.size()); assertSame(chosen.iterator().next(), firstAlternative.iterator().next()); - control.verify(); - control.reset(); All other = new All(); other.addAssertion(a1); ea.addPolicyComponent(other); Collection secondAlternative = CastUtils.cast(other.getPolicyComponents(), PolicyAssertion.class); - EasyMock.expect(engine.supportsAlternative(firstAlternative, assertor, m)).andReturn(false); - EasyMock.expect(engine.supportsAlternative(secondAlternative, assertor, m)).andReturn(true); - control.replay(); + when(engine.supportsAlternative(firstAlternative, assertor, m)).thenReturn(false); + when(engine.supportsAlternative(secondAlternative, assertor, m)).thenReturn(true); chosen = selector.selectAlternative(policy, engine, assertor, null, m); assertSame(1, chosen.size()); assertSame(chosen.size(), secondAlternative.size()); assertSame(chosen.iterator().next(), secondAlternative.iterator().next()); - control.verify(); } } \ No newline at end of file diff --git a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/selector/MinimalMaximalAlternativeSelectorTest.java b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/selector/MinimalMaximalAlternativeSelectorTest.java index ff2cd704474..1c442ce889c 100644 --- a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/selector/MinimalMaximalAlternativeSelectorTest.java +++ b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/selector/MinimalMaximalAlternativeSelectorTest.java @@ -34,34 +34,24 @@ import org.apache.neethi.ExactlyOne; import org.apache.neethi.Policy; -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.assertSame; - +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; /** * */ public class MinimalMaximalAlternativeSelectorTest { - - private IMocksControl control; - - @Before - public void setUp() { - control = EasyMock.createNiceControl(); - } - @Test public void testChooseMinAlternative() { Message m = new MessageImpl(); AlternativeSelector selector = new MinimalAlternativeSelector(); - PolicyEngine engine = control.createMock(PolicyEngine.class); - Assertor assertor = control.createMock(Assertor.class); + PolicyEngine engine = mock(PolicyEngine.class); + Assertor assertor = mock(Assertor.class); Policy policy = new Policy(); ExactlyOne ea = new ExactlyOne(); @@ -76,14 +66,12 @@ public void testChooseMinAlternative() { Collection minAlternative = CastUtils.cast(all.getPolicyComponents(), PolicyAssertion.class); policy.addPolicyComponent(ea); - EasyMock.expect(engine.supportsAlternative(maxAlternative, assertor, m)).andReturn(true); - EasyMock.expect(engine.supportsAlternative(minAlternative, assertor, m)).andReturn(true); + when(engine.supportsAlternative(maxAlternative, assertor, m)).thenReturn(true); + when(engine.supportsAlternative(minAlternative, assertor, m)).thenReturn(true); - control.replay(); Collection choice = selector.selectAlternative(policy, engine, assertor, null, m); assertEquals(0, choice.size()); - control.verify(); } @Test @@ -91,8 +79,8 @@ public void testChooseMaxAlternative() { Message m = new MessageImpl(); AlternativeSelector selector = new MaximalAlternativeSelector(); - PolicyEngine engine = control.createMock(PolicyEngine.class); - Assertor assertor = control.createMock(Assertor.class); + PolicyEngine engine = mock(PolicyEngine.class); + Assertor assertor = mock(Assertor.class); Policy policy = new Policy(); ExactlyOne ea = new ExactlyOne(); @@ -107,13 +95,11 @@ public void testChooseMaxAlternative() { Collection minAlternative = CastUtils.cast(all.getPolicyComponents(), PolicyAssertion.class); policy.addPolicyComponent(ea); - EasyMock.expect(engine.supportsAlternative(maxAlternative, assertor, m)).andReturn(true); - EasyMock.expect(engine.supportsAlternative(minAlternative, assertor, m)).andReturn(true); + when(engine.supportsAlternative(maxAlternative, assertor, m)).thenReturn(true); + when(engine.supportsAlternative(minAlternative, assertor, m)).thenReturn(true); - control.replay(); Collection choice = selector.selectAlternative(policy, engine, assertor, null, m); assertEquals(1, choice.size()); assertSame(a1, choice.iterator().next()); - control.verify(); } } \ No newline at end of file