### Question:
LabelContainsTextRule extends AbstractRule { @Override protected void applyTo(Page page, Violations violations) { for (HtmlLabel label : page.findAllLabelTags()) { validateLabel(label, page, violations); } }  @Override String getName();  }### Answer:
@Test public void labelWithText() throws Exception { String content = "<html><body><form><label for=\"firstname\">Firstname</label></form></body></html>"; Violations violations = rule.applyTo(toHtmlPage(content)); assertNoViolations(violations); }
@Test public void labelWithWrappedText() throws Exception { String content = "<html><body><form><label for=\"firstname\"><span>Firstname</span></label></form></body></html>"; Violations violations = rule.applyTo(toHtmlPage(content)); assertNoViolations(violations); }
@Test public void labelWithMissingText() throws Exception { String content = "<html><body><form><label for=\"firstname\"></label></form></body></html>"; Violations violations = rule.applyTo(toHtmlPage(content)); assertViolations(violations, rule, 1); }