Package com.google.test.metric

Examples of com.google.test.metric.MethodCost


  }

  public void testPrintCost() throws Exception {
    XMLReportGenerator report = new XMLReportGenerator(handler, costModel, 0, 0, 0);

    MethodCost methodCost = new MethodCost("", "methodName", 1, false, false, false);
    methodCost.addCostSource(new CyclomaticCost(new SourceLocation(null, 0), Cost.cyclomatic(1)));
    methodCost.addCostSource(new CyclomaticCost(new SourceLocation(null, 0), Cost.cyclomatic(1)));
    ViolationCost violation = new MethodInvocationCost(new SourceLocation("source.file", 123), methodCost,
        IMPLICIT_STATIC_INIT, Cost.cyclomatic(2).add(Cost.global(3)));
    report.writeCost(violation);
    assertXMLEquals("<cost cyclomatic=\"2\" file=\"source.file\" global=\"3\" line=\"123\" "
        + "lod=\"0\" method=\"methodName\" overall=\"32\" "
View Full Code Here


  // This was throwing NPE before
  public void testPrintCostNullReason() throws Exception {
    XMLReportGenerator report = new XMLReportGenerator(handler, costModel, 0, 0, 0);

    MethodCost methodCost = new MethodCost("", "methodName", 1, false, false, false);
    methodCost.addCostSource(new CyclomaticCost(new SourceLocation(null, 0), Cost.cyclomatic(1)));
    methodCost.addCostSource(new CyclomaticCost(new SourceLocation(null, 0), Cost.cyclomatic(1)));
    ViolationCost violation = new MethodInvocationCost(new SourceLocation("source.file", 123), methodCost,
        NON_OVERRIDABLE_METHOD_CALL, Cost.cyclomatic(2).add(Cost.global(3)));
    report.writeCost(violation);
    assertXMLEquals("<cost cyclomatic=\"2\" file=\"source.file\" global=\"3\" line=\"123\" "
        + "lod=\"0\" method=\"methodName\" overall=\"32\" "
View Full Code Here

      public void writeCost(ViolationCost violation) throws SAXException {
        write("L" + violation.getLocation().getLineNumber() + ",");
      }

    };
    MethodCost methodCost = new MethodCost("", "methodName", 123, false, false, false);
    methodCost.addCostSource(new GlobalCost(new SourceLocation(null, 123), null, Cost.global(1)));
    methodCost.addCostSource(new CyclomaticCost(new SourceLocation(null, 234), Cost.cyclomatic(1)));
    methodCost.addCostSource(new CyclomaticCost(new SourceLocation(null, 345), Cost.cyclomatic(1)));
    methodCost.addCostSource(new GlobalCost(new SourceLocation(null, 456), null, Cost.global(1)));
    methodCost.link();
    report.writeCost(methodCost);
    assertXMLEquals("<method cyclomatic=\"2\" global=\"2\" line=\"123\" "
        + "lod=\"0\" name=\"methodName\" overall=\"22\">L123,L234,L345,L456,</method>");
  }
View Full Code Here

      @Override
      public void writeCost(MethodCost methodCost) throws SAXException {
        write(methodCost.getMethodName() + "()");
      }
    };
    MethodCost m1 = new MethodCost("", "M1", -1, false, false, false);
    m1.addCostSource(new CyclomaticCost(new SourceLocation(null, 0), Cost.cyclomatic(1)));
    m1.addCostSource(new CyclomaticCost(new SourceLocation(null, 0), Cost.cyclomatic(1)));
    MethodCost m2 = new MethodCost("", "M2", -1, false, false, false);
    m2.addCostSource(new CyclomaticCost(new SourceLocation(null, 0), Cost.cyclomatic(1)));
    m1.link();
    m2.link();
    ClassCost classCost = new ClassCost("className", asList(m1, m2));
    report.writeCost(classCost);
    assertXMLEquals("<class class=\"className\" cost=\"1\">M1()M2()</class>");
  }
View Full Code Here

      public void writeCost(ClassCost cost) throws SAXException {
        write(cost.getClassName() + ";");
      }
    };
    report.printHeader();
    MethodCost m1 = new MethodCost("", "M1", -1, false, false, false);
    m1.addCostSource(new CyclomaticCost(new SourceLocation(null, 0), Cost.cyclomatic(1)));
    m1.addCostSource(new CyclomaticCost(new SourceLocation(null, 0), Cost.cyclomatic(1)));
    m1.link();
    ClassCost c1 = new ClassCost("C1", asList(m1));
    ClassCost c2 = new ClassCost("C2", asList(m1));
    report.addClassCost(c1);
    report.addClassCost(c2);
    report.printFooter();
View Full Code Here

  public MethodCost doThingMethod;
  private MethodCost methodWithIndirectCosts;

  protected void setUp() throws Exception {
    super.setUp();
    doThingMethod = new MethodCost("Foo", "doThing()", 1, false, false, false);
    doThingMethod.addCostSource(new CyclomaticCost(new SourceLocation(null, 3), Cost.cyclomatic(100)));

    methodWithIndirectCosts = new MethodCost("Foo", "hasIndirect()", 2, false, false, false);
    methodWithIndirectCosts.addCostSource(new CyclomaticCost(new SourceLocation(null, 4), Cost.cyclomatic(50)));
    methodWithIndirectCosts.addCostSource(new MethodInvocationCost(new SourceLocation(null, 1),
        doThingMethod, NON_OVERRIDABLE_METHOD_CALL, Cost.cyclomatic(33)));
    costModel = new CostModel();
  }
View Full Code Here

    costModel = new CostModel();
  }

  public void testDirectCostOfAMethodCanBeSubtractedFromClassCost() {
    ClassCost classCost = new ClassCost("com.google.Foo", Arrays.asList(doThingMethod));
    MethodCost methodCost = doThingMethod;
    assertEquals(1.0f, hypotheticalCostModel.computeContributionFromMethod(classCost, methodCost));
  }
View Full Code Here

    assertEquals(1.0f, hypotheticalCostModel.computeContributionFromMethod(classCost, methodCost));
  }

  public void testContributionFromOneMethodIsCorrect() {
    ClassCost classCost = new ClassCost("com.google.Foo", Arrays.asList(doThingMethod, methodWithIndirectCosts));
    MethodCost methodCost = doThingMethod;
    float costWithoutDoThing = (0 + (50 + 33)) / 2;
    float costWithDoThing = (100 + (50 + 33)) / 2;
    assertEquals(1 - costWithoutDoThing / costWithDoThing,
        hypotheticalCostModel.computeContributionFromMethod(classCost, methodCost));
  }
View Full Code Here

  public void testMethodCostGoesDownWhenADependentCostIsRemoved() throws Exception {
    ClassInfo aClass = repo.getClass(Example.class.getCanonicalName());
    ClassCost classCost = computer.compute(aClass);
    float costWithWorkInConstructor = (4 + 7) / 2;
    float costWithoutWorkInConstructor = (0 + 3) / 2;
    MethodCost constructorCost = classCost.getMethodCost("Example()");
    MethodInvocationCost instanceCost4Invocation =
        (MethodInvocationCost) constructorCost.getViolationCosts().get(0);
    float actual = hypotheticalCostModel.computeContributionFromIssue(classCost, constructorCost,
        instanceCost4Invocation);
    // TODO
    //assertEquals(1 - costWithoutWorkInConstructor / costWithWorkInConstructor, actual);
  }
View Full Code Here

  PropertiesReportGenerator report = new PropertiesReportGenerator(out, costModel);

  private static final String CLASS_NAME = "com.google.foo.Bar";
  public void testReport() throws Exception {

    MethodCost methodCost = new MethodCost("", "doThing", 3, false, false, false);
    methodCost.addCostSource(new CyclomaticCost(new SourceLocation(null, 0), Cost.cyclomatic(1)));
    methodCost.link();
    final ClassCost classCost = new ClassCost(CLASS_NAME, Arrays.asList(methodCost));
    report.addClassCost(classCost);
    report.printFooter();

    String output = out.toString();
View Full Code Here

TOP

Related Classes of com.google.test.metric.MethodCost

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.