### Question:
CaptionTextForTableRule extends AbstractRule { @Override protected void applyTo(Page page, Violations violations) { for (HtmlTable table : page.findAllTableTags()) { if (table.getCaptionText() == null || table.getCaptionText().isEmpty()) { violations.add(createViolation(table, page, RULE_MESSAGE)); } } }  @Override String getName();  }### Answer:
@Test public void tableWithMissingCaptionText() throws Exception { String content = "<html><body><table><tr><td>Hello World</td></tr></table></body></html>"; Violations violations = rule.applyTo(toHtmlPage(content)); assertViolations(violations, rule, 1); }
@Test public void tableWithEmptyCaptionText() throws Exception { String content = "<html><body><table><caption></caption><tr><td>Hello World</td></tr></table></body></html>"; Violations violations = rule.applyTo(toHtmlPage(content)); assertViolations(violations, rule, 1); }
@Test public void tableWithWhitespaceOnlyCaptionText() throws Exception { String content = "<html><body><table><caption> </caption><tr><td>Hello World</td></tr></table></body></html>"; Violations violations = rule.applyTo(toHtmlPage(content)); assertViolations(violations, rule, 1); }
@Test public void tableWithCaptionText() throws Exception { String content = "<html><body><table><caption>Short summary</caption><tr><td>Accessibility</td></tr></table></body></html>"; Violations violations = rule.applyTo(toHtmlPage(content)); assertNoViolations(violations); }