### Question:
FieldsetContainsLegendRule extends AbstractRule { @Override protected void applyTo(Page page, Violations violations) { for (HtmlFieldSet fieldSet : page.findAllFieldsetTags()) { if (!(fieldSet.getFirstChild() instanceof HtmlLegend)) { violations.add(createViolation(fieldSet, page, RULE_MESSAGE)); } } }  @Override String getName();  }### Answer:
@Test public void fieldsetWithLegendPresent() throws Exception { String content = "<html><body><fieldset><legend>Description</legend></fieldset></body></html>"; Violations violations = rule.applyTo(toHtmlPage(content)); assertNoViolations(violations, rule); }
@Test public void fieldsetWithLegendMissing() throws Exception { String content = "<html><body><fieldset><p>no legend</p></fieldset></body></html>"; Violations violations = rule.applyTo(toHtmlPage(content)); assertViolations(violations, rule, 1); }