示例#1
0
 @Test
 public void shouldPushTokenAtBegining() {
   Token pushedToken = new Token("push", 1, 0);
   List<Token> pushedTokenList = new ArrayList<>();
   pushedTokenList.add(pushedToken);
   tokenQueue.pushForward(pushedTokenList);
   assertThat(tokenQueue.peek(), is(pushedToken));
   assertThat(tokenQueue.size(), is(4));
 }
  @Test(expected = IllegalStateException.class)
  public void shouldThrowAnException() {
    TokenMatcher tokenMatcher = mock(TokenMatcher.class);
    StatementChannel channel = StatementChannel.create(tokenMatcher);
    StatementChannelDisptacher dispatcher = new StatementChannelDisptacher(Arrays.asList(channel));
    TokenQueue tokenQueue = mock(TokenQueue.class);
    when(tokenQueue.peek()).thenReturn(new Token("a", 1, 0)).thenReturn(null);
    List<Statement> statements = mock(List.class);

    dispatcher.consume(tokenQueue, statements);
  }
  @Test
  public void shouldConsume() {
    TokenMatcher tokenMatcher = mock(TokenMatcher.class);
    when(tokenMatcher.matchToken(any(TokenQueue.class), anyListOf(Token.class))).thenReturn(true);
    StatementChannel channel = StatementChannel.create(tokenMatcher);
    StatementChannelDisptacher dispatcher = new StatementChannelDisptacher(Arrays.asList(channel));
    TokenQueue tokenQueue = mock(TokenQueue.class);
    when(tokenQueue.peek()).thenReturn(new Token("a", 1, 0)).thenReturn(null);
    List<Statement> statements = mock(List.class);

    assertThat(dispatcher.consume(tokenQueue, statements), is(true));
    verify(tokenQueue, times(2)).peek();
    verifyNoMoreInteractions(tokenQueue);
    verifyNoMoreInteractions(statements);
  }
示例#4
0
 @Test
 public void shouldPeekToken() {
   Token token = tokenQueue.peek();
   assertThat(token, is(new Token("a", 1, 0)));
   assertThat(tokenQueue.size(), is(3));
 }