Remove "EasyMock" from static method calls by using static import
Change-Id: I0d5ee06406842737de53d69cd5ad6701ee48267b
diff --git a/src/test/java/net/onrc/onos/apps/proxyarp/ProxyArpManagerTest.java b/src/test/java/net/onrc/onos/apps/proxyarp/ProxyArpManagerTest.java
index ee70f32..29bb95a 100644
--- a/src/test/java/net/onrc/onos/apps/proxyarp/ProxyArpManagerTest.java
+++ b/src/test/java/net/onrc/onos/apps/proxyarp/ProxyArpManagerTest.java
@@ -1,5 +1,14 @@
package net.onrc.onos.apps.proxyarp;
+import static org.easymock.EasyMock.anyLong;
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.anyShort;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -205,44 +214,44 @@
private void makeMock() {
//Mock floodlight modules
- context = EasyMock.createMock(FloodlightModuleContext.class);
- floodligthProviderService = EasyMock.createMock(IFloodlightProviderService.class);
- configInfoService = EasyMock.createMock(IConfigInfoService.class);
- restApiService = EasyMock.createMock(IRestApiService.class);
- datagridService = EasyMock.createMock(IDatagridService.class);
- flowPusherService = EasyMock.createMock(IFlowPusherService.class);
- topologyService = EasyMock.createMock(ITopologyService.class);
- hostService = EasyMock.createMock(IHostService.class);
- packetService = EasyMock.createMock(IPacketService.class);
- eg = EasyMock.createMock(IEventChannel.class);
- el = EasyMock.createMock(IEventChannelListener.class);
+ context = createMock(FloodlightModuleContext.class);
+ floodligthProviderService = createMock(IFloodlightProviderService.class);
+ configInfoService = createMock(IConfigInfoService.class);
+ restApiService = createMock(IRestApiService.class);
+ datagridService = createMock(IDatagridService.class);
+ flowPusherService = createMock(IFlowPusherService.class);
+ topologyService = createMock(ITopologyService.class);
+ hostService = createMock(IHostService.class);
+ packetService = createMock(IPacketService.class);
+ eg = createMock(IEventChannel.class);
+ el = createMock(IEventChannelListener.class);
//Mock Topology related data
- topology = EasyMock.createMock(Topology.class);
- host1 = EasyMock.createMock(Host.class);
- inPort1 = EasyMock.createMock(Port.class);
- outPort1 = EasyMock.createMock(Port.class);
- sw1 = EasyMock.createMock(Switch.class);
+ topology = createMock(Topology.class);
+ host1 = createMock(Host.class);
+ inPort1 = createMock(Port.class);
+ outPort1 = createMock(Port.class);
+ sw1 = createMock(Switch.class);
}
private void prepareExpectForGeneral() {
- EasyMock.expect(inPort1.getNumber()).andReturn(sw1Inport).anyTimes();
- EasyMock.expect(outPort1.getNumber()).andReturn(sw1Outport).anyTimes();
- EasyMock.expect(outPort1.getOutgoingLink()).andReturn(null).anyTimes();
- EasyMock.expect(outPort1.getIncomingLink()).andReturn(null).anyTimes();
- EasyMock.expect(outPort1.getSwitch()).andReturn(sw1).anyTimes();
- EasyMock.expect(sw1.getDpid()).andReturn(sw1Dpid).anyTimes();
+ expect(inPort1.getNumber()).andReturn(sw1Inport).anyTimes();
+ expect(outPort1.getNumber()).andReturn(sw1Outport).anyTimes();
+ expect(outPort1.getOutgoingLink()).andReturn(null).anyTimes();
+ expect(outPort1.getIncomingLink()).andReturn(null).anyTimes();
+ expect(outPort1.getSwitch()).andReturn(sw1).anyTimes();
+ expect(sw1.getDpid()).andReturn(sw1Dpid).anyTimes();
}
private void prepareExpectForInit() {
- EasyMock.expect(context.getServiceImpl(IFloodlightProviderService.class)).andReturn(floodligthProviderService);
- EasyMock.expect(context.getServiceImpl(IConfigInfoService.class)).andReturn(configInfoService);
- EasyMock.expect(context.getServiceImpl(IRestApiService.class)).andReturn(restApiService);
- EasyMock.expect(context.getServiceImpl(IDatagridService.class)).andReturn(datagridService);
- EasyMock.expect(context.getServiceImpl(IFlowPusherService.class)).andReturn(flowPusherService);
- EasyMock.expect(context.getServiceImpl(ITopologyService.class)).andReturn(topologyService);
- EasyMock.expect(context.getServiceImpl(IHostService.class)).andReturn(hostService);
- EasyMock.expect(context.getServiceImpl(IPacketService.class)).andReturn(packetService);
+ expect(context.getServiceImpl(IFloodlightProviderService.class)).andReturn(floodligthProviderService);
+ expect(context.getServiceImpl(IConfigInfoService.class)).andReturn(configInfoService);
+ expect(context.getServiceImpl(IRestApiService.class)).andReturn(restApiService);
+ expect(context.getServiceImpl(IDatagridService.class)).andReturn(datagridService);
+ expect(context.getServiceImpl(IFlowPusherService.class)).andReturn(flowPusherService);
+ expect(context.getServiceImpl(ITopologyService.class)).andReturn(topologyService);
+ expect(context.getServiceImpl(IHostService.class)).andReturn(hostService);
+ expect(context.getServiceImpl(IPacketService.class)).andReturn(packetService);
}
private void prepareExpectForStartUp() {
@@ -253,22 +262,22 @@
// fail("Exception:" + e.getMessage());
// }
// PowerMock.replayAll();
- EasyMock.expect(configInfoService.getVlan()).andReturn(vlanId);
- restApiService.addRestletRoutable(EasyMock.isA(ArpWebRoutable.class));
- EasyMock.expectLastCall();
+ expect(configInfoService.getVlan()).andReturn(vlanId);
+ restApiService.addRestletRoutable(isA(ArpWebRoutable.class));
+ expectLastCall();
packetService.registerPacketListener(arpManager);
- EasyMock.expectLastCall();
- EasyMock.expect(topologyService.getTopology()).andReturn(topology);
- EasyMock.expect(datagridService.addListener(EasyMock.<String>anyObject(),
- EasyMock.isA(IEventChannelListener.class),
- (Class) EasyMock.anyObject(), (Class) EasyMock.anyObject())).andReturn(eg).anyTimes();
+ expectLastCall();
+ expect(topologyService.getTopology()).andReturn(topology);
+ expect(datagridService.addListener(EasyMock.<String>anyObject(),
+ isA(IEventChannelListener.class),
+ (Class) anyObject(), (Class) anyObject())).andReturn(eg).anyTimes();
List<ArpCacheNotification> list = new ArrayList<ArpCacheNotification>();
- EasyMock.expect(eg.getAllEntries()).andReturn(list);
+ expect(eg.getAllEntries()).andReturn(list);
}
private void prepareExpectForLearnArp() {
- eg.addEntry(EasyMock.eq(srcIp.toString()), EasyMock.isA(ArpCacheNotification.class));
- EasyMock.expectLastCall();
+ eg.addEntry(eq(srcIp.toString()), isA(ArpCacheNotification.class));
+ expectLastCall();
}
@After
@@ -279,9 +288,9 @@
@Test
public void testConfigTimeWithNoConfig() {
Map<String, String> config = new HashMap<String, String>();
- EasyMock.expect(context.getConfigParams(arpManager)).andReturn(config);
+ expect(context.getConfigParams(arpManager)).andReturn(config);
- EasyMock.replay(context, floodligthProviderService, configInfoService,
+ replay(context, floodligthProviderService, configInfoService,
restApiService, datagridService, flowPusherService,
topologyService, hostService, packetService, topology, eg,
el, host1, inPort1, sw1);
@@ -298,9 +307,9 @@
String strCleanupMsec = "bbbbb";
config.put("agingmsec", strAgingMsec);
config.put("cleanupmsec", strCleanupMsec);
- EasyMock.expect(context.getConfigParams(arpManager)).andReturn(config);
+ expect(context.getConfigParams(arpManager)).andReturn(config);
- EasyMock.replay(context, floodligthProviderService, configInfoService,
+ replay(context, floodligthProviderService, configInfoService,
restApiService, datagridService, flowPusherService,
topologyService, hostService, packetService, topology,
eg, el, host1, inPort1, sw1);
@@ -316,9 +325,9 @@
String strCleanupMsec = "10000";
configMap.put("agingmsec", strAgingMsec);
configMap.put("cleanupmsec", strCleanupMsec);
- EasyMock.expect(context.getConfigParams(arpManager)).andReturn(configMap);
+ expect(context.getConfigParams(arpManager)).andReturn(configMap);
- EasyMock.replay(context, floodligthProviderService, configInfoService,
+ replay(context, floodligthProviderService, configInfoService,
restApiService, datagridService, flowPusherService,
topologyService, hostService, packetService, topology,
eg, el, host1, inPort1, sw1);
@@ -331,9 +340,9 @@
@Test
public void testGetMacAddress() {
Map<String, String> config = new HashMap<String, String>();
- EasyMock.expect(context.getConfigParams(arpManager)).andReturn(config);
+ expect(context.getConfigParams(arpManager)).andReturn(config);
- EasyMock.replay(context, floodligthProviderService, configInfoService,
+ replay(context, floodligthProviderService, configInfoService,
restApiService, datagridService, flowPusherService,
topologyService, hostService, packetService, topology,
eg, el, host1, inPort1, sw1);
@@ -350,9 +359,9 @@
@Test
public void testGetMappings() {
Map<String, String> config = new HashMap<String, String>();
- EasyMock.expect(context.getConfigParams(arpManager)).andReturn(config);
+ expect(context.getConfigParams(arpManager)).andReturn(config);
- EasyMock.replay(context, floodligthProviderService, configInfoService,
+ replay(context, floodligthProviderService, configInfoService,
restApiService, datagridService, flowPusherService,
topologyService, hostService, packetService, topology,
eg, el, host1, inPort1, sw1);
@@ -367,9 +376,9 @@
@Test
public void testReceivePacketWithNoArpPacket() {
Map<String, String> config = new HashMap<String, String>();
- EasyMock.expect(context.getConfigParams(arpManager)).andReturn(config);
+ expect(context.getConfigParams(arpManager)).andReturn(config);
- EasyMock.replay(context, floodligthProviderService, configInfoService,
+ replay(context, floodligthProviderService, configInfoService,
restApiService, datagridService, flowPusherService,
topologyService, hostService, packetService, topology,
eg, el, host1, inPort1, sw1);
@@ -381,11 +390,11 @@
@Test
public void testReceivePacketWithOtherOpCode() {
Map<String, String> config = new HashMap<String, String>();
- EasyMock.expect(context.getConfigParams(arpManager)).andReturn(config);
+ expect(context.getConfigParams(arpManager)).andReturn(config);
prepareExpectForLearnArp();
- EasyMock.replay(context, floodligthProviderService, configInfoService,
+ replay(context, floodligthProviderService, configInfoService,
restApiService, datagridService, flowPusherService,
topologyService, hostService, packetService, topology,
eg, el, host1, inPort1, sw1);
@@ -397,17 +406,17 @@
@Test
public void testClassifyPacketToSendArpReplyNotification() {
Map<String, String> config = new HashMap<String, String>();
- EasyMock.expect(context.getConfigParams(arpManager)).andReturn(config);
+ expect(context.getConfigParams(arpManager)).andReturn(config);
prepareExpectForLearnArp();
ArpReplyNotification value =
new ArpReplyNotification(ByteBuffer.wrap(dstIp.getAddress()).getInt(), dstMac);
eg.addTransientEntry(srcMac.toLong(), value);
- EasyMock.expectLastCall();
- EasyMock.expect(context.getServiceImpl(IDatagridService.class)).andReturn(datagridService);
+ expectLastCall();
+ expect(context.getServiceImpl(IDatagridService.class)).andReturn(datagridService);
- EasyMock.replay(context, floodligthProviderService, configInfoService,
+ replay(context, floodligthProviderService, configInfoService,
restApiService, datagridService, flowPusherService,
topologyService, hostService, packetService, topology,
eg, el, host1, inPort1, sw1);
@@ -419,14 +428,14 @@
@Test
public void testClassifyPacketToHandleArpRequest() {
Map<String, String> config = new HashMap<String, String>();
- EasyMock.expect(context.getConfigParams(arpManager)).andReturn(config);
+ expect(context.getConfigParams(arpManager)).andReturn(config);
prepareExpectForLearnArp();
- EasyMock.expect(configInfoService.fromExternalNetwork(EasyMock.anyLong(), EasyMock.anyShort())).andReturn(true);
- EasyMock.expect(configInfoService.isInterfaceAddress(dstIp)).andReturn(false);
+ expect(configInfoService.fromExternalNetwork(anyLong(), anyShort())).andReturn(true);
+ expect(configInfoService.isInterfaceAddress(dstIp)).andReturn(false);
- EasyMock.replay(context, floodligthProviderService, configInfoService,
+ replay(context, floodligthProviderService, configInfoService,
restApiService, datagridService, flowPusherService,
topologyService, hostService, packetService, topology,
eg, el, host1, inPort1, sw1);
@@ -441,22 +450,22 @@
portList.add(outPort1);
Map<String, String> config = new HashMap<String, String>();
- EasyMock.expect(context.getConfigParams(arpManager)).andReturn(config);
+ expect(context.getConfigParams(arpManager)).andReturn(config);
prepareExpectForLearnArp();
- EasyMock.expect(configInfoService.fromExternalNetwork(
- EasyMock.anyLong(), EasyMock.anyShort())).andReturn(false);
+ expect(configInfoService.fromExternalNetwork(
+ anyLong(), anyShort())).andReturn(false);
topology.acquireReadLock();
- EasyMock.expectLastCall();
- EasyMock.expect(topology.getHostByMac(dstMac)).andReturn(host1);
+ expectLastCall();
+ expect(topology.getHostByMac(dstMac)).andReturn(host1);
topology.releaseReadLock();
- EasyMock.expectLastCall();
- EasyMock.expect(host1.getAttachmentPoints()).andReturn(portList);
- eg.addTransientEntry(EasyMock.anyLong(), EasyMock.anyObject());
- EasyMock.expectLastCall();
+ expectLastCall();
+ expect(host1.getAttachmentPoints()).andReturn(portList);
+ eg.addTransientEntry(anyLong(), anyObject());
+ expectLastCall();
- EasyMock.replay(context, configInfoService, restApiService, floodligthProviderService,
+ replay(context, configInfoService, restApiService, floodligthProviderService,
topologyService, datagridService, eg, topology, host1, inPort1, outPort1, sw1);
arpManager.init(context);
arpManager.startUp(context);
diff --git a/src/test/java/net/onrc/onos/core/flowprogrammer/FlowPusherTest.java b/src/test/java/net/onrc/onos/core/flowprogrammer/FlowPusherTest.java
index ab11188..d963ded 100644
--- a/src/test/java/net/onrc/onos/core/flowprogrammer/FlowPusherTest.java
+++ b/src/test/java/net/onrc/onos/core/flowprogrammer/FlowPusherTest.java
@@ -1,6 +1,16 @@
package net.onrc.onos.core.flowprogrammer;
+import static org.easymock.EasyMock.anyInt;
+import static org.easymock.EasyMock.anyLong;
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.anyShort;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -23,7 +33,6 @@
import net.onrc.onos.core.intent.IntentOperation.Operator;
import net.onrc.onos.core.util.IntegrationTest;
-import org.easymock.EasyMock;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.projectfloodlight.openflow.protocol.OFBarrierReply;
@@ -58,19 +67,19 @@
public void testAddMessage() {
beginInitMock();
- OFMessage msg = EasyMock.createMock(OFMessage.class);
- EasyMock.expect(msg.getXid()).andReturn((long) 1).anyTimes();
+ OFMessage msg = createMock(OFMessage.class);
+ expect(msg.getXid()).andReturn((long) 1).anyTimes();
//EasyMock.expect(msg.()).andReturn((short) 100).anyTimes();
- EasyMock.replay(msg);
+ replay(msg);
IOFSwitch sw = createConnectedSwitchMock(1, false);
try {
- sw.write(EasyMock.eq(msg), EasyMock.eq((FloodlightContext) null));
- EasyMock.expectLastCall().once();
- EasyMock.replay(sw);
+ sw.write(eq(msg), eq((FloodlightContext) null));
+ expectLastCall().once();
+ replay(sw);
} catch (IOException e1) {
fail("Failed in IOFSwitch#write()");
}
@@ -87,8 +96,8 @@
} catch (InterruptedException e) {
fail("Failed in Thread.sleep()");
}
- EasyMock.verify(msg);
- EasyMock.verify(sw);
+ verify(msg);
+ verify(sw);
verifyAll();
pusher.stop();
@@ -110,19 +119,19 @@
List<OFMessage> messages = new ArrayList<OFMessage>();
for (int i = 0; i < numMsg; ++i) {
- OFMessage msg = EasyMock.createMock(OFMessage.class);
- EasyMock.expect(msg.getXid()).andReturn((long) i).anyTimes();
- EasyMock.replay(msg);
+ OFMessage msg = createMock(OFMessage.class);
+ expect(msg.getXid()).andReturn((long) i).anyTimes();
+ replay(msg);
messages.add(msg);
try {
- sw.write(EasyMock.eq(msg), EasyMock.eq((FloodlightContext) null));
- EasyMock.expectLastCall().once();
+ sw.write(eq(msg), eq((FloodlightContext) null));
+ expectLastCall().once();
} catch (IOException e1) {
fail("Failed in IOFSwitch#write()");
}
}
- EasyMock.replay(sw);
+ replay(sw);
endInitMock();
initPusher(1);
@@ -139,9 +148,9 @@
}
for (OFMessage msg : messages) {
- EasyMock.verify(msg);
+ verify(msg);
}
- EasyMock.verify(sw);
+ verify(sw);
verifyAll();
pusher.stop();
@@ -164,20 +173,20 @@
List<OFMessage> messages = new ArrayList<OFMessage>();
for (int j = 0; j < numMsg; ++j) {
- OFMessage msg = EasyMock.createMock(OFMessage.class);
- EasyMock.expect(msg.getXid()).andReturn((long) j).anyTimes();
- EasyMock.replay(msg);
+ OFMessage msg = createMock(OFMessage.class);
+ expect(msg.getXid()).andReturn((long) j).anyTimes();
+ replay(msg);
messages.add(msg);
try {
- sw.write(EasyMock.eq(msg), EasyMock.eq((FloodlightContext) null));
- EasyMock.expectLastCall().once();
+ sw.write(eq(msg), eq((FloodlightContext) null));
+ expectLastCall().once();
} catch (IOException e1) {
fail("Failed in IOFWrite#write()");
}
}
swMap.put(sw, messages);
- EasyMock.replay(sw);
+ replay(sw);
}
endInitMock();
@@ -199,10 +208,10 @@
for (IOFSwitch sw : swMap.keySet()) {
for (OFMessage msg : swMap.get(sw)) {
- EasyMock.verify(msg);
+ verify(msg);
}
- EasyMock.verify(sw);
+ verify(sw);
}
verifyAll();
@@ -227,21 +236,21 @@
List<OFMessage> messages = new ArrayList<OFMessage>();
for (int j = 0; j < numMsg; ++j) {
- OFMessage msg = EasyMock.createMock(OFMessage.class);
- EasyMock.expect(msg.getXid()).andReturn((long) j).anyTimes();
+ OFMessage msg = createMock(OFMessage.class);
+ expect(msg.getXid()).andReturn((long) j).anyTimes();
- EasyMock.replay(msg);
+ replay(msg);
messages.add(msg);
try {
- sw.write(EasyMock.eq(msg), EasyMock.eq((FloodlightContext) null));
- EasyMock.expectLastCall().once();
+ sw.write(eq(msg), eq((FloodlightContext) null));
+ expectLastCall().once();
} catch (IOException e1) {
fail("Failed in IOFWrite#write()");
}
}
swMap.put(sw, messages);
- EasyMock.replay(sw);
+ replay(sw);
}
endInitMock();
@@ -262,10 +271,10 @@
for (IOFSwitch sw : swMap.keySet()) {
for (OFMessage msg : swMap.get(sw)) {
- EasyMock.verify(msg);
+ verify(msg);
}
- EasyMock.verify(sw);
+ verify(sw);
}
verifyAll();
@@ -291,34 +300,34 @@
beginInitMock();
IOFSwitch sw = createConnectedSwitchMock(1, true);
- EasyMock.expect(sw.getOFVersion()).andReturn(OFVersion.OF_10).once();
+ expect(sw.getOFVersion()).andReturn(OFVersion.OF_10).once();
List<OFMessage> messages = new ArrayList<OFMessage>();
for (int i = 0; i < numMsg; ++i) {
- OFMessage msg = EasyMock.createMock(OFMessage.class);
- EasyMock.expect(msg.getXid()).andReturn((long) 1).anyTimes();
- EasyMock.replay(msg);
+ OFMessage msg = createMock(OFMessage.class);
+ expect(msg.getXid()).andReturn((long) 1).anyTimes();
+ replay(msg);
messages.add(msg);
try {
- sw.write(EasyMock.eq(msg), EasyMock.eq((FloodlightContext) null));
- EasyMock.expectLastCall().once();
+ sw.write(eq(msg), eq((FloodlightContext) null));
+ expectLastCall().once();
} catch (IOException e1) {
fail("Failed in IOFWrite#write()");
}
}
try {
- sw.write(EasyMock.anyObject(OFBarrierRequest.class), EasyMock.eq((FloodlightContext) null));
- EasyMock.expectLastCall().once();
+ sw.write(anyObject(OFBarrierRequest.class), eq((FloodlightContext) null));
+ expectLastCall().once();
barrierTime = System.currentTimeMillis();
} catch (IOException e1) {
fail("Failed in IOFWrite#write()");
}
- EasyMock.replay(sw);
+ replay(sw);
endInitMock();
initPusher(1);
@@ -346,9 +355,9 @@
assertTrue(measuredRate < acceptableRate);
for (OFMessage msg : messages) {
- EasyMock.verify(msg);
+ verify(msg);
}
- EasyMock.verify(sw);
+ verify(sw);
verifyAll();
pusher.stop();
@@ -362,15 +371,15 @@
beginInitMock();
IOFSwitch sw = createConnectedSwitchMock(1, true);
- EasyMock.expect(sw.getOFVersion()).andReturn(OFVersion.OF_10).once();
+ expect(sw.getOFVersion()).andReturn(OFVersion.OF_10).once();
try {
- sw.write((OFMessage) EasyMock.anyObject(), EasyMock.eq((FloodlightContext) null));
- EasyMock.expectLastCall().once();
+ sw.write((OFMessage) anyObject(), eq((FloodlightContext) null));
+ expectLastCall().once();
} catch (IOException e1) {
fail("Failed in IOFWrite#write()");
}
- EasyMock.replay(sw);
+ replay(sw);
endInitMock();
initPusher(1);
@@ -414,39 +423,39 @@
beginInitMock();
- OFFlowModify fm = EasyMock.createMock(OFFlowModify.class);
+ OFFlowModify fm = createMock(OFFlowModify.class);
- OFFlowModify.Builder bld = EasyMock.createMock(OFFlowModify.Builder.class);
+ OFFlowModify.Builder bld = createMock(OFFlowModify.Builder.class);
- EasyMock.expect(bld.setIdleTimeout(EasyMock.anyInt())).andReturn(bld);
- EasyMock.expect(bld.setHardTimeout(EasyMock.anyInt())).andReturn(bld);
- EasyMock.expect(bld.setPriority(EasyMock.anyShort())).andReturn(bld);
- EasyMock.expect(bld.setBufferId(OFBufferId.NO_BUFFER)).andReturn(bld);
- EasyMock.expect(bld.setCookie(U64.of(EasyMock.anyLong()))).andReturn(bld);
- EasyMock.expect(bld.setMatch(EasyMock.anyObject(Match.class))).andReturn(bld);
- EasyMock.expect(bld.setActions((List<OFAction>) EasyMock.anyObject())).andReturn(bld);
- EasyMock.expect(bld.setOutPort(OFPort.of(EasyMock.anyInt()))).andReturn(bld).atLeastOnce();
- EasyMock.expect(bld.build()).andReturn(fm);
+ expect(bld.setIdleTimeout(anyInt())).andReturn(bld);
+ expect(bld.setHardTimeout(anyInt())).andReturn(bld);
+ expect(bld.setPriority(anyShort())).andReturn(bld);
+ expect(bld.setBufferId(OFBufferId.NO_BUFFER)).andReturn(bld);
+ expect(bld.setCookie(U64.of(anyLong()))).andReturn(bld);
+ expect(bld.setMatch(anyObject(Match.class))).andReturn(bld);
+ expect(bld.setActions((List<OFAction>) anyObject())).andReturn(bld);
+ expect(bld.setOutPort(OFPort.of(anyInt()))).andReturn(bld).atLeastOnce();
+ expect(bld.build()).andReturn(fm);
- EasyMock.expect(fm.getXid()).andReturn(XID_TO_VERIFY).anyTimes();
- EasyMock.expect(fm.getType()).andReturn(OFType.FLOW_MOD).anyTimes();
+ expect(fm.getXid()).andReturn(XID_TO_VERIFY).anyTimes();
+ expect(fm.getType()).andReturn(OFType.FLOW_MOD).anyTimes();
IOFSwitch sw = createConnectedSwitchMock(DPID_TO_VERIFY, false);
- EasyMock.expect(sw.getStringId()).andReturn("1").anyTimes();
- EasyMock.expect(sw.getOFVersion()).andReturn(OFVersion.OF_10).once();
+ expect(sw.getStringId()).andReturn("1").anyTimes();
+ expect(sw.getOFVersion()).andReturn(OFVersion.OF_10).once();
try {
- sw.write(EasyMock.anyObject(OFMessage.class), EasyMock.eq((FloodlightContext) null));
- EasyMock.expectLastCall().once();
+ sw.write(anyObject(OFMessage.class), eq((FloodlightContext) null));
+ expectLastCall().once();
} catch (IOException e1) {
fail("Failed in IOFWrite#write()");
}
- EasyMock.replay(bld, fm);
- EasyMock.replay(sw);
+ replay(bld, fm);
+ replay(sw);
endInitMock();
initPusher(1);
@@ -459,50 +468,50 @@
fail("Failed to sleep");
}
- EasyMock.verify(sw);
+ verify(sw);
verifyAll();
pusher.stop();
}
private void beginInitMock() {
- context = EasyMock.createMock(FloodlightContext.class);
- modContext = EasyMock.createMock(FloodlightModuleContext.class);
+ context = createMock(FloodlightContext.class);
+ modContext = createMock(FloodlightModuleContext.class);
// AAS: I don't think we should mock factories... the rabbit whole is too deep.
//factory10 = EasyMock.createMock(OFFactories.getFactory(OFVersion.OF_10).getClass());
- flProviderService = EasyMock.createMock(IFloodlightProviderService.class);
- threadPoolService = EasyMock.createMock(IThreadPoolService.class);
+ flProviderService = createMock(IFloodlightProviderService.class);
+ threadPoolService = createMock(IThreadPoolService.class);
- EasyMock.expect(modContext.getServiceImpl(EasyMock.eq(IThreadPoolService.class)))
+ expect(modContext.getServiceImpl(eq(IThreadPoolService.class)))
.andReturn(threadPoolService).once();
- EasyMock.expect(modContext.getServiceImpl(EasyMock.eq(IFloodlightProviderService.class)))
+ expect(modContext.getServiceImpl(eq(IFloodlightProviderService.class)))
.andReturn(flProviderService).once();
// AAS: FlowPusher doesn't call the following anymore.
- flProviderService.addOFMessageListener(EasyMock.eq(OFType.BARRIER_REPLY),
- EasyMock.anyObject(FlowPusher.class));
- EasyMock.expectLastCall().once();
+ flProviderService.addOFMessageListener(eq(OFType.BARRIER_REPLY),
+ anyObject(FlowPusher.class));
+ expectLastCall().once();
- ScheduledExecutorService executor = EasyMock.createMock(ScheduledExecutorService.class);
- EasyMock.expect(executor.schedule((Runnable) EasyMock.anyObject(), EasyMock.anyLong(),
- (TimeUnit) EasyMock.anyObject())).andReturn(null).once();
- EasyMock.replay(executor);
- EasyMock.expect(threadPoolService.getScheduledExecutor()).andReturn(executor).anyTimes();
+ ScheduledExecutorService executor = createMock(ScheduledExecutorService.class);
+ expect(executor.schedule((Runnable) anyObject(), anyLong(),
+ (TimeUnit) anyObject())).andReturn(null).once();
+ replay(executor);
+ expect(threadPoolService.getScheduledExecutor()).andReturn(executor).anyTimes();
}
private void endInitMock() {
- EasyMock.replay(threadPoolService);
- EasyMock.replay(flProviderService);
+ replay(threadPoolService);
+ replay(flProviderService);
//EasyMock.replay(factory10);
- EasyMock.replay(modContext);
- EasyMock.replay(context);
+ replay(modContext);
+ replay(context);
}
private void verifyAll() {
- EasyMock.verify(threadPoolService);
- EasyMock.verify(flProviderService);
+ verify(threadPoolService);
+ verify(flProviderService);
//EasyMock.verify(factory10);
- EasyMock.verify(modContext);
- EasyMock.verify(context);
+ verify(modContext);
+ verify(context);
}
private void initPusher(int numThread) {
@@ -512,11 +521,11 @@
}
private IOFSwitch createConnectedSwitchMock(long dpid, boolean useBarrier) {
- IOFSwitch sw = EasyMock.createMock(IOFSwitch.class);
- EasyMock.expect(sw.isConnected()).andReturn(true).anyTimes();
- EasyMock.expect(sw.getId()).andReturn(dpid).anyTimes();
+ IOFSwitch sw = createMock(IOFSwitch.class);
+ expect(sw.isConnected()).andReturn(true).anyTimes();
+ expect(sw.getId()).andReturn(dpid).anyTimes();
sw.flush();
- EasyMock.expectLastCall().anyTimes();
+ expectLastCall().anyTimes();
if (useBarrier) {
prepareBarrier(sw);
}
@@ -525,15 +534,15 @@
}
private void prepareBarrier(IOFSwitch sw) {
- OFBarrierRequest.Builder bld = EasyMock.createMock(factory10.buildBarrierRequest().getClass());
- EasyMock.expect(bld.setXid(EasyMock.anyInt())).andReturn(bld);
- EasyMock.expect(bld.getXid()).andReturn((long) 1).anyTimes();
- EasyMock.expect(bld.getType()).andReturn(OFType.BARRIER_REQUEST).anyTimes();
+ OFBarrierRequest.Builder bld = createMock(factory10.buildBarrierRequest().getClass());
+ expect(bld.setXid(anyInt())).andReturn(bld);
+ expect(bld.getXid()).andReturn((long) 1).anyTimes();
+ expect(bld.getType()).andReturn(OFType.BARRIER_REQUEST).anyTimes();
- OFBarrierRequest req = EasyMock.createMock(OFBarrierRequest.class);
- EasyMock.expect(bld.build()).andReturn(req).anyTimes();
- EasyMock.replay(bld);
- EasyMock.expect(sw.getNextTransactionId()).andReturn(1);
+ OFBarrierRequest req = createMock(OFBarrierRequest.class);
+ expect(bld.build()).andReturn(req).anyTimes();
+ replay(bld);
+ expect(sw.getNextTransactionId()).andReturn(1);
}
}
diff --git a/src/test/java/net/onrc/onos/core/flowprogrammer/FlowSynchronizerTest.java b/src/test/java/net/onrc/onos/core/flowprogrammer/FlowSynchronizerTest.java
index 112620e..654cb7a 100644
--- a/src/test/java/net/onrc/onos/core/flowprogrammer/FlowSynchronizerTest.java
+++ b/src/test/java/net/onrc/onos/core/flowprogrammer/FlowSynchronizerTest.java
@@ -1,5 +1,12 @@
package net.onrc.onos.core.flowprogrammer;
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.eq;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.getCurrentArguments;
+import static org.easymock.EasyMock.replay;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -16,7 +23,6 @@
import net.onrc.onos.core.flowprogrammer.IFlowSyncService.SyncResult;
import net.onrc.onos.core.intent.FlowEntry;
-import org.easymock.EasyMock;
import org.easymock.IAnswer;
import org.junit.After;
import org.junit.Before;
@@ -60,15 +66,15 @@
idAdded = new ArrayList<Long>();
idRemoved = new ArrayList<Long>();
- pusher = EasyMock.createMock(FlowPusher.class);
- EasyMock.expect(pusher.suspend(EasyMock.anyObject(IOFSwitch.class))).andReturn(true).anyTimes();
- EasyMock.expect(pusher.resume(EasyMock.anyObject(IOFSwitch.class))).andReturn(true).anyTimes();
- pusher.add(EasyMock.anyObject(IOFSwitch.class), EasyMock.anyObject(OFMessage.class),
- EasyMock.eq(MsgPriority.HIGH));
- EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
+ pusher = createMock(FlowPusher.class);
+ expect(pusher.suspend(anyObject(IOFSwitch.class))).andReturn(true).anyTimes();
+ expect(pusher.resume(anyObject(IOFSwitch.class))).andReturn(true).anyTimes();
+ pusher.add(anyObject(IOFSwitch.class), anyObject(OFMessage.class),
+ eq(MsgPriority.HIGH));
+ expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
- OFMessage msg = (OFMessage) EasyMock.getCurrentArguments()[1];
+ OFMessage msg = (OFMessage) getCurrentArguments()[1];
if (msg.getType().equals(OFType.FLOW_MOD)) {
OFFlowMod fm = (OFFlowMod) msg;
if (fm.getCommand() == OFFlowModCommand.DELETE_STRICT) {
@@ -78,17 +84,17 @@
return null;
}
}).anyTimes();
- pusher.pushFlowEntry(EasyMock.anyObject(IOFSwitch.class), EasyMock.anyObject(FlowEntry.class),
- EasyMock.eq(MsgPriority.HIGH));
- EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
+ pusher.pushFlowEntry(anyObject(IOFSwitch.class), anyObject(FlowEntry.class),
+ eq(MsgPriority.HIGH));
+ expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
- FlowEntry flow = (FlowEntry) EasyMock.getCurrentArguments()[1];
+ FlowEntry flow = (FlowEntry) getCurrentArguments()[1];
idAdded.add(flow.getFlowEntryId());
return null;
}
}).anyTimes();
- EasyMock.replay(pusher);
+ replay(pusher);
}
@After
@@ -216,8 +222,8 @@
* @return Mock object.
*/
private IOFSwitch createMockSwitch(long[] cookieList) {
- IOFSwitch sw = EasyMock.createMock(IOFSwitch.class);
- EasyMock.expect(sw.getId()).andReturn((long) 1).anyTimes();
+ IOFSwitch sw = createMock(IOFSwitch.class);
+ expect(sw.getId()).andReturn((long) 1).anyTimes();
List<OFStatsReply> stats = new ArrayList<OFStatsReply>();
for (long cookie : cookieList) {
@@ -225,24 +231,24 @@
}
@SuppressWarnings("unchecked")
- Future<List<OFStatsReply>> future = EasyMock.createMock(Future.class);
+ Future<List<OFStatsReply>> future = createMock(Future.class);
try {
- EasyMock.expect(future.get()).andReturn(stats).once();
+ expect(future.get()).andReturn(stats).once();
} catch (InterruptedException e1) {
fail("Failed in Future#get()");
} catch (ExecutionException e1) {
fail("Failed in Future#get()");
}
- EasyMock.replay(future);
+ replay(future);
try {
- EasyMock.expect(sw.getStatistics(EasyMock.anyObject(OFFlowStatsRequest.class)))
+ expect(sw.getStatistics(anyObject(OFFlowStatsRequest.class)))
.andReturn(future).once();
} catch (IOException e) {
fail("Failed in IOFSwitch#getStatistics()");
}
- EasyMock.replay(sw);
+ replay(sw);
return sw;
}
diff --git a/src/test/java/net/onrc/onos/core/hostmanager/HostManagerTest.java b/src/test/java/net/onrc/onos/core/hostmanager/HostManagerTest.java
index 3c4bfee..1431a24 100644
--- a/src/test/java/net/onrc/onos/core/hostmanager/HostManagerTest.java
+++ b/src/test/java/net/onrc/onos/core/hostmanager/HostManagerTest.java
@@ -6,7 +6,9 @@
import static org.easymock.EasyMock.eq;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.isA;
import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
import java.util.Date;
@@ -35,7 +37,6 @@
import net.onrc.onos.core.util.Dpid;
import net.onrc.onos.core.util.PortNumber;
-import org.easymock.EasyMock;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -227,8 +228,8 @@
Ethernet eth = (Ethernet) pkt1;
Host srcHost = hostManager.getSourceHostFromPacket(eth, sw1Dpid, sw1DevPort);
- floodlightProvider.addOFMessageListener(EasyMock.eq(OFType.PACKET_IN),
- EasyMock.isA(HostManager.class));
+ floodlightProvider.addOFMessageListener(eq(OFType.PACKET_IN),
+ isA(HostManager.class));
srcHost.setLastSeenTimestamp(lastSeenTimestamp);
assertEquals(lastSeenTimestamp, srcHost.getLastSeenTimestamp());
}
@@ -267,11 +268,11 @@
*/
@Test
public void testProcessPacketInAddNewHost() throws FloodlightModuleException {
- floodlightProvider.addOFMessageListener(EasyMock.eq(OFType.PACKET_IN),
- EasyMock.isA(HostManager.class));
- EasyMock.expectLastCall();
- floodlightProvider.publishUpdate(EasyMock.isA(IUpdate.class));
- EasyMock.expectLastCall();
+ floodlightProvider.addOFMessageListener(eq(OFType.PACKET_IN),
+ isA(HostManager.class));
+ expectLastCall();
+ floodlightProvider.publishUpdate(isA(IUpdate.class));
+ expectLastCall();
replay(floodlightProvider);
hostManager.init(modContext);
@@ -280,7 +281,7 @@
sw1, pktIn, (Ethernet) pkt1, (short) sw1DevPort);
assertEquals(Command.CONTINUE, cmd);
- EasyMock.verify(floodlightProvider);
+ verify(floodlightProvider);
}
/**
@@ -289,9 +290,9 @@
*/
@Test
public void testProcessPacketInHasLink() throws FloodlightModuleException {
- floodlightProvider.addOFMessageListener(EasyMock.eq(OFType.PACKET_IN),
- EasyMock.isA(HostManager.class));
- EasyMock.expectLastCall();
+ floodlightProvider.addOFMessageListener(eq(OFType.PACKET_IN),
+ isA(HostManager.class));
+ expectLastCall();
replay(floodlightProvider);
hostManager.init(modContext);
@@ -300,7 +301,7 @@
sw1, pktIn2, (Ethernet) pkt1, (short) sw1DevPort2);
assertEquals(Command.CONTINUE, cmd);
- EasyMock.verify(floodlightProvider);
+ verify(floodlightProvider);
}
/**
@@ -323,18 +324,18 @@
Long longmac = eth.getSourceMAC().toLong();
Host srcHost = hostManager.getSourceHostFromPacket(eth, sw1Dpid, sw1DevPort);
- floodlightProvider.addOFMessageListener(EasyMock.eq(OFType.PACKET_IN),
- EasyMock.isA(HostManager.class));
- EasyMock.expectLastCall();
- floodlightProvider.publishUpdate(EasyMock.isA(IUpdate.class));
- EasyMock.expectLastCall();
+ floodlightProvider.addOFMessageListener(eq(OFType.PACKET_IN),
+ isA(HostManager.class));
+ expectLastCall();
+ floodlightProvider.publishUpdate(isA(IUpdate.class));
+ expectLastCall();
replay(floodlightProvider);
hostManager.init(modContext);
hostManager.startUp(modContext);
hostManager.addHost(longmac, srcHost);
- EasyMock.verify(floodlightProvider);
+ verify(floodlightProvider);
}
/**
@@ -346,18 +347,18 @@
Ethernet eth = (Ethernet) pkt1;
Host srcHost = hostManager.getSourceHostFromPacket(eth, sw1Dpid, sw1DevPort);
- floodlightProvider.addOFMessageListener(EasyMock.eq(OFType.PACKET_IN),
- EasyMock.isA(HostManager.class));
- EasyMock.expectLastCall();
- floodlightProvider.publishUpdate(EasyMock.isA(IUpdate.class));
- EasyMock.expectLastCall();
+ floodlightProvider.addOFMessageListener(eq(OFType.PACKET_IN),
+ isA(HostManager.class));
+ expectLastCall();
+ floodlightProvider.publishUpdate(isA(IUpdate.class));
+ expectLastCall();
replay(floodlightProvider);
hostManager.init(modContext);
hostManager.startUp(modContext);
hostManager.deleteHost(srcHost);
- EasyMock.verify(floodlightProvider);
+ verify(floodlightProvider);
}
/**
@@ -369,18 +370,18 @@
Ethernet eth = (Ethernet) pkt1;
MACAddress mac = eth.getSourceMAC();
- floodlightProvider.addOFMessageListener(EasyMock.eq(OFType.PACKET_IN),
- EasyMock.isA(HostManager.class));
- EasyMock.expectLastCall();
- floodlightProvider.publishUpdate(EasyMock.isA(IUpdate.class));
- EasyMock.expectLastCall();
+ floodlightProvider.addOFMessageListener(eq(OFType.PACKET_IN),
+ isA(HostManager.class));
+ expectLastCall();
+ floodlightProvider.publishUpdate(isA(IUpdate.class));
+ expectLastCall();
replay(floodlightProvider);
hostManager.init(modContext);
hostManager.startUp(modContext);
hostManager.deleteHostByMac(mac);
- EasyMock.verify(floodlightProvider);
+ verify(floodlightProvider);
}
/**
diff --git a/src/test/java/net/onrc/onos/core/linkdiscovery/LinkDiscoveryManagerTest.java b/src/test/java/net/onrc/onos/core/linkdiscovery/LinkDiscoveryManagerTest.java
index 8c63293..cbbbcfc 100644
--- a/src/test/java/net/onrc/onos/core/linkdiscovery/LinkDiscoveryManagerTest.java
+++ b/src/test/java/net/onrc/onos/core/linkdiscovery/LinkDiscoveryManagerTest.java
@@ -17,9 +17,15 @@
package net.onrc.onos.core.linkdiscovery;
+import static org.easymock.EasyMock.anyLong;
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.anyShort;
+import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.createNiceMock;
import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.reportMatcher;
import static org.easymock.EasyMock.verify;
import java.io.IOException;
@@ -42,7 +48,6 @@
import net.onrc.onos.core.packet.OnosLldp;
import net.onrc.onos.core.registry.IControllerRegistryService;
-import org.easymock.EasyMock;
import org.easymock.IArgumentMatcher;
import org.junit.Before;
import org.junit.Test;
@@ -124,7 +129,7 @@
* @return anything of type OFPacketOut
*/
private static OFPacketOut matchOutPort(int outPort) {
- EasyMock.reportMatcher(new PacketOutPortMatcher(outPort));
+ reportMatcher(new PacketOutPortMatcher(outPort));
return null;
}
@@ -135,7 +140,7 @@
private IOFSwitch createMockSwitch(Long id) {
IOFSwitch mockSwitch = createNiceMock(IOFSwitch.class);
expect(mockSwitch.getId()).andReturn(id).anyTimes();
- expect(mockSwitch.portEnabled(EasyMock.anyShort())).andReturn(true).anyTimes();
+ expect(mockSwitch.portEnabled(anyShort())).andReturn(true).anyTimes();
expect(mockSwitch.getFactory()).andReturn(factory10).anyTimes();
return mockSwitch;
}
@@ -147,10 +152,10 @@
private OFPortDesc createMockPortWithState(short portNumber,
Set<OFPortState> state) {
- OFPort ofPort = EasyMock.createMock(OFPort.class);
+ OFPort ofPort = createMock(OFPort.class);
expect(ofPort.getShortPortNumber()).andReturn(portNumber).anyTimes();
- OFPortDesc ofPortDesc = EasyMock.createMock(OFPortDesc.class);
+ OFPortDesc ofPortDesc = createMock(OFPortDesc.class);
expect(ofPortDesc.getPortNo()).andReturn(ofPort).anyTimes();
expect(ofPortDesc.getHwAddr()).andReturn(
MacAddress.of(DEFAULT_MAC_ADDRESS)).anyTimes();
@@ -173,8 +178,8 @@
MockThreadPoolService tp = new MockThreadPoolService();
RestApiServer restApi = new RestApiServer();
IControllerRegistryService registry =
- EasyMock.createMock(IControllerRegistryService.class);
- expect(registry.hasControl(EasyMock.anyLong())).andReturn(true).anyTimes();
+ createMock(IControllerRegistryService.class);
+ expect(registry.hasControl(anyLong())).andReturn(true).anyTimes();
replay(registry);
cntx.addService(IControllerRegistryService.class, registry);
cntx.addService(IRestApiService.class, restApi);
@@ -414,10 +419,10 @@
expect(swTest.getPort(portNum)).andReturn(ofPortDesc).atLeastOnce();
swTest.write(matchOutPort(portNum),
- EasyMock.anyObject(FloodlightContext.class));
- EasyMock.expectLastCall().times(1);
+ anyObject(FloodlightContext.class));
+ expectLastCall().times(1);
swTest.flush();
- EasyMock.expectLastCall().once();
+ expectLastCall().once();
replay(swTest);
linkDiscovery.sendDiscoveryMessage(3L, portNum, false);
@@ -445,7 +450,7 @@
expect(sw.getPort(portNum)).andReturn(ofPortDesc).once();
sw.write(matchOutPort(portNum),
- EasyMock.anyObject(FloodlightContext.class));
+ anyObject(FloodlightContext.class));
sw.flush();
replay(sw);
@@ -544,7 +549,7 @@
ethPacket.setPayload(lldpPacket);
ethPacket.setPad(true);
- OFPacketIn pi = EasyMock.createMock(OFPacketIn.class);
+ OFPacketIn pi = createMock(OFPacketIn.class);
expect(pi.getData()).andReturn(ethPacket.serialize()).anyTimes();
replay(pi);
diff --git a/src/test/java/net/onrc/onos/core/registry/ZookeeperRegistryTest.java b/src/test/java/net/onrc/onos/core/registry/ZookeeperRegistryTest.java
index 3ac2c96..b13993b 100644
--- a/src/test/java/net/onrc/onos/core/registry/ZookeeperRegistryTest.java
+++ b/src/test/java/net/onrc/onos/core/registry/ZookeeperRegistryTest.java
@@ -28,7 +28,6 @@
import org.apache.curator.x.discovery.ServiceDiscovery;
import org.apache.curator.x.discovery.ServiceDiscoveryBuilder;
import org.apache.curator.x.discovery.ServiceInstance;
-import org.easymock.EasyMock;
import org.easymock.IAnswer;
import org.junit.After;
import org.junit.Before;
@@ -40,6 +39,17 @@
import org.powermock.modules.junit4.PowerMockRunner;
import org.projectfloodlight.openflow.util.HexString;
+import static org.easymock.EasyMock.anyBoolean;
+import static org.easymock.EasyMock.anyInt;
+import static org.easymock.EasyMock.anyLong;
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.getCurrentArguments;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
/**
* Unit test for {@link ZookeeperRegistry}.
* NOTE: {@link FloodlightTestCase} conflicts with PowerMock. If FloodLight-related methods need to be tested,
@@ -75,8 +85,8 @@
// Mock of CuratorFrameworkFactory
PowerMock.mockStatic(CuratorFrameworkFactory.class);
- EasyMock.expect(CuratorFrameworkFactory.newClient((String) EasyMock.anyObject(),
- EasyMock.anyInt(), EasyMock.anyInt(), (RetryPolicy) EasyMock.anyObject())).andReturn(client);
+ expect(CuratorFrameworkFactory.newClient((String) anyObject(),
+ anyInt(), anyInt(), (RetryPolicy) anyObject())).andReturn(client);
PowerMock.replay(CuratorFrameworkFactory.class);
FloodlightModuleContext fmc = new FloodlightModuleContext();
@@ -172,17 +182,17 @@
@Test
public void testRequestControl() throws Exception {
// Mock LeaderLatch
- LeaderLatch latch = EasyMock.createMock(LeaderLatch.class);
- latch.addListener(EasyMock.anyObject(SwitchLeaderListener.class));
- EasyMock.expectLastCall().once();
+ LeaderLatch latch = createMock(LeaderLatch.class);
+ latch.addListener(anyObject(SwitchLeaderListener.class));
+ expectLastCall().once();
latch.start();
- EasyMock.expectLastCall().once();
- EasyMock.replay(latch);
+ expectLastCall().once();
+ replay(latch);
PowerMock.expectNew(LeaderLatch.class,
- EasyMock.anyObject(CuratorFramework.class),
- EasyMock.anyObject(String.class),
- EasyMock.anyObject(String.class))
+ anyObject(CuratorFramework.class),
+ anyObject(String.class),
+ anyObject(String.class))
.andReturn(latch).once();
PowerMock.replay(LeaderLatch.class);
@@ -199,7 +209,7 @@
fail(e.getMessage());
}
- EasyMock.verify(latch);
+ verify(latch);
}
/**
@@ -212,21 +222,21 @@
@Test
public void testReleaseControl() throws Exception {
// Mock of LeaderLatch
- LeaderLatch latch = EasyMock.createMock(LeaderLatch.class);
- latch.addListener(EasyMock.anyObject(SwitchLeaderListener.class));
- EasyMock.expectLastCall().once();
+ LeaderLatch latch = createMock(LeaderLatch.class);
+ latch.addListener(anyObject(SwitchLeaderListener.class));
+ expectLastCall().once();
latch.start();
- EasyMock.expectLastCall().once();
- latch.removeListener(EasyMock.anyObject(SwitchLeaderListener.class));
- EasyMock.expectLastCall().once();
+ expectLastCall().once();
+ latch.removeListener(anyObject(SwitchLeaderListener.class));
+ expectLastCall().once();
latch.close();
- EasyMock.expectLastCall().once();
- EasyMock.replay(latch);
+ expectLastCall().once();
+ replay(latch);
PowerMock.expectNew(LeaderLatch.class,
- EasyMock.anyObject(CuratorFramework.class),
- EasyMock.anyObject(String.class),
- EasyMock.anyObject(String.class))
+ anyObject(CuratorFramework.class),
+ anyObject(String.class),
+ anyObject(String.class))
.andReturn(latch).once();
PowerMock.replay(LeaderLatch.class);
@@ -239,7 +249,7 @@
registry.requestControl(dpidToRequest, callback);
registry.releaseControl(dpidToRequest);
- EasyMock.verify(latch);
+ verify(latch);
}
/**
@@ -251,22 +261,22 @@
@Test
public void testHasControl() throws Exception {
// Mock of LeaderLatch
- LeaderLatch latch = EasyMock.createMock(LeaderLatch.class);
- latch.addListener(EasyMock.anyObject(SwitchLeaderListener.class));
- EasyMock.expectLastCall().once();
+ LeaderLatch latch = createMock(LeaderLatch.class);
+ latch.addListener(anyObject(SwitchLeaderListener.class));
+ expectLastCall().once();
latch.start();
- EasyMock.expectLastCall().once();
- EasyMock.expect(latch.hasLeadership()).andReturn(true).anyTimes();
- latch.removeListener(EasyMock.anyObject(SwitchLeaderListener.class));
- EasyMock.expectLastCall().once();
+ expectLastCall().once();
+ expect(latch.hasLeadership()).andReturn(true).anyTimes();
+ latch.removeListener(anyObject(SwitchLeaderListener.class));
+ expectLastCall().once();
latch.close();
- EasyMock.expectLastCall().once();
- EasyMock.replay(latch);
+ expectLastCall().once();
+ replay(latch);
PowerMock.expectNew(LeaderLatch.class,
- EasyMock.anyObject(CuratorFramework.class),
- EasyMock.anyObject(String.class),
- EasyMock.anyObject(String.class))
+ anyObject(CuratorFramework.class),
+ anyObject(String.class),
+ anyObject(String.class))
.andReturn(latch);
PowerMock.replay(LeaderLatch.class);
@@ -289,7 +299,7 @@
// Test after release control
assertFalse(registry.hasControl(dpidToRequest));
- EasyMock.verify(latch);
+ verify(latch);
}
/**
@@ -414,9 +424,9 @@
@SuppressWarnings({"serial", "unchecked" })
private CuratorFramework createCuratorFrameworkMock() throws Exception {
// Mock of AtomicValue
- AtomicValue<Long> atomicValue = EasyMock.createMock(AtomicValue.class);
- EasyMock.expect(atomicValue.succeeded()).andReturn(true).anyTimes();
- EasyMock.expect(atomicValue.preValue()).andAnswer(new IAnswer<Long>() {
+ AtomicValue<Long> atomicValue = createMock(AtomicValue.class);
+ expect(atomicValue.succeeded()).andReturn(true).anyTimes();
+ expect(atomicValue.preValue()).andAnswer(new IAnswer<Long>() {
private long value = 0;
@Override
@@ -425,7 +435,7 @@
return value;
}
}).anyTimes();
- EasyMock.expect(atomicValue.postValue()).andAnswer(new IAnswer<Long>() {
+ expect(atomicValue.postValue()).andAnswer(new IAnswer<Long>() {
private long value = ID_BLOCK_SIZE;
@Override
@@ -434,31 +444,31 @@
return value;
}
}).anyTimes();
- EasyMock.replay(atomicValue);
+ replay(atomicValue);
// Mock DistributedAtomicLong
- DistributedAtomicLong daLong = EasyMock.createMock(DistributedAtomicLong.class);
- EasyMock.expect(daLong.add(EasyMock.anyLong())).andReturn(atomicValue).anyTimes();
- EasyMock.replay(daLong);
+ DistributedAtomicLong daLong = createMock(DistributedAtomicLong.class);
+ expect(daLong.add(anyLong())).andReturn(atomicValue).anyTimes();
+ replay(daLong);
PowerMock.expectNew(DistributedAtomicLong.class,
new Class<?>[]{CuratorFramework.class, String.class, RetryPolicy.class},
- EasyMock.anyObject(CuratorFramework.class),
- EasyMock.anyObject(String.class),
- EasyMock.anyObject(RetryPolicy.class)).
+ anyObject(CuratorFramework.class),
+ anyObject(String.class),
+ anyObject(RetryPolicy.class)).
andReturn(daLong).anyTimes();
PowerMock.replay(DistributedAtomicLong.class);
// Mock ListenerContainer
- ListenerContainer<PathChildrenCacheListener> listenerContainer = EasyMock.createMock(ListenerContainer.class);
- listenerContainer.addListener(EasyMock.anyObject(PathChildrenCacheListener.class));
- EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
+ ListenerContainer<PathChildrenCacheListener> listenerContainer = createMock(ListenerContainer.class);
+ listenerContainer.addListener(anyObject(PathChildrenCacheListener.class));
+ expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
- pathChildrenCacheListener = (PathChildrenCacheListener) EasyMock.getCurrentArguments()[0];
+ pathChildrenCacheListener = (PathChildrenCacheListener) getCurrentArguments()[0];
return null;
}
}).once();
- EasyMock.replay(listenerContainer);
+ replay(listenerContainer);
// Mock PathChildrenCache
PathChildrenCache pathChildrenCacheMain = createPathChildrenCacheMock(
@@ -472,58 +482,58 @@
// Mock PathChildrenCache constructor
PowerMock.expectNew(PathChildrenCache.class,
- EasyMock.anyObject(CuratorFramework.class), EasyMock.anyObject(String.class), EasyMock.anyBoolean()).
+ anyObject(CuratorFramework.class), anyObject(String.class), anyBoolean()).
andReturn(pathChildrenCacheMain).once();
PowerMock.expectNew(PathChildrenCache.class,
- EasyMock.anyObject(CuratorFramework.class), EasyMock.anyObject(String.class), EasyMock.anyBoolean()).
+ anyObject(CuratorFramework.class), anyObject(String.class), anyBoolean()).
andReturn(pathChildrenCache1).once();
PowerMock.expectNew(PathChildrenCache.class,
- EasyMock.anyObject(CuratorFramework.class), EasyMock.anyObject(String.class), EasyMock.anyBoolean()).
+ anyObject(CuratorFramework.class), anyObject(String.class), anyBoolean()).
andReturn(pathChildrenCache2).anyTimes();
PowerMock.replay(PathChildrenCache.class);
// Mock ServiceCache
- ServiceCache<ControllerService> serviceCache = EasyMock.createMock(ServiceCache.class);
+ ServiceCache<ControllerService> serviceCache = createMock(ServiceCache.class);
serviceCache.start();
- EasyMock.expectLastCall().once();
- EasyMock.expect(serviceCache.getInstances()).andReturn(new ArrayList<ServiceInstance<ControllerService>>() { {
+ expectLastCall().once();
+ expect(serviceCache.getInstances()).andReturn(new ArrayList<ServiceInstance<ControllerService>>() { {
add(createServiceInstanceMock("controller1"));
add(createServiceInstanceMock("controller2"));
} }).anyTimes();
- EasyMock.replay(serviceCache);
+ replay(serviceCache);
// Mock ServiceCacheBuilder
- ServiceCacheBuilder<ControllerService> serviceCacheBuilder = EasyMock.createMock(ServiceCacheBuilder.class);
- EasyMock.expect(serviceCacheBuilder.name(EasyMock.anyObject(String.class)))
+ ServiceCacheBuilder<ControllerService> serviceCacheBuilder = createMock(ServiceCacheBuilder.class);
+ expect(serviceCacheBuilder.name(anyObject(String.class)))
.andReturn(serviceCacheBuilder).once();
- EasyMock.expect(serviceCacheBuilder.build()).andReturn(serviceCache).once();
- EasyMock.replay(serviceCacheBuilder);
+ expect(serviceCacheBuilder.build()).andReturn(serviceCache).once();
+ replay(serviceCacheBuilder);
// Mock ServiceDiscovery
- ServiceDiscovery<ControllerService> serviceDiscovery = EasyMock.createMock(ServiceDiscovery.class);
+ ServiceDiscovery<ControllerService> serviceDiscovery = createMock(ServiceDiscovery.class);
serviceDiscovery.start();
- EasyMock.expectLastCall().once();
- EasyMock.expect(serviceDiscovery.serviceCacheBuilder()).andReturn(serviceCacheBuilder).once();
- serviceDiscovery.registerService(EasyMock.anyObject(ServiceInstance.class));
- EasyMock.expectLastCall().once();
- EasyMock.replay(serviceDiscovery);
+ expectLastCall().once();
+ expect(serviceDiscovery.serviceCacheBuilder()).andReturn(serviceCacheBuilder).once();
+ serviceDiscovery.registerService(anyObject(ServiceInstance.class));
+ expectLastCall().once();
+ replay(serviceDiscovery);
// Mock CuratorFramework
- CuratorFramework mockClient = EasyMock.createMock(CuratorFramework.class);
+ CuratorFramework mockClient = createMock(CuratorFramework.class);
mockClient.start();
- EasyMock.expectLastCall().once();
- EasyMock.expect(mockClient.usingNamespace(EasyMock.anyObject(String.class))).andReturn(mockClient);
- EasyMock.replay(mockClient);
+ expectLastCall().once();
+ expect(mockClient.usingNamespace(anyObject(String.class))).andReturn(mockClient);
+ replay(mockClient);
// Mock ServiceDiscoveryBuilder
- ServiceDiscoveryBuilder<ControllerService> builder = EasyMock.createMock(ServiceDiscoveryBuilder.class);
- EasyMock.expect(builder.client(mockClient)).andReturn(builder).once();
- EasyMock.expect(builder.basePath(EasyMock.anyObject(String.class))).andReturn(builder);
- EasyMock.expect(builder.build()).andReturn(serviceDiscovery);
- EasyMock.replay(builder);
+ ServiceDiscoveryBuilder<ControllerService> builder = createMock(ServiceDiscoveryBuilder.class);
+ expect(builder.client(mockClient)).andReturn(builder).once();
+ expect(builder.basePath(anyObject(String.class))).andReturn(builder);
+ expect(builder.build()).andReturn(serviceDiscovery);
+ replay(builder);
PowerMock.mockStatic(ServiceDiscoveryBuilder.class);
- EasyMock.expect(ServiceDiscoveryBuilder.builder(ControllerService.class)).andReturn(builder).once();
+ expect(ServiceDiscoveryBuilder.builder(ControllerService.class)).andReturn(builder).once();
PowerMock.replay(ServiceDiscoveryBuilder.class);
return mockClient;
@@ -536,14 +546,14 @@
* @return Mock ServiceInstance object
*/
private ServiceInstance<ControllerService> createServiceInstanceMock(String controllerId) {
- ControllerService controllerService = EasyMock.createMock(ControllerService.class);
- EasyMock.expect(controllerService.getControllerId()).andReturn(controllerId).anyTimes();
- EasyMock.replay(controllerService);
+ ControllerService controllerService = createMock(ControllerService.class);
+ expect(controllerService.getControllerId()).andReturn(controllerId).anyTimes();
+ replay(controllerService);
@SuppressWarnings("unchecked")
- ServiceInstance<ControllerService> serviceInstance = EasyMock.createMock(ServiceInstance.class);
- EasyMock.expect(serviceInstance.getPayload()).andReturn(controllerService).anyTimes();
- EasyMock.replay(serviceInstance);
+ ServiceInstance<ControllerService> serviceInstance = createMock(ServiceInstance.class);
+ expect(serviceInstance.getPayload()).andReturn(controllerService).anyTimes();
+ replay(serviceInstance);
return serviceInstance;
}
@@ -562,23 +572,23 @@
final String[] paths,
ListenerContainer<PathChildrenCacheListener> listener)
throws Exception {
- PathChildrenCache pathChildrenCache = EasyMock.createMock(PathChildrenCache.class);
+ PathChildrenCache pathChildrenCache = createMock(PathChildrenCache.class);
- EasyMock.expect(pathChildrenCache.getListenable()).andReturn(listener).anyTimes();
+ expect(pathChildrenCache.getListenable()).andReturn(listener).anyTimes();
- pathChildrenCache.start(EasyMock.anyObject(StartMode.class));
- EasyMock.expectLastCall().anyTimes();
+ pathChildrenCache.start(anyObject(StartMode.class));
+ expectLastCall().anyTimes();
List<ChildData> childs = new ArrayList<ChildData>();
for (String path : paths) {
childs.add(createChildDataMockForCurrentData(controllerId, path));
}
- EasyMock.expect(pathChildrenCache.getCurrentData()).andReturn(childs).anyTimes();
+ expect(pathChildrenCache.getCurrentData()).andReturn(childs).anyTimes();
pathChildrenCache.rebuild();
- EasyMock.expectLastCall().anyTimes();
+ expectLastCall().anyTimes();
- EasyMock.replay(pathChildrenCache);
+ replay(pathChildrenCache);
return pathChildrenCache;
}
@@ -592,10 +602,10 @@
* @return Mock ChildData object
*/
private ChildData createChildDataMockForCurrentData(String controllerId, String path) {
- ChildData data = EasyMock.createMock(ChildData.class);
- EasyMock.expect(data.getPath()).andReturn(path + "-0").anyTimes();
- EasyMock.expect(data.getData()).andReturn(controllerId.getBytes()).anyTimes();
- EasyMock.replay(data);
+ ChildData data = createMock(ChildData.class);
+ expect(data.getPath()).andReturn(path + "-0").anyTimes();
+ expect(data.getData()).andReturn(controllerId.getBytes()).anyTimes();
+ replay(data);
return data;
}
@@ -630,16 +640,16 @@
*/
private PathChildrenCacheEvent createChildrenCacheEventMock(String controllerId, String path,
PathChildrenCacheEvent.Type type) {
- PathChildrenCacheEvent event = EasyMock.createMock(PathChildrenCacheEvent.class);
- ChildData data = EasyMock.createMock(ChildData.class);
+ PathChildrenCacheEvent event = createMock(PathChildrenCacheEvent.class);
+ ChildData data = createMock(ChildData.class);
- EasyMock.expect(data.getPath()).andReturn(path).anyTimes();
- EasyMock.expect(data.getData()).andReturn(controllerId.getBytes()).anyTimes();
- EasyMock.replay(data);
+ expect(data.getPath()).andReturn(path).anyTimes();
+ expect(data.getData()).andReturn(controllerId.getBytes()).anyTimes();
+ replay(data);
- EasyMock.expect(event.getType()).andReturn(type).anyTimes();
- EasyMock.expect(event.getData()).andReturn(data).anyTimes();
- EasyMock.replay(event);
+ expect(event.getType()).andReturn(type).anyTimes();
+ expect(event.getData()).andReturn(data).anyTimes();
+ replay(event);
return event;
}
diff --git a/src/test/java/net/onrc/onos/core/topology/TopologyManagerTest.java b/src/test/java/net/onrc/onos/core/topology/TopologyManagerTest.java
index 14a3685..2f8f377 100644
--- a/src/test/java/net/onrc/onos/core/topology/TopologyManagerTest.java
+++ b/src/test/java/net/onrc/onos/core/topology/TopologyManagerTest.java
@@ -15,7 +15,6 @@
import net.onrc.onos.core.util.SwitchPort;
import net.onrc.onos.core.util.TestUtils;
import net.onrc.onos.core.util.UnitTest;
-import org.easymock.EasyMock;
import org.junit.Before;
import org.junit.Test;
@@ -27,8 +26,10 @@
import static org.easymock.EasyMock.anyObject;
import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.createNiceMock;
import static org.easymock.EasyMock.eq;
import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.expectLastCall;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.reset;
import static org.easymock.EasyMock.verify;
@@ -92,10 +93,10 @@
@Before
public void setUp() throws Exception {
// Mock objects for testing
- datagridService = EasyMock.createNiceMock(IDatagridService.class);
- dataStoreService = EasyMock.createNiceMock(TopologyDatastore.class);
+ datagridService = createNiceMock(IDatagridService.class);
+ dataStoreService = createNiceMock(TopologyDatastore.class);
registryService = createMock(IControllerRegistryService.class);
- eventChannel = EasyMock.createNiceMock(IEventChannel.class);
+ eventChannel = createNiceMock(IEventChannel.class);
expect(datagridService.createChannel(
eq(eventChannelName),
@@ -170,7 +171,7 @@
// Replace the eventHandler to prevent the thread from starting
TestUtils.setField(theTopologyManager, "eventHandler",
- EasyMock.createNiceMock(TopologyManager.EventHandler.class));
+ createNiceMock(TopologyManager.EventHandler.class));
theTopologyManager.startup(datagridService);
// Replace the data store with a mocked object
@@ -218,7 +219,7 @@
// Mock the eventChannel functions first
eventChannel.addEntry(anyObject(byte[].class),
anyObject(TopologyEvent.class));
- EasyMock.expectLastCall().times(1, 1); // 1 event
+ expectLastCall().times(1, 1); // 1 event
replay(eventChannel);
setupTopologyManager();
@@ -242,7 +243,7 @@
public void testRemoveSwitchMastershipEvent() {
// Mock the eventChannel functions first
eventChannel.removeEntry(anyObject(byte[].class));
- EasyMock.expectLastCall().times(1, 1); // 1 event
+ expectLastCall().times(1, 1); // 1 event
replay(eventChannel);
setupTopologyManager();
@@ -267,7 +268,7 @@
// Mock the eventChannel functions first
eventChannel.addEntry(anyObject(byte[].class),
anyObject(TopologyEvent.class));
- EasyMock.expectLastCall().times(3, 3); // (1 Switch + 1 Port), 1 Port
+ expectLastCall().times(3, 3); // (1 Switch + 1 Port), 1 Port
replay(eventChannel);
setupTopologyManager();
@@ -301,7 +302,7 @@
public void testRemoveSwitchAndPortDiscoveryEvent() {
// Mock the eventChannel functions first
eventChannel.removeEntry(anyObject(byte[].class));
- EasyMock.expectLastCall().times(2, 2); // 1 Switch, 1 Port
+ expectLastCall().times(2, 2); // 1 Switch, 1 Port
replay(eventChannel);
setupTopologyManager();
@@ -334,7 +335,7 @@
// Mock the eventChannel functions first
eventChannel.addEntry(anyObject(byte[].class),
anyObject(TopologyEvent.class));
- EasyMock.expectLastCall().times(5, 5); // (2 Switch + 2 Port + 1 Link)
+ expectLastCall().times(5, 5); // (2 Switch + 2 Port + 1 Link)
replay(eventChannel);
setupTopologyManager();
@@ -374,7 +375,7 @@
public void testRemoveLinkDiscoveryEvent() {
// Mock the eventChannel functions first
eventChannel.removeEntry(anyObject(byte[].class));
- EasyMock.expectLastCall().times(1, 1); // (1 Link)
+ expectLastCall().times(1, 1); // (1 Link)
replay(eventChannel);
setupTopologyManager();
@@ -415,7 +416,7 @@
// Mock the eventChannel functions first
eventChannel.addEntry(anyObject(byte[].class),
anyObject(TopologyEvent.class));
- EasyMock.expectLastCall().times(1, 1); // 1 Host
+ expectLastCall().times(1, 1); // 1 Host
replay(eventChannel);
setupTopologyManager();
@@ -443,7 +444,7 @@
public void testRemoveHostDiscoveryEvent() {
// Mock the eventChannel functions first
eventChannel.removeEntry(anyObject(byte[].class));
- EasyMock.expectLastCall().times(1, 1); // 1 Host
+ expectLastCall().times(1, 1); // 1 Host
replay(eventChannel);
setupTopologyManager();