AnyTokenExpression extends NativeExpression implements Matcher { @Override public void execute(Machine machine) { if (machine.length() == 0) { machine.backtrack(); } else { machine.createLeafNode(this, 1); machine.jump(1); } } private  AnyTokenExpression(); @Override void execute(Machine machine); @Override String toString(); static final AnyTokenExpression INSTANCE; }
@Test public void should_match() { Token token = mock(Token.class); when(machine.length()).thenReturn(1); when(machine.tokenAt(0)).thenReturn(token); expression.execute(machine); InOrder inOrder = Mockito.inOrder(machine); inOrder.verify(machine).length(); inOrder.verify(machine).createLeafNode(expression, 1); inOrder.verify(machine).jump(1); verifyNoMoreInteractions(machine); }
@Test public void should_backtrack() { when(machine.length()).thenReturn(0); expression.execute(machine); InOrder inOrder = Mockito.inOrder(machine); inOrder.verify(machine).length(); inOrder.verify(machine).backtrack(); verifyNoMoreInteractions(machine); }