### Question:
Cleaner { public boolean isValid(Document dirtyDocument) { Validate.notNull(dirtyDocument); Document clean = Document.createShell(dirtyDocument.baseUri()); int numDiscarded = copySafeNodes(dirtyDocument.body(), clean.body()); return numDiscarded == 0 && dirtyDocument.head().childNodes().size() == 0; } Cleaner(Whitelist whitelist); Document clean(Document dirtyDocument); boolean isValid(Document dirtyDocument); boolean isValidBodyHtml(String bodyHtml);  }### Answer:
@Test public void testIsValidDocument() { String ok = "<html><head></head><body><p>Hello</p></body><html>"; String nok = "<html><head><script>woops</script><title>Hello</title></head><body><p>Hello</p></body><html>"; Whitelist relaxed = Whitelist.relaxed(); Cleaner cleaner = new Cleaner(relaxed); Document okDoc = Jsoup.parse(ok); assertTrue(cleaner.isValid(okDoc)); assertFalse(cleaner.isValid(Jsoup.parse(nok))); assertFalse(new Cleaner(Whitelist.none()).isValid(okDoc)); }
@Test public void testScriptTagInWhiteList() { Whitelist whitelist = Whitelist.relaxed(); whitelist.addTags( "script" ); assertTrue( Jsoup.isValid("Hello<script>alert('Doh')</script>World !", whitelist ) ); }