Use MastershipServiceAdapter rather than recreating adapters in each test
Change-Id: Ice275eb56e2602dfb86598a402e205225afdbf91
diff --git a/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockMastershipService.java b/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockMastershipService.java
index eed7b58..bc6885d 100644
--- a/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockMastershipService.java
+++ b/drivers/netconf/src/test/java/org/onosproject/drivers/netconf/MockMastershipService.java
@@ -15,17 +15,10 @@
*/
package org.onosproject.drivers.netconf;
-import java.util.Set;
-import java.util.concurrent.CompletableFuture;
-
-import org.onosproject.cluster.NodeId;
-import org.onosproject.cluster.RoleInfo;
-import org.onosproject.mastership.MastershipListener;
-import org.onosproject.mastership.MastershipService;
+import org.onosproject.mastership.MastershipServiceAdapter;
import org.onosproject.net.DeviceId;
-import org.onosproject.net.MastershipRole;
-public class MockMastershipService implements MastershipService {
+public class MockMastershipService extends MastershipServiceAdapter {
public MockMastershipService() {
}
@@ -37,52 +30,4 @@
}
return false;
}
-
- @Override
- public void addListener(MastershipListener listener) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void removeListener(MastershipListener listener) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public MastershipRole getLocalRole(DeviceId deviceId) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public CompletableFuture<MastershipRole> requestRoleFor(DeviceId deviceId) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public CompletableFuture<Void> relinquishMastership(DeviceId deviceId) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public NodeId getMasterFor(DeviceId deviceId) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public RoleInfo getNodesFor(DeviceId deviceId) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public Set<DeviceId> getDevicesOf(NodeId nodeId) {
- // TODO Auto-generated method stub
- return null;
- }
}
diff --git a/incubator/protobuf/services/nb/BUCK b/incubator/protobuf/services/nb/BUCK
index 49787ec..0a5a8d6 100644
--- a/incubator/protobuf/services/nb/BUCK
+++ b/incubator/protobuf/services/nb/BUCK
@@ -12,6 +12,11 @@
'//incubator/protobuf/api:onos-grpc-api'
]
+TEST_DEPS = [
+ '//lib:TEST',
+ '//lib:TEST_ADAPTERS',
+]
+
GRPC_DEPS = [
'//lib:GRPC_1.3',
'//incubator/grpc-dependencies:grpc-core-repkg-' + GRPC_VER,
@@ -58,6 +63,7 @@
osgi_jar_with_tests(
deps = COMPILE_DEPS,
+ test_deps = TEST_DEPS,
visibility = ['PUBLIC'],
)
diff --git a/incubator/protobuf/services/nb/src/test/java/org/onosproject/incubator/protobuf/services/nb/GrpcNbMastershipServiceTest.java b/incubator/protobuf/services/nb/src/test/java/org/onosproject/incubator/protobuf/services/nb/GrpcNbMastershipServiceTest.java
index dd7abfc..0eb590b 100644
--- a/incubator/protobuf/services/nb/src/test/java/org/onosproject/incubator/protobuf/services/nb/GrpcNbMastershipServiceTest.java
+++ b/incubator/protobuf/services/nb/src/test/java/org/onosproject/incubator/protobuf/services/nb/GrpcNbMastershipServiceTest.java
@@ -36,16 +36,14 @@
import org.onosproject.grpc.nb.mastership.MastershipServiceNb.requestRoleForSyncRequest;
import org.onosproject.incubator.protobuf.models.cluster.NodeIdProtoTranslator;
import org.onosproject.incubator.protobuf.models.net.MastershipRoleProtoTranslator;
-import org.onosproject.mastership.MastershipListener;
import org.onosproject.mastership.MastershipService;
+import org.onosproject.mastership.MastershipServiceAdapter;
import org.onosproject.net.DeviceId;
import org.onosproject.net.MastershipRole;
import java.io.IOException;
import java.util.Map;
import java.util.Optional;
-import java.util.Set;
-import java.util.concurrent.CompletableFuture;
import static org.junit.Assert.assertEquals;
@@ -192,7 +190,7 @@
assertEquals(nid3, NodeIdProtoTranslator.translate(reply.getRoleInfo().getMaster()));
}
- private class MockMastershipService implements MastershipService {
+ private class MockMastershipService extends MastershipServiceAdapter {
@Override
public MastershipRole getLocalRole(DeviceId deviceId) {
@@ -200,25 +198,11 @@
}
@Override
- public CompletableFuture<MastershipRole> requestRoleFor(DeviceId deviceId) {
- return null;
- }
-
- @Override
public MastershipRole requestRoleForSync(DeviceId deviceId) {
return mastershipMap.get(deviceId);
}
@Override
- public CompletableFuture<Void> relinquishMastership(DeviceId deviceId) {
- return null;
- }
-
- @Override
- public void relinquishMastershipSync(DeviceId deviceId) {
- }
-
- @Override
public NodeId getMasterFor(DeviceId deviceId) {
return nodeIdMap.get(deviceId);
}
@@ -228,19 +212,5 @@
return roleInfoMap.get(deviceId);
}
- @Override
- public Set<DeviceId> getDevicesOf(NodeId nodeId) {
- return null;
- }
-
- @Override
- public void addListener(MastershipListener listener) {
-
- }
-
- @Override
- public void removeListener(MastershipListener listener) {
-
- }
}
}
diff --git a/providers/lldp/src/test/java/org/onosproject/provider/lldp/impl/LldpLinkProviderTest.java b/providers/lldp/src/test/java/org/onosproject/provider/lldp/impl/LldpLinkProviderTest.java
index bad64f3..54bd151 100644
--- a/providers/lldp/src/test/java/org/onosproject/provider/lldp/impl/LldpLinkProviderTest.java
+++ b/providers/lldp/src/test/java/org/onosproject/provider/lldp/impl/LldpLinkProviderTest.java
@@ -15,15 +15,12 @@
*/
package org.onosproject.provider.lldp.impl;
-import java.nio.ByteBuffer;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.CompletableFuture;
-
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Lists;
+import com.google.common.util.concurrent.MoreExecutors;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -38,8 +35,7 @@
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.core.DefaultApplicationId;
-import org.onosproject.mastership.MastershipListener;
-import org.onosproject.mastership.MastershipService;
+import org.onosproject.mastership.MastershipServiceAdapter;
import org.onosproject.net.Annotations;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DefaultAnnotations;
@@ -71,12 +67,14 @@
import org.onosproject.net.provider.ProviderId;
import org.onosproject.provider.lldpcommon.LinkDiscovery;
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Lists;
-import com.google.common.util.concurrent.MoreExecutors;
+import java.nio.ByteBuffer;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
@@ -790,7 +788,7 @@
}
}
- private final class TestMasterShipService implements MastershipService {
+ private final class TestMasterShipService extends MastershipServiceAdapter {
@Override
public MastershipRole getLocalRole(DeviceId deviceId) {
@@ -803,31 +801,6 @@
}
@Override
- public CompletableFuture<Void> relinquishMastership(DeviceId deviceId) {
- return null;
- }
-
- @Override
- public NodeId getMasterFor(DeviceId deviceId) {
- return null;
- }
-
- @Override
- public Set<DeviceId> getDevicesOf(NodeId nodeId) {
- return null;
- }
-
- @Override
- public void addListener(MastershipListener listener) {
-
- }
-
- @Override
- public void removeListener(MastershipListener listener) {
-
- }
-
- @Override
public RoleInfo getNodesFor(DeviceId deviceId) {
return new RoleInfo(new NodeId("foo"), Collections.<NodeId>emptyList());
}