### Question:
DefinitionListContainsItemsRule extends AbstractRule { @Override protected void applyTo(Page page, Violations violations) { for (HtmlDefinitionList definitionList : page.findAllDefinitionLists()) { if (!containsDefinitionTermsOrDescription(definitionList)) { violations.add(createViolation(definitionList, page, RULE_MESSAGE)); } } }  @Override String getName();  }### Answer:
@Test public void emptyDefinitionListPresent() throws Exception { String content = "<html><body><dl></dl></body></html>"; Violations violations = rule.applyTo(toHtmlPage(content)); assertViolations(violations, rule, 1); }
@Test public void selfClosingDefinitionListPresent() throws Exception { String content = "<html><body><dl /></body></html>"; Violations violations = rule.applyTo(toHtmlPage(content)); assertViolations(violations, rule, 1); }
@Test public void definitionListWithDefinitionTermAndDescription() throws Exception { String content = "<html><body><dl><dt>Speaker</dt><dd>Some wise words...</dd></dl></body></html>"; Violations violations = rule.applyTo(toHtmlPage(content)); assertNoViolations(violations, rule); }
@Test public void definitionListWithDifferentContentOnly() throws Exception { String content = "<html><body><dl><p>Hello World</p></dl></body></html>"; Violations violations = rule.applyTo(toHtmlPage(content)); assertViolations(violations, rule, 1); }