### Question:
AlternativeTextForImageRule extends AbstractRule { @Override protected void applyTo(Page page, Violations violations) { for (HtmlImage image : page.findAllImageTags()) { validateImage(image, page, violations); } }  @Override String getName();  }### Answer:
@Test public void imageWithMissingAlternativeText() throws Exception { String content = "<html><body><img src=\"myImage.gif\" /></body></html>"; Violations violations = rule.applyTo(toHtmlPage(content)); assertViolations(violations, rule, 1); }
@Test public void imageWithEmptyAlternativeText() throws Exception { String content = "<html><body><img src=\"myImage.gif\" alt=\"\" /></body></html>"; Violations violations = rule.applyTo(toHtmlPage(content)); assertNoViolations(violations); }
@Test public void imageWithAlternativeText() throws Exception { String content = "<html><body><img src=\"myImage.gif\" alt=\"Alternative Text\" /></body></html>"; Violations violations = rule.applyTo(toHtmlPage(content)); assertNoViolations(violations); }