Example #1
0
  /**
   * RUL 008
   *
   * <p>Class: ReturnTypeRule Unit: processRuleOnNode(Declaration d, ArrayList<Declaration>
   * allDecls);
   *
   * <p>This test checks that the unit scores correctly for a class declaration instance.
   */
  @Test
  public void returnOne() {
    Method methodOne = new Method("getName");
    Method methodTwo = new Method("getOwner");
    Method methodThree = new Method("getFriends");

    methodOne.setReturnType("String"); // value is 6
    methodTwo.setReturnType("Object"); // value is 10
    methodThree.setReturnType("Object[]"); // value is 10x5 = 50

    ClassDeclaration classInstance = new ClassDeclaration("Dog", false);
    classInstance.addNewMethod(methodTwo);
    classInstance.addNewMethod(methodOne);
    classInstance.addNewMethod(methodThree);

    ReturnTypeRule rule = new ReturnTypeRule();

    rule.processRuleOnNode(classInstance, null);
    assertEquals(66, rule.getScore());
  }
Example #2
0
  /**
   * RUL 009
   *
   * <p>Class: ReturnTypeRule Unit: processRuleOnNode(Declaration d, ArrayList<Declaration>
   * allDecls);
   *
   * <p>This test checks that the unit scores correctly for a interface declaration instance.
   */
  @Test
  public void returnTwo() {
    Method methodOne = new Method("getName");
    Method methodTwo = new Method("getOwner");
    Method methodThree = new Method("getFriends");

    methodOne.setReturnType("String"); // value is 6
    methodTwo.setReturnType("String"); // value is 6
    methodThree.setReturnType(
        "HashMap<String,String>"); // value is 10x3 = 30, its an object and is a map

    InterfaceDeclaration interfaceInstance = new InterfaceDeclaration("Animal");
    interfaceInstance.addNewMethod(methodTwo);
    interfaceInstance.addNewMethod(methodOne);
    interfaceInstance.addNewMethod(methodThree);

    ReturnTypeRule rule = new ReturnTypeRule();

    rule.processRuleOnNode(interfaceInstance, null);
    assertEquals(42, rule.getScore());
  }