### Question:
HtmlToText implements Transformer { @Override public InputStream transform(InputStream input, Charset charset) throws IOException { Preconditions.checkNotNull(input); Preconditions.checkNotNull(charset); String htmlString = CharStreams.toString(new InputStreamReader(input, charset)); String ppPlainText = Jsoup.clean(htmlString , "", Whitelist.none().addTags("br", "p"), new Document.OutputSettings().prettyPrint(true)); String plainText = Jsoup.clean(ppPlainText , "", Whitelist.none(), new Document.OutputSettings().prettyPrint(false)); String withEntities = Parser.unescapeEntities(plainText, false); return new ByteArrayInputStream(withEntities.getBytes(charset)); }  @Override InputStream transform(InputStream input, Charset charset); @Override MSEmailBodyType targetType();  }### Answer:
@Test(expected=NullPointerException.class) public void transformNullShouldThrowNPE() throws IOException { testee.transform(null, Charsets.UTF_8); }
@Test(expected=NullPointerException.class) public void transformNullCharsetShouldThrowNPE() throws IOException { testee.transform(new ByteArrayInputStream(new byte[] {0x22}), null); }
@Test public void transformSimpleString() throws IOException { ByteArrayInputStream inputStream = stringToInputStream("<html><body>simple string</body></html>"); InputStream actual = testee.transform(inputStream, Charsets.UTF_8); assertThat(actual).hasContentEqualTo(stringToInputStream("simple string")); }
@Test public void transformMultilineString() throws IOException { ByteArrayInputStream inputStream = stringToInputStream("<html><body>line one<br/>line two</body></html>"); InputStream actual = testee.transform(inputStream, Charsets.UTF_8); assertThat(actual).hasContentEqualTo(stringToInputStream("line one\r\nline two\r\n")); }
@Test public void transformStringWithEntity() throws IOException { ByteArrayInputStream inputStream = stringToInputStream("<html><body>line one<br/> &lt line two</body></html>"); InputStream actual = testee.transform(inputStream, Charsets.UTF_8); assertThat(actual).hasContentEqualTo(stringToInputStream("line one\r\n < line two\r\n")); }
@Test public void transformTruncatedString() throws IOException { String html = "<html>" + " <head>" + " <meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\">" + " </head>" + " <body bgcolor=\"#FFFFFF\" text=\"#000000\">" + " <div class=\"moz-cite-prefix\">Salut David,<br>" + " <br>" + " on a oublié un petit détail. Sur la page d'obm.org <a" + " href=\"http: " on a écrit \"starting with OBM 3, iOS5, Windows Mobile &lt; 7 and" + " Android &lt; 3 are no more supported.\"<br>" + " <br>" + " On parle d'OBM 3, pas d'OPush 3, donc:<br>" + " <ul>" + " <li>est-ce que ça veut dire qu'aussi à partir d'OPush 3 on ne" ; String text = "Salut David,\r\n \r\n" + " on a oublié un petit détail. Sur la page d'obm.org suivante on a écrit \"starting " + "with OBM 3, iOS5, Windows Mobile < 7 and Android < 3 are no more supported.\"\r\n \r\n" + " On parle d'OBM 3, pas d'OPush 3, donc:\r\n" + " est-ce que ça veut dire qu'aussi à partir d'OPush 3 on ne"; ByteArrayInputStream inputStream = stringToInputStream(html); InputStream actual = testee.transform(inputStream, Charsets.UTF_8); assertThat(actual).hasContentEqualTo(stringToInputStream(text)); }