Migrate from YangInstanceIdentifier.EMPTY
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / entityownership / CandidateListChangeListenerTest.java
index 33fb4e3ddd0f0c135a0cecd611ca9d42c8bf3a9e..d79de61ece805f22bf41fc0b5bf46ec88e90c42c 100644 (file)
@@ -12,11 +12,16 @@ import static org.opendaylight.controller.cluster.datastore.entityownership.Enti
 import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.candidatePath;
 import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.entityOwnersWithCandidate;
 import static org.opendaylight.controller.cluster.datastore.entityownership.EntityOwnersModel.entityPath;
-import akka.testkit.JavaTestKit;
+
+import akka.testkit.javadsl.TestKit;
 import com.google.common.collect.ImmutableSet;
-import java.util.concurrent.TimeUnit;
+import java.time.Duration;
+import org.junit.Before;
 import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
 import org.opendaylight.controller.cluster.datastore.AbstractActorTest;
+import org.opendaylight.controller.cluster.datastore.Shard;
 import org.opendaylight.controller.cluster.datastore.ShardDataTree;
 import org.opendaylight.controller.cluster.datastore.entityownership.messages.CandidateAdded;
 import org.opendaylight.controller.cluster.datastore.entityownership.messages.CandidateRemoved;
@@ -26,7 +31,6 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
-import scala.concurrent.duration.FiniteDuration;
 
 /**
  * Unit tests for CandidateListChangeListener.
@@ -40,12 +44,20 @@ public class CandidateListChangeListenerTest extends AbstractActorTest {
     private static final YangInstanceIdentifier ENTITY_ID2 =
             YangInstanceIdentifier.of(QName.create("test", "2015-08-14", "entity2"));
 
-    private final ShardDataTree shardDataTree = new ShardDataTree(SchemaContextHelper.entityOwners(),
-        TreeType.OPERATIONAL);
+    private ShardDataTree shardDataTree;
+
+    @Mock
+    private Shard mockShard;
+
+    @Before
+    public void setup() {
+        MockitoAnnotations.initMocks(this);
+        shardDataTree = new ShardDataTree(mockShard, SchemaContextHelper.entityOwners(), TreeType.OPERATIONAL);
+    }
 
     @Test
     public void testOnDataTreeChanged() throws Exception {
-        JavaTestKit kit = new JavaTestKit(getSystem());
+        TestKit kit = new TestKit(getSystem());
 
         new CandidateListChangeListener(kit.getRef(), "test").init(shardDataTree);
 
@@ -59,7 +71,7 @@ public class CandidateListChangeListenerTest extends AbstractActorTest {
                 ImmutableSet.copyOf(candidateAdded.getAllCandidates()));
 
         writeNode(ENTITY_OWNERS_PATH, entityOwnersWithCandidate(ENTITY_TYPE, ENTITY_ID1, memberName1));
-        kit.expectNoMsg(FiniteDuration.create(500, TimeUnit.MILLISECONDS));
+        kit.expectNoMessage(Duration.ofMillis(500));
 
         String memberName2 = "member-2";
         writeNode(ENTITY_OWNERS_PATH, entityOwnersWithCandidate(ENTITY_TYPE, ENTITY_ID1, memberName2));
@@ -95,11 +107,12 @@ public class CandidateListChangeListenerTest extends AbstractActorTest {
                 ImmutableSet.copyOf(candidateRemoved.getRemainingCandidates()));
     }
 
-    private void writeNode(YangInstanceIdentifier path, NormalizedNode<?, ?> node) throws DataValidationFailedException {
+    private void writeNode(final YangInstanceIdentifier path, final NormalizedNode<?, ?> node)
+            throws DataValidationFailedException {
         AbstractEntityOwnershipTest.writeNode(path, node, shardDataTree);
     }
 
-    private void deleteNode(YangInstanceIdentifier path) throws DataValidationFailedException {
+    private void deleteNode(final YangInstanceIdentifier path) throws DataValidationFailedException {
         AbstractEntityOwnershipTest.deleteNode(path, shardDataTree);
     }
 }