MessageBuilder { @NotNull public SafeHtml build() { SafeHtmlBuilder builder = new SafeHtmlBuilder().appendHtmlConstant("<pre style='margin:0px;'>"); StringBuilder prefixes = new StringBuilder(); for (Iterator<MessageType> iterator = types.iterator(); iterator.hasNext(); ) { MessageType type = iterator.next(); if (UNDEFINED.equals(type)) { builder.append(SimpleHtmlSanitizer.sanitizeHtml(message)); } else { String prefix = type.getPrefix(); builder.appendHtmlConstant("[<span style='color:" + type.getColor() + ";'>") .appendHtmlConstant("<b>" + prefix.replaceAll("[\\[\\]]", "") + "</b></span>]"); prefixes.append(prefix); if (iterator.hasNext()) { prefixes.append(' '); } } } if (prefixes.length() != 0) { builder.append(SimpleHtmlSanitizer.sanitizeHtml(message.substring(prefixes.length()))); } return builder.appendHtmlConstant("</pre>") .toSafeHtml(); } @Inject  MessageBuilder(); @NotNull MessageBuilder type(@NotNull MessageType type); @NotNull MessageBuilder message(@NotNull String message); @NotNull SafeHtml build();  }
@Test public void messageWithoutTypeAndContentShouldBeGenerated() throws Exception { String content = new MessageBuilder().build() .asString(); assertThat(content, equalTo(getContentByPath(getClass(), "MessageWithoutTypeAndContent.txt"))); }