Improve config system shutdown
[controller.git] / opendaylight / config / config-manager / src / test / java / org / opendaylight / controller / config / manager / impl / osgi / BlankTransactionServiceTrackerTest.java
index 4d342a60ade2d1259fab1363a55dba431ec200cf..47b6d100c975de02bd5583e5f6b47aa99556bcad 100644 (file)
@@ -8,15 +8,12 @@
 
 package org.opendaylight.controller.config.manager.impl.osgi;
 
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.fail;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
-
+import com.google.common.util.concurrent.MoreExecutors;
 import java.util.Collections;
 import javax.management.ObjectName;
 import org.junit.Before;
@@ -31,7 +28,6 @@ import org.opendaylight.controller.config.spi.ModuleFactory;
 import org.osgi.framework.ServiceReference;
 
 public class BlankTransactionServiceTrackerTest {
-
     @Mock
     private BlankTransactionServiceTracker.BlankTransaction blankTx;
     private BlankTransactionServiceTracker tracker;
@@ -39,8 +35,9 @@ public class BlankTransactionServiceTrackerTest {
     @Before
     public void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
-        doReturn(new CommitStatus(Collections.<ObjectName>emptyList(), Collections.<ObjectName>emptyList(), Collections.<ObjectName>emptyList())).when(blankTx).hit();
-        tracker = new BlankTransactionServiceTracker(blankTx);
+        doReturn(new CommitStatus(Collections.<ObjectName>emptyList(), Collections.<ObjectName>emptyList(),
+                Collections.<ObjectName>emptyList())).when(blankTx).hit();
+        tracker = new BlankTransactionServiceTracker(blankTx, 10, MoreExecutors.newDirectExecutorService());
     }
 
     @Test
@@ -56,33 +53,21 @@ public class BlankTransactionServiceTrackerTest {
         IllegalArgumentException argumentException = new IllegalArgumentException();
         ValidationException validationException = ValidationException.createForSingleException(new ModuleIdentifier("m", "i"), argumentException);
         doThrow(validationException).when(blankTx).hit();
-        try {
-            tracker.addingService(getMockServiceReference());
-        } catch (Exception e) {
-            verify(blankTx, times(1)).hit();
-            assertNotNull(e.getCause());
-            assertSame(validationException, e.getCause());
-            return;
-        }
 
-        fail("Exception should have occurred for validation exception");
+        tracker.addingService(getMockServiceReference());
+        verify(blankTx, times(10)).hit();
     }
 
     @Test
     public void testConflictingException() throws Exception {
         int maxAttempts = 2;
-        tracker = new BlankTransactionServiceTracker(blankTx, maxAttempts);
+        tracker = new BlankTransactionServiceTracker(blankTx, maxAttempts, MoreExecutors.newDirectExecutorService());
 
         final ConflictingVersionException ex = new ConflictingVersionException();
         doThrow(ex).when(blankTx).hit();
-        try {
-            tracker.addingService(getMockServiceReference());
-        } catch (Exception e) {
-            verify(blankTx, times(maxAttempts)).hit();
-            return;
-        }
 
-        fail("Exception should have occurred for conflicting exception");
+        tracker.addingService(getMockServiceReference());
+        verify(blankTx, times(maxAttempts)).hit();
     }
 
     private ServiceReference<ModuleFactory> getMockServiceReference() {