ConsoleImpl extends Composite implements Console { @Override public void print(@NotNull String text) { if (text.isEmpty()) { return; } MessageType messageType = MessageType.detect(text); for (String message : text.split("\n")) { if (message.isEmpty()) { continue; } MessageBuilder messageBuilder = messageBuilderProvider.get() .message(message) .type(messageType); if (DOCKER.equals(messageType) && message.startsWith(DOCKER.getPrefix() + ' ' + ERROR.getPrefix())) { messageBuilder.type(ERROR); } print(messageBuilder.build()); } } @Inject  ConsoleImpl(RunnerResources resources,
                       Provider<MessageBuilder> messageBuilderProvider,
                       WidgetFactory widgetFactory,
                       @NotNull @Assisted Runner runner); @Override void print(@NotNull String text); @Override void printInfo(@NotNull String line); @Override void printError(@NotNull String line); @Override void printWarn(@NotNull String line); @Override void scrollBottom(); @Override void clear(); @Override void changeWrapTextParam(); @Override boolean isWrapText();  }
@Test public void someMessageShouldBePrinted() throws Exception { String message = INFO.getPrefix() + SOME_TEXT; console.print(message); verify(messageBuilder).type(INFO); verify(messageBuilder).message(message); verify(console.output).add(any(HTML.class)); }
@Test public void emptyMessageShouldNotBePrinted() { console.print(""); verifyNoMoreInteractions(messageBuilderProvider); }
@Test public void dockerErrorMessageShouldBePrinted() throws Exception { String message = DOCKER.getPrefix() + ' ' + ERROR.getPrefix() + SOME_TEXT; console.print(message); verify(messageBuilder).type(DOCKER); verify(messageBuilder).type(ERROR); verify(messageBuilder).message(message); verify(console.output).add(any(HTML.class)); }
@Test public void complexMessageShouldBePrinted() throws Exception { String content = INFO.getPrefix() + SOME_TEXT; String message = content + '\n' + content; console.print(message); verify(messageBuilder, times(2)).type(INFO); verify(messageBuilder, times(2)).message(content); verify(console.output, times(2)).add(any(HTML.class)); }
@Test public void complexMessageShouldBePrinted2() throws Exception { String content = INFO.getPrefix() + SOME_TEXT; String message = content + '\n'; console.print(message); verify(messageBuilder).type(INFO); verify(messageBuilder).message(content); verify(console.output).add(any(HTML.class)); }