### Question:
InitialMessageTimeout implements MessageSender<T> { public void timedOut() { State prev; do { prev = state.get(); if (prev != State.NO_MESSAGES_YET) { return; } } while (!state.compareAndSet(prev, State.TIMED_OUT)); copy(timeoutMessages, target); } InitialMessageTimeout(MessageSender<T> target, MessageReceiver<T> timeoutMessages, long timeout, TimeUnit unit); @Override void send(T message); void timedOut();  }### Answer:
@Test public void if_the_first_event_happens_before_timeout_then_forwards_all_messages_to_the_target_listener() { MessageReceiver<Event<DummyListener>> timeoutMessages = onBar123(); InitialMessageTimeout<Event<DummyListener>> timeout = new InitialMessageTimeout<>(target, timeoutMessages, NEVER, TimeUnit.MILLISECONDS); sendTo(timeout).onFoo(1); timeout.timedOut(); sendTo(timeout).onFoo(2); sendTo(timeout).onFoo(3); expect.onFoo(1); expect.onFoo(2); expect.onFoo(3); verifyExpected(target); }
@Test public void if_times_out_before_initial_message_then_sends_timeout_messages_and_drops_all_future_messages() { MessageReceiver<Event<DummyListener>> timeoutMessages = onBar123(); InitialMessageTimeout<Event<DummyListener>> timeout = new InitialMessageTimeout<>(target, timeoutMessages, NEVER, TimeUnit.MILLISECONDS); timeout.timedOut(); sendTo(timeout).onFoo(1); sendTo(timeout).onFoo(2); sendTo(timeout).onFoo(3); expect.onBar(1); expect.onBar(2); expect.onBar(3); verifyExpected(target); }