### Question:
HeadingsInCorrectOrderRule extends AbstractRule { @Override protected void applyTo(Page page, Violations violations) { HtmlElement lastHeading = null; for (HtmlElement currentHeading : page.findAllHeadingTags()) { if (lastHeading == null) { checkFirstHeading(violations, currentHeading, page); } else { checkAllOtherHeadings(violations, lastHeading, currentHeading, page); } lastHeading = currentHeading; } }  @Override String getName();  }### Answer:
@Test public void headersInCorrectOrder() throws Exception { String content = "<html><body><h1>First Level</h1><h2>Second Level</h2><h3>Third Level</h3></body></html>"; Violations violations = rule.applyTo(toHtmlPage(content)); assertNoViolations(violations); }
@Test public void headersMustStartAtFirstLevel() throws Exception { String content = "<html><body><h2>First Level</h2><h3>Third Level</h3></body></html>"; Violations violations = rule.applyTo(toHtmlPage(content)); assertViolations(violations, rule, 1); }
@Test public void notMoreThanOneHeaderOfFirstLevelIsAllowed() throws Exception { String content = "<html><body><h1>First Level</h1><h2>Third Level</h2><h1>First Level again</h1></body></html>"; Violations violations = rule.applyTo(toHtmlPage(content)); assertViolations(violations, rule, 1); }
@Test public void headersMayNotSkipLevels() throws Exception { String content = "<html><body><h1>First Level</h1><h3>Third Level</h3></body></html>"; Violations violations = rule.applyTo(toHtmlPage(content)); assertViolations(violations, rule, 1); }
@Test public void headersMayNotSkipMultipleLevels() throws Exception { String content = "<html><body><h1>First Level</h1><h3>Third Level</h3><h6>Third Level</h6></body></html>"; Violations violations = rule.applyTo(toHtmlPage(content)); assertViolations(violations, rule, 2); }