@Test
@SuppressWarnings("unchecked")
public void shouldPollForEvents() throws Exception {

    final Sequence gatingSequence = new Sequence();
    final SingleProducerSequencer sequencer = new SingleProducerSequencer(16,
        new BusySpinWaitStrategy());
    final EventPoller.Handler<Object> handler = new EventPoller.Handler<Object>() {
        public boolean onEvent(Object event, long sequence, boolean endOfBatch)
                                                                               throws Exception {
            return false;
        }
    };
    final Object[] data = new Object[16];
    final DataProvider<Object> provider = new DataProvider<Object>() {
        public Object get(long sequence) {
            return data[(int) sequence];
        }
    };
    final EventPoller<Object> poller = sequencer.newPoller(provider, gatingSequence);
    final Object event = new Object();
    data[0] = event;
    assertThat(poller.poll(handler), is(EventPoller.PollState.IDLE));
    // Publish Event.
    sequencer.publish(sequencer.next());
    assertThat(poller.poll(handler), is(EventPoller.PollState.GATING));
    gatingSequence.incrementAndGet();
    assertThat(poller.poll(handler), is(EventPoller.PollState.PROCESSING));
}