### Question:
RecordStructureDeclarationRules extends TimedDelegate { @Override protected Set<Violation> doMeasuredAnalysis() throws JDOMException { final Set<Violation> violations = new HashSet<Violation>(); final List<Element> records = selectNodesByName("RECORD."); final List<Element> frees = selectNodesByName("Z_FREE."); for (final Element record : records) { final String recordName = getCclName(record.getChild("COMMA.")); for (final Element listOrStruct : selectNodesByName(record, "FIELD.", "[OCCUR. or not(FORMAT.)]")) { if (listOrStruct.getChildren("FIELD.").size() == 0) { violations.add(new EmptyListOrStructureDefinitionViolation(recordName, getCclName(listOrStruct), getLineNumber(listOrStruct))); } } if (recordStructureHasNoDefinedScoping(record)) { violations.add(new UnprotectedRecordStructureDefinitionViolation(recordName, getLineNumber(record))); } for (final Element free : frees) { if (getCclName(free).equalsIgnoreCase(recordName)) { violations.add(new FreedRecordStructureViolation(recordName, getLineNumber(free))); break; } } } return violations; } RecordStructureDeclarationRules(final Document document); @Override Set<Violation> getCheckedViolations();  }### Answer:
@Test public void testWellDefinedRecordDeclarations() throws Exception { final Set<Violation> violations = new RecordStructureDeclarationRules( toDocument("well-defined-record-structures.xml")).doMeasuredAnalysis(); assertThat(violations).hasSize(0); }
@Test public void testEmptyListOrStructureDeclarations() throws Exception { final Set<Violation> violations = new RecordStructureDeclarationRules( toDocument("empty-list-or-structure-declarations.xml")).doMeasuredAnalysis(); assertThat(violations).hasSize(4); assertThat(violations).contains(new EmptyListOrStructureDefinitionViolation("BADRECORD1", "LIST1", 5)); assertThat(violations).contains(new EmptyListOrStructureDefinitionViolation("BADRECORD2", "STRUCT2", 11)); assertThat(violations).contains(new EmptyListOrStructureDefinitionViolation("BADRECORD3", "SUBSTRUCT3", 18)); assertThat(violations).contains(new EmptyListOrStructureDefinitionViolation("BADRECORD4", "STRUCT4", 24)); }
@Test public void testFreedRecordStructures() throws Exception { final Set<Violation> violations = new RecordStructureDeclarationRules(toDocument("freed-record-structures.xml")) .doMeasuredAnalysis(); assertThat(violations).hasSize(3); assertThat(violations).contains(new FreedRecordStructureViolation("MYREC", 3)); assertThat(violations).contains(new FreedRecordStructureViolation("ANOTHERREC", 25)); assertThat(violations).contains(new FreedRecordStructureViolation("ATHIRDREC", 24)); }
@Test public void testUnprotectedRecordStructures() throws Exception { final Set<Violation> violations = new RecordStructureDeclarationRules( toDocument("unprotected-record-structure-declarations.xml")).doMeasuredAnalysis(); assertThat(violations).hasSize(2); assertThat(violations).contains(new UnprotectedRecordStructureDefinitionViolation("REC1", 3)); assertThat(violations).contains(new UnprotectedRecordStructureDefinitionViolation("REC2", 8)); }