### Question:
AnchorsWithoutTargetAttributeRule extends AbstractRule { @Override protected void applyTo(Page page, Violations violations) { for (HtmlAnchor anchor : page.findAllAnchorTags()) { if (hasAttribute(anchor, "target")) { violations.add(createViolation(anchor, page, RULE_MESSAGE)); } } }  @Override String getName();  }### Answer:
@Test public void linkWithTargetAttributePresent() throws Exception { String content = "<html><body><a href=\"url.htm\" target=\"_blank\">Click me</a></body></html>"; Violations violations = rule.applyTo(toHtmlPage(content)); assertViolations(violations, rule, 1); }
@Test public void linkWithNoTargetAttribute() throws Exception { String content = "<html><body><a href=\"url.htm\">Click me</a></body></html>"; Violations violations = rule.applyTo(toHtmlPage(content)); assertNoViolations(violations, rule); }