OfframpServiceV2 implements OfframpService { @VisibleForTesting void handleIncomingEvent(Event event) { log.debug("Received Event: {}", event); switch (event.getType()) { case REQUEST: handleRequest((Request) event); break; case CANCEL: requested = 0L; break; case COMMIT: handleCommit((Commit) event); break; default: throw new IllegalStateException("Unexpected event type: " + event); } }  @Override void run(); @Override void close(); @Override void onEvent(String event);  }
@Test public void handleIncomingRequest() throws Exception { underTest.handleIncomingEvent(new Request(10L)); assertThat(underTest.getRequested(), is(10L)); }
@Test public void handleIncomingRequestCountZero() throws Exception { underTest.handleIncomingEvent(new Request(0L)); assertThat(underTest.getRequested(), is(0L)); }
@Test public void handleIncomingCancel() throws Exception { underTest.handleIncomingEvent(new Request(10L)); underTest.handleIncomingEvent(new Cancel()); assertThat(underTest.getRequested(), is(0L)); }
@Test(expected = IllegalStateException.class) public void handleIncomingUnexpected() throws Exception { underTest.handleIncomingEvent(new Connection("")); }