### Question:
TableHeaderContainsTextRule extends AbstractRule { @Override protected void applyTo(Page page, Violations violations) { for (HtmlTableCell cell : page.findAllTableHeaders()) { if (cell.getTextContent() == null || cell.getTextContent().isEmpty()) { violations.add(createViolation(cell, page, RULE_MESSAGE)); } } }  @Override String getName();  }### Answer:
@Test public void tableHeadersWithText() throws Exception { String content = "<html><body><table><tr><th>Heading 1</th><th>Heading 2</th></tr><tr><td>Cell 1</td><td>Cell 2</td></tr></table></body></html>"; Violations violations = rule.applyTo(toHtmlPage(content)); assertViolations(violations, rule, 0); }
@Test public void tableHeadersWithMissingText() throws Exception { String content = "<html><body><table><tr><th></th><th /></tr><tr><td>Cell 1</td><td>Cell 2</td></tr></table></body></html>"; Violations violations = rule.applyTo(toHtmlPage(content)); assertEquals(2, violations.size()); assertViolations(violations, rule, 2); }