Migrate SnapshotManagerTest 65/93265/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 22 Oct 2020 18:51:32 +0000 (20:51 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 22 Oct 2020 18:53:22 +0000 (20:53 +0200)
Use MockitoJUnitRunner to initialize mocks, which shows we have
unneeded stubbings and that we are lacking two stubs.

Change-Id: I5a4ebde09a72bb4d2c2ba9affa524731413bd02c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-akka-raft/src/test/java/org/opendaylight/controller/cluster/raft/SnapshotManagerTest.java

index 4cdec8c..3133c5b 100644 (file)
@@ -32,9 +32,10 @@ import java.util.function.Consumer;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.ArgumentCaptor;
 import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.controller.cluster.DataPersistenceProvider;
 import org.opendaylight.controller.cluster.io.FileBackedOutputStreamFactory;
 import org.opendaylight.controller.cluster.raft.SnapshotManager.LastAppliedTermInformationReader;
@@ -48,6 +49,7 @@ import org.opendaylight.controller.cluster.raft.persisted.Snapshot;
 import org.opendaylight.controller.cluster.raft.utils.MessageCollectorActor;
 import org.slf4j.LoggerFactory;
 
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class SnapshotManagerTest extends AbstractActorTest {
 
     @Mock
@@ -79,8 +81,6 @@ public class SnapshotManagerTest extends AbstractActorTest {
 
     @Before
     public void setUp() {
-        MockitoAnnotations.initMocks(this);
-
         doReturn(false).when(mockRaftActorContext).hasFollowers();
         doReturn(mockConfigParams).when(mockRaftActorContext).getConfigParams();
         doReturn(10L).when(mockConfigParams).getSnapshotBatchCount();
@@ -287,6 +287,7 @@ public class SnapshotManagerTest extends AbstractActorTest {
         doReturn(45L).when(mockReplicatedLog).getSnapshotIndex();
         doReturn(6L).when(mockReplicatedLog).getSnapshotTerm();
         ReplicatedLogEntry replicatedLogEntry = mock(ReplicatedLogEntry.class);
+        doReturn(null).when(mockReplicatedLog).get(0);
         doReturn(replicatedLogEntry).when(mockReplicatedLog).get(9);
         doReturn(6L).when(replicatedLogEntry).getTerm();
         doReturn(9L).when(replicatedLogEntry).getIndex();
@@ -340,6 +341,7 @@ public class SnapshotManagerTest extends AbstractActorTest {
 
         long replicatedToAllIndex = 1;
         ReplicatedLogEntry replicatedLogEntry = mock(ReplicatedLogEntry.class);
+        doReturn(null).when(mockReplicatedLog).get(0);
         doReturn(replicatedLogEntry).when(mockReplicatedLog).get(replicatedToAllIndex);
         doReturn(6L).when(replicatedLogEntry).getTerm();
         doReturn(replicatedToAllIndex).when(replicatedLogEntry).getIndex();
@@ -569,11 +571,6 @@ public class SnapshotManagerTest extends AbstractActorTest {
     public void testTrimLogWhenLastAppliedNotSet() {
         doReturn(-1L).when(mockRaftActorContext).getLastApplied();
 
-        ReplicatedLogEntry replicatedLogEntry = mock(ReplicatedLogEntry.class);
-        doReturn(true).when(mockReplicatedLog).isPresent(10);
-        doReturn(replicatedLogEntry).when(mockReplicatedLog).get(10);
-        doReturn(5L).when(replicatedLogEntry).getTerm();
-
         long retIndex = snapshotManager.trimLog(10);
         assertEquals("return index", -1L, retIndex);
 
@@ -587,11 +584,6 @@ public class SnapshotManagerTest extends AbstractActorTest {
     public void testTrimLogWhenLastAppliedZero() {
         doReturn(0L).when(mockRaftActorContext).getLastApplied();
 
-        ReplicatedLogEntry replicatedLogEntry = mock(ReplicatedLogEntry.class);
-        doReturn(true).when(mockReplicatedLog).isPresent(10);
-        doReturn(replicatedLogEntry).when(mockReplicatedLog).get(10);
-        doReturn(5L).when(replicatedLogEntry).getTerm();
-
         long retIndex = snapshotManager.trimLog(10);
         assertEquals("return index", -1L, retIndex);
 
@@ -626,12 +618,6 @@ public class SnapshotManagerTest extends AbstractActorTest {
 
         assertEquals(true, snapshotManager.isCapturing());
 
-        ReplicatedLogEntry replicatedLogEntry = mock(ReplicatedLogEntry.class);
-        doReturn(20L).when(mockRaftActorContext).getLastApplied();
-        doReturn(true).when(mockReplicatedLog).isPresent(10);
-        doReturn(replicatedLogEntry).when(mockReplicatedLog).get(10);
-        doReturn(5L).when(replicatedLogEntry).getTerm();
-
         snapshotManager.trimLog(10);
 
         verify(mockReplicatedLog, never()).snapshotPreCommit(anyLong(), anyLong());
@@ -647,12 +633,6 @@ public class SnapshotManagerTest extends AbstractActorTest {
 
         assertEquals(true, snapshotManager.isCapturing());
 
-        ReplicatedLogEntry replicatedLogEntry = mock(ReplicatedLogEntry.class);
-        doReturn(20L).when(mockRaftActorContext).getLastApplied();
-        doReturn(true).when(mockReplicatedLog).isPresent(10);
-        doReturn(replicatedLogEntry).when(mockReplicatedLog).get(10);
-        doReturn(5L).when(replicatedLogEntry).getTerm();
-
         snapshotManager.trimLog(10);
 
         verify(mockReplicatedLog, never()).snapshotPreCommit(10, 5);

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.