### Question:
SingleTitlePerPageRule extends AbstractRule { @Override protected void applyTo(Page page, Violations violations) { List<HtmlTitle> allTitleTags = page.findAllTitleTags(); if (allTitleTags.isEmpty()) { violations.add(createViolation(null, page, RULE_MESSAGE)); } else if (allTitleTags.size() > 1) { for (HtmlTitle title : allTitleTags) { violations.add(createViolation(title, page, RULE_MESSAGE)); } } }  @Override String getName();  }### Answer:
@Test public void multipleTitlesOnPage() throws Exception { String content = "<html><head>" + " <title>First</title>" + " <title>Second</title>" + " <title>Third</title>" + "</head><body><p>text</p></body></html>"; Violations violations = rule.applyTo(toHtmlPage(content)); assertViolations(violations, rule, 3); }
@Test public void missingTitleOnPage() throws Exception { String content = "<html><head></head><body><p>text</p></body></html>"; Violations violations = rule.applyTo(toHtmlPage(content)); assertViolations(violations, rule, 1); }
@Test public void exactlyOneTitleOnPage() throws Exception { String content = "<html><head><title>Good title</title></head><body><p>text</p></body></html>"; Violations violations = rule.applyTo(toHtmlPage(content)); assertNoViolations(violations, rule); }