Skip to content

Commit

Permalink
CXF-8861: Get rid of EasyMock in cxf-rt-ws-policy (#1315)
Browse files Browse the repository at this point in the history
  • Loading branch information
reta committed Jun 29, 2023
1 parent 1e9e61a commit a0796fa
Show file tree
Hide file tree
Showing 24 changed files with 749 additions and 1,293 deletions.
5 changes: 3 additions & 2 deletions rt/ws/policy/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${cxf.mockito.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,42 +34,33 @@
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;
import static org.junit.Assert.assertFalse;
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);
Expand All @@ -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<Assertion> alt1 = new ArrayList<>();
Expand All @@ -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
Expand Down
Loading

0 comments on commit a0796fa

Please sign in to comment.