### Question:
TitleContainsTextRule extends AbstractRule { @Override protected void applyTo(Page page, Violations violations) { for (HtmlTitle title : page.findAllTitleTags()) { if (title.getTextContent() == null || title.getTextContent().trim().isEmpty()) { violations.add(createViolation(title, page, RULE_MESSAGE)); } } }  @Override String getName();  }### Answer:
@Test public void emptyTitleTagPresent() throws Exception { String content = "<html><head><title></title></head></html>"; Violations violations = rule.applyTo(toHtmlPage(content)); assertViolations(violations, rule, 1); }
@Test public void whitespaceOnlyTitleTagPresent() throws Exception { String content = "<html><head><title> </title></head></html>"; Violations violations = rule.applyTo(toHtmlPage(content)); assertViolations(violations, rule, 1); }
@Test public void noViolationRaisedByRule() throws Exception { String content = "<html><head><title>Hello World</title></head></html>"; Violations violations = rule.applyTo(toHtmlPage(content)); assertNoViolations(violations, rule); }