@Test public void testTwoChildrenContinues() { final Task[] spies = new Task[2]; Interpreter interpreter = new Interpreter(null); Node one = create( spy -> { when(spy.update(anyInt())).thenReturn(Status.RUNNING, Status.SUCCESS); spies[0] = spy; }); Node two = create( spy -> { when(spy.update(anyInt())).thenReturn(Status.RUNNING); spies[1] = spy; }); SequenceNode node = new SequenceNode(); node.children().add(one); node.children().add(two); Task selector = interpreter.start(node); interpreter.tick(0); Assert.assertEquals(Status.RUNNING, selector.getStatus()); interpreter.tick(0); Assert.assertEquals(Status.RUNNING, selector.getStatus()); interpreter.tick(0); Assert.assertEquals(Status.RUNNING, selector.getStatus()); verify(spies[0]).onTerminate(Status.SUCCESS); verify(spies[1]).onInitialize(); }
@Test public void testOneChildPassThrough() { final Task[] spies = new Task[1]; Status[] stats = new Status[] {Status.SUCCESS, Status.FAILURE}; for (final Status status : stats) { Interpreter interpreter = new Interpreter(null); Node mock = create( spy -> { when(spy.update(0)).thenReturn(Status.RUNNING, status); spies[0] = spy; }); SequenceNode node = new SequenceNode(); node.children().add(mock); Task task = interpreter.start(node); interpreter.tick(0); Assert.assertEquals(Status.RUNNING, task.getStatus()); interpreter.tick(0); Assert.assertEquals(status, task.getStatus()); verify(spies[0]).onTerminate(status); } }