DebugStream extends PrintStream { boolean subscribeToDebugBroadcast(@NotNull DebugSubscription subscription) { synchronized (debugSubscriptions) { if (!debugSubscriptions.contains(subscription)) { debugSubscriptions.add(subscription); return true; } return false; } } DebugStream(@NotNull String streamName, @NotNull PrintStream out); @Override void print(String s);  }
@Test public void testRecordMessageToBroadcast() { subscription.assertNotSameLastMessage(String.format(DebugStream.DEBUG_PREFIX, "System.out") + "Test"); subscription.assertNotSameLastMessage(String.format(DebugStream.DEBUG_PREFIX, "System.err") + "Test"); systemOut.subscribeToDebugBroadcast(subscription); systemErr.subscribeToDebugBroadcast(subscription); System.out.println("Test"); subscription.assertSameLastMessage(String.format(DebugStream.DEBUG_PREFIX, "System.out") + "Test"); System.err.println("Test"); subscription.assertSameLastMessage(String.format(DebugStream.DEBUG_PREFIX, "System.err") + "Test"); }