Simplify code using Java 8 features
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / SimpleShardDataTreeCohortTest.java
index 5b218715737b6a34032aacc0beb01826e2da1444..34d36b058bbea8f35c5f5370df2ee8098e85918c 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.controller.cluster.datastore;
 import static org.junit.Assert.assertSame;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
@@ -19,7 +18,6 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
 
 import com.google.common.primitives.UnsignedLong;
 import com.google.common.util.concurrent.FutureCallback;
-import java.util.Collections;
 import java.util.Optional;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.Future;
@@ -33,7 +31,6 @@ import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
-import scala.concurrent.Promise;
 
 /**
  * Unit tests for SimpleShardDataTreeCohort.
@@ -56,18 +53,18 @@ public class SimpleShardDataTreeCohortTest extends AbstractTest {
     private SimpleShardDataTreeCohort cohort;
 
     @Before
-    public void setup() throws Exception {
+    public void setup() {
         MockitoAnnotations.initMocks(this);
 
-        doNothing().when(mockUserCohorts).commit();
+        doReturn(Optional.empty()).when(mockUserCohorts).commit();
         doReturn(Optional.empty()).when(mockUserCohorts).abort();
 
-        cohort = new SimpleShardDataTreeCohort.Normal(mockShardDataTree, mockModification, nextTransactionId(),
-            mockUserCohorts);
+        cohort = new SimpleShardDataTreeCohort(mockShardDataTree, mockModification, nextTransactionId(),
+            mockUserCohorts, Optional.empty());
     }
 
     @Test
-    public void testCanCommitSuccess() throws Exception {
+    public void testCanCommitSuccess() {
         canCommitSuccess();
     }
 
@@ -85,7 +82,7 @@ public class SimpleShardDataTreeCohortTest extends AbstractTest {
         verifyNoMoreInteractions(callback);
     }
 
-    private void testValidatationPropagates(final Exception cause) throws DataValidationFailedException {
+    private void testValidatationPropagates(final Exception cause) {
         doAnswer(invocation -> {
             invocation.getArgumentAt(0, SimpleShardDataTreeCohort.class).failedCanCommit(cause);
             return null;
@@ -100,17 +97,17 @@ public class SimpleShardDataTreeCohortTest extends AbstractTest {
     }
 
     @Test
-    public void testCanCommitWithConflictingModEx() throws DataValidationFailedException {
+    public void testCanCommitWithConflictingModEx() {
         testValidatationPropagates(new ConflictingModificationAppliedException(YangInstanceIdentifier.EMPTY, "mock"));
     }
 
     @Test
-    public void testCanCommitWithDataValidationEx() throws DataValidationFailedException {
+    public void testCanCommitWithDataValidationEx() {
         testValidatationPropagates(new DataValidationFailedException(YangInstanceIdentifier.EMPTY, "mock"));
     }
 
     @Test
-    public void testCanCommitWithIllegalArgumentEx() throws DataValidationFailedException {
+    public void testCanCommitWithIllegalArgumentEx() {
         testValidatationPropagates(new IllegalArgumentException("mock"));
     }
 
@@ -134,12 +131,13 @@ public class SimpleShardDataTreeCohortTest extends AbstractTest {
     }
 
     @Test
-    public void testPreCommitAndCommitSuccess() throws Exception {
+    public void testPreCommitAndCommitSuccess() {
         canCommitSuccess();
         final DataTreeCandidateTip candidate = preCommitSuccess();
 
         doAnswer(invocation -> {
-            invocation.getArgumentAt(0, SimpleShardDataTreeCohort.class).successfulCommit(UnsignedLong.valueOf(0));
+            invocation.getArgumentAt(0, SimpleShardDataTreeCohort.class).successfulCommit(UnsignedLong.valueOf(0),
+                () -> { });
             return null;
         }).when(mockShardDataTree).startCommit(cohort, candidate);
 
@@ -154,7 +152,7 @@ public class SimpleShardDataTreeCohortTest extends AbstractTest {
     }
 
     @Test
-    public void testPreCommitWithIllegalArgumentEx() throws Exception {
+    public void testPreCommitWithIllegalArgumentEx() {
         canCommitSuccess();
 
         final Exception cause = new IllegalArgumentException("mock");
@@ -174,7 +172,7 @@ public class SimpleShardDataTreeCohortTest extends AbstractTest {
     }
 
     @Test
-    public void testPreCommitWithReportedFailure() throws Exception {
+    public void testPreCommitWithReportedFailure() {
         canCommitSuccess();
 
         final Exception cause = new IllegalArgumentException("mock");
@@ -230,7 +228,7 @@ public class SimpleShardDataTreeCohortTest extends AbstractTest {
 
     @Test
     public void testAbort() throws Exception {
-        doReturn(true).when(mockShardDataTree).startAbort(cohort);
+        doReturn(Boolean.TRUE).when(mockShardDataTree).startAbort(cohort);
 
         abort(cohort).get();
         verify(mockShardDataTree).startAbort(cohort);
@@ -240,13 +238,10 @@ public class SimpleShardDataTreeCohortTest extends AbstractTest {
     public void testAbortWithCohorts() throws Exception {
         doReturn(true).when(mockShardDataTree).startAbort(cohort);
 
-        final Promise<Iterable<Object>> cohortFuture = akka.dispatch.Futures.promise();
-        doReturn(Optional.of(cohortFuture.future())).when(mockUserCohorts).abort();
+        doReturn(Optional.of(CompletableFuture.completedFuture(null))).when(mockUserCohorts).abort();
 
         final Future<?> abortFuture = abort(cohort);
 
-        cohortFuture.success(Collections.emptyList());
-
         abortFuture.get();
         verify(mockShardDataTree).startAbort(cohort);
     }