PrintStreamMessageLogger implements MessageListener { @Override public void onMessageSent(Object message) { logMessage(OUTGOING_MESSAGE, message); } PrintStreamMessageLogger(PrintStream out); @Override void onMessageSent(Object message); @Override void onProcessingStarted(Object actor, Object message); @Override void onProcessingFinished(); @Override Executor getListenedExecutor(Executor realExecutor);  }
@Test public void sending_messages_outside_an_actor_logs_only_the_message() { logger.onMessageSent("message1"); assertThat(output.toString(), containsLineWithWords("<external> ->", "message1")); }
@Test public void the_current_thread_is_logged() { logger.onMessageSent("message1"); assertThat(output.toString(), containsString(Thread.currentThread().getName())); }
@Test public void unique_id_for_each_message_is_logged() { String message = "message1"; int messageId = System.identityHashCode(message); logger.onMessageSent(message); String output = this.output.toString(); assertThat(output, containsString(Integer.toHexString(messageId))); assertThat(output).matches("(?s).* 0x[0-9a-f]{8} .*"); }
@Test public void timestamps_are_shown_as_seconds_since_start_with_microsecond_precision() { final Queue<Long> fakeNanoTime = new LinkedList<>(); fakeNanoTime.add(1000000L); fakeNanoTime.add(1234567L); PrintStreamMessageLogger logger = new PrintStreamMessageLogger(new PrintStream(output)) { @Override protected long nanoTime() { return fakeNanoTime.poll(); } }; logger.onMessageSent("message1"); assertThat(output.toString(), containsString("[ 0.000235]")); }