### Question:
LabelForSelectTagRule extends AbstractRule { @Override protected void applyTo(Page page, Violations violations) { for (HtmlSelect select : page.findAllSelectTags()) { if (hasNonEmptyAttribute(select, "id") && !containsLabelForId(page.findAllLabelTags(), select.getId())) { violations.add(createViolation(select, page, RULE_MESSAGE)); } } }  @Override String getName();  }### Answer:
@Test public void selectWithAssociatedLabel() throws Exception { String content = "<html><body><form><label for=\"gender\">Comment</label><select id=\"gender\"><option>m</option><option>f</option></select></form></body></html>"; Violations violations = rule.applyTo(toHtmlPage(content)); assertNoViolations(violations); }
@Test public void selectWithMissingLabel() throws Exception { String content = "<html><body><form><select id=\"gender\"><option>m</option><option>f</option></select></form></body></html>"; Violations violations = rule.applyTo(toHtmlPage(content)); assertViolations(violations, rule, 1); }