SRADA-395: added unit test for ProcessManager#stopAll
authorVladislav Eliseev <v.eliseev@samsung.com>
Tue, 24 May 2016 13:12:15 +0000 (16:12 +0300)
committerMaria Guseva <m.guseva@samsung.com>
Thu, 30 Jun 2016 05:53:40 +0000 (14:53 +0900)
Change-Id: Ifdc00663e93f26dae77678bd2f5156f4a54b3546

org.tizen.dynamicanalyzer.cli/test/src/org/tizen/dynamicanalyzer/cli/manager/ProcessManagerTest.java

index 7d6a14c..f78823b 100644 (file)
@@ -5,6 +5,7 @@ import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.doAnswer;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
@@ -296,4 +297,49 @@ public class ProcessManagerTest {
                // check that force stop tracing was requested
                verify(mgr1).forceStopTracing();
        }
+
+       /**
+        * Check manager stops all running tracing processes.
+        */
+       @Test
+       public void stopAll() throws Exception {
+               setupManagers();
+
+               // start processes
+               pm.startTracing(args1);
+               pm.startTracing(args2);
+
+               // setup answers on stop signals that finalize corresponding tracing context
+               Answer<Boolean> finalizeContext1 = new Answer<Boolean>() {
+                       @Override
+                       public Boolean answer(InvocationOnMock invocation) throws Throwable {
+                               ctx1.finishContext(100500);
+                               when(mgr1.isFinished()).thenReturn(true);
+                               return true;
+                       }
+               }, finalizeContext2 = new Answer<Boolean>() {
+                       @Override
+                       public Boolean answer(InvocationOnMock invocation) throws Throwable {
+                               ctx2.finishContext(100500);
+                               when(mgr2.isFinished()).thenReturn(true);
+                               return true;
+                       }
+               };
+
+               // we don't know exactly which API method will be used, therefore mock both
+               doAnswer(finalizeContext1).when(mgr1).stopTracing();
+               doAnswer(finalizeContext1).when(mgr1).stopTracing(Mockito.anyLong());
+
+               doAnswer(finalizeContext2).when(mgr2).stopTracing();
+               doAnswer(finalizeContext2).when(mgr2).stopTracing(Mockito.anyLong());
+
+               // request stop
+               DAResult result = pm.stopAll();
+
+               // check results
+               assertEquals(ErrorCode.SUCCESS.getErrorNumber(), result.getErrorNumber());
+
+               assertTrue(ctx1.isFinished());
+               assertTrue(ctx2.isFinished());
+       }
 }