DescriptionFormatter { protected String format(BufferedReader input) throws IOException { this.reader = input; this.states = Collections.asLifoQueue(new LinkedList<State>()); this.tags = Collections.asLifoQueue(new LinkedList<String>()); this.currentState = State.TEXT; this.currentTag = null; this.builder = new StringBuilder().append("<p>"); this.currentLine = this.reader.readLine(); while (this.currentLine != null) { switch (this.currentState) { case CODE: handleCode(); break; case IGNORE: handleIgnore(); break; case TEXT: handleText(); break; default: break; } } this.reader.close(); return this.builder.toString(); }  String format(String input);  }
@Test public void formatTest() throws IOException { DescriptionFormatter desc = new DescriptionFormatter(); InputStream in = null; try { in = this.getClass().getClassLoader().getResourceAsStream("description.txt"); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String formattedDescription = desc.format(reader); assertThat(formattedDescription) .isEqualTo( "<p>Some text that will be included</p><p></p><p>Some text that will be included. </p><p>Some text that will be included</p><p></p><p><b>Example 1:</b> Included text</p><p><pre>\n formated\n text\n</pre>\n</p><p></p><p></p>"); } finally { Closeables.closeQuietly(in); } }