### Question:
WhileLoopRules extends TimedDelegate { @Override protected Set<Violation> doMeasuredAnalysis() throws JDOMException { final Set<Violation> violations = new HashSet<Violation>(); final List<Element> whileLoops = selectNodesByName("WHILE."); for (final Element whileLoop : whileLoops) { List<Attribute> nameAttributes = selectAttributes(whileLoop, "./*[1]/descendant-or-self::NAME/@text"); boolean found = false; for (Attribute nameAttribute : nameAttributes) { if (!selectNodes(whileLoop, "./COMMA. .isEmpty()) { found = true; break; } if (!selectNodes(whileLoop, "./COMMA. .isEmpty()) { found = true; break; } } if (!found) { violations.add(new InfiniteLoopViolation(getLineNumber(whileLoop))); } } return violations; } WhileLoopRules(final Document document); @Override Set<Violation> getCheckedViolations();  }### Answer:
@Test public void testNoReferenceToConditionals() throws Exception { final Set<Violation> violations = new WhileLoopRules(toDocument("no-reference-to-conditionals.xml")) .doMeasuredAnalysis(); assertThat(violations).hasSize(6); final List<Integer> failedLines = new ArrayList<Integer>(Arrays.asList(23, 19, 15, 11, 7, 3)); for (Violation v : violations) { assertThat(failedLines).contains(v.getLineNumber()); } }
@Test public void testReferenceToConditionals() throws Exception { final Set<Violation> violations = new WhileLoopRules(toDocument("reference-to-conditionals.xml")) .doMeasuredAnalysis(); assertThat(violations).hasSize(0); }