Use MastershipServiceAdapter rather than recreating adapters in each test
Change-Id: Ice275eb56e2602dfb86598a402e205225afdbf91
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) {
-
- }
}
}