private StatementChannelDisptacher getChannelDispatcher() { return new StatementChannelDisptacher(channels); } }
public List<Statement> chunk(@Nullable TokenQueue tokenQueue) { if (tokenQueue == null) { throw new IllegalArgumentException(); } List<Statement> statements = new ArrayList<>(); try { channelDispatcher.consume(tokenQueue, statements); return statements; } catch (Exception e) { throw new DuplicationsException("Unable to build statement from token : " + tokenQueue.peek(), e); } }
@Test(expected = IllegalStateException.class) public void shouldThrowAnException() { TokenMatcher tokenMatcher = mock(TokenMatcher.class); StatementChannel channel = StatementChannel.create(tokenMatcher); StatementChannelDisptacher dispatcher = new StatementChannelDisptacher(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), anyList())).thenReturn(true); StatementChannel channel = StatementChannel.create(tokenMatcher); StatementChannelDisptacher dispatcher = new StatementChannelDisptacher(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); }
public List<Statement> chunk(TokenQueue tokenQueue) { if (tokenQueue == null) { throw new IllegalArgumentException(); } List<Statement> statements = new ArrayList<Statement>(); try { channelDispatcher.consume(tokenQueue, statements); return statements; } catch (Exception e) { throw new DuplicationsException("Unable to build statement from token : " + tokenQueue.peek(), e); } }
private StatementChannelDisptacher getChannelDispatcher() { return new StatementChannelDisptacher(channels); } }