/** * RUL 006 * * <p>Class: ReferenceTypeRule Unit: processRuleOnNode(Declaration d, ArrayList<Declaration> * allDecls); * * <p>This test checks that the reference type rule works for three different instances of Class * Declaration correctly. */ @Test public void referenceOne() { ArrayList<Declaration> allDecls = new ArrayList<Declaration>(); ClassDeclaration a = new ClassDeclaration("Class A", false); ClassDeclaration b = new ClassDeclaration("Class B", false); ClassDeclaration c = new ClassDeclaration("Class C", false); ClassDeclaration d = new ClassDeclaration("Class D", false); Declaration e = new InterfaceDeclaration("Interface E"); Declaration f = new InterfaceDeclaration("Interface F"); // Add all to list allDecls.add(f); allDecls.add(e); allDecls.add(d); allDecls.add(c); allDecls.add(b); allDecls.add(a); // Add reference to A and D for (Declaration p : allDecls) { p.addReferenceToType(a.getName()); p.addReferenceToType(d.getName()); } // Add reference to an interface for (Declaration p : allDecls) { p.addReferenceToType(e.getName()); } ReferenceTypeRule rule = new ReferenceTypeRule(); // Both A and D have the same number of references. rule.processRuleOnNode(a, allDecls); assertEquals(allDecls.size(), rule.getScore()); rule.processRuleOnNode(d, allDecls); assertEquals(allDecls.size(), rule.getScore()); // Add one more reference to C c.addReferenceToNewObject(e.getName()); // Score should be allDecls size + 1 rule.processRuleOnNode(e, allDecls); assertEquals(allDecls.size() + 1, rule.getScore()); }
/** * RUL 007 * * <p>Class: ReferenceTypeRule Unit: processRuleOnNode(Declaration d, ArrayList<Declaration> * allDecls); * * <p>This test checks that the unit scores NULL as 0. */ @Test public void referenceTwo() { ArrayList<Declaration> allDecls = new ArrayList<Declaration>(); ClassDeclaration a = new ClassDeclaration("Class A", false); ClassDeclaration b = new ClassDeclaration("Class B", false); ClassDeclaration c = new ClassDeclaration("Class C", false); ClassDeclaration d = new ClassDeclaration("Class D", false); Declaration e = new InterfaceDeclaration("Interface E"); Declaration f = new InterfaceDeclaration("Interface F"); // Add all to list allDecls.add(f); allDecls.add(e); allDecls.add(d); allDecls.add(c); allDecls.add(b); allDecls.add(a); // Add reference to A and D for (Declaration p : allDecls) { p.addReferenceToType(a.getName()); p.addReferenceToType(d.getName()); } // Add reference to an interface for (Declaration p : allDecls) { p.addReferenceToType(e.getName()); } ReferenceTypeRule rule = new ReferenceTypeRule(); // Check F's score, should be 0 as no other decl references it. rule.processRuleOnNode(f, allDecls); assertEquals(0, rule.getScore()); }