示例#1
0
 @Test
 public void testShutdownHook() {
   ArgumentCaptor<Thread> shutdownHookCaptor = ArgumentCaptor.forClass(Thread.class);
   DataCollectorMain main = new TMain();
   Assert.assertEquals(0, main.doMain());
   Mockito.verify(runtime, Mockito.times(1)).addShutdownHook(shutdownHookCaptor.capture());
   Mockito.reset(task);
   shutdownHookCaptor.getValue().run();
   Mockito.verify(task, Mockito.times(1)).stop();
 }
示例#2
0
 @Test
 public void testRunException() {
   Mockito.doThrow(new RuntimeException()).when(task).run();
   DataCollectorMain main = new TMain();
   Assert.assertEquals(1, main.doMain());
   Mockito.verify(logConfigurator, Mockito.times(1)).configure();
   Mockito.verify(buildInfo, Mockito.times(1)).log(Mockito.any(Logger.class));
   Mockito.verify(runtimeInfo, Mockito.times(1)).log(Mockito.any(Logger.class));
   Mockito.verify(task, Mockito.times(1)).init();
   Mockito.verify(runtime, Mockito.times(1)).addShutdownHook(Mockito.any(Thread.class));
   Mockito.verify(task, Mockito.times(1)).run();
   Mockito.verify(runtime, Mockito.times(0)).removeShutdownHook(Mockito.any(Thread.class));
 }
示例#3
0
 @Test
 public void testOKFullRun() {
   DataCollectorMain main = new TMain();
   Mockito.verifyZeroInteractions(runtime);
   Mockito.verifyZeroInteractions(logConfigurator);
   Mockito.verifyZeroInteractions(buildInfo);
   Mockito.verifyZeroInteractions(runtimeInfo);
   Mockito.verifyZeroInteractions(task);
   Assert.assertEquals(0, main.doMain());
   Mockito.verify(logConfigurator, Mockito.times(1)).configure();
   Mockito.verify(buildInfo, Mockito.times(1)).log(Mockito.any(Logger.class));
   Mockito.verify(runtimeInfo, Mockito.times(1)).log(Mockito.any(Logger.class));
   Mockito.verify(task, Mockito.times(1)).init();
   Mockito.verify(runtime, Mockito.times(1)).addShutdownHook(Mockito.any(Thread.class));
   Mockito.verify(task, Mockito.times(1)).run();
   Mockito.verify(runtime, Mockito.times(1)).removeShutdownHook(Mockito.any(Thread.class));
 }