Package com.google.test.metric

Examples of com.google.test.metric.MethodInvocationCost


    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\" "
        + "reason=\"implicit cost from static initialization\"/>");
View Full Code Here


    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\" "
        + "reason=\"" + NON_OVERRIDABLE_METHOD_CALL + "\"/>");
View Full Code Here

    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

    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

    CostModel costModel = new CostModel();
    SourceLocation location = new SourceLocation("com/google/FooClass.java", 1);
    final Issue issue =
        new Issue(location, "void doThing()", 0.5f, IssueType.CONSTRUCTION, IssueSubType.SETTER);
    final MethodCost methodCost = new MethodCost("", "void setUp()", 1, false, false, false);
    methodCost.addCostSource(new MethodInvocationCost(location, methodCost,
        Reason.IMPLICIT_SETTER, new Cost(100, 1, new int[0])));

    //TODO: looks like we want IssuesReporter to be an interface
    IssuesReporter issuesReporter = new IssuesReporter(null, null) {
      @Override
View Full Code Here

  }

  public void test2DeepPrintAll() throws Exception {
    DrillDownReportGenerator printer =
      new DrillDownReportGenerator(new PrintStream(out), costModel, null, MAX_VALUE, 0);
    methodCost2.addCostSource(new MethodInvocationCost(new SourceLocation(null, 81), methodCost1,
        NON_OVERRIDABLE_METHOD_CALL, Cost.cyclomatic(1)));
    methodCost2.link();
    printer.print("", methodCost2, MAX_VALUE);
    assertStringEquals("c.g.t.A.method2()V [CC: 3 / CC: 2]\n" +
        "  line 81: c.g.t.A.method1()V [CC: 1 / CC: 1] " + NON_OVERRIDABLE_METHOD_CALL +
View Full Code Here

  }

  public void test3DeepPrintAll() throws Exception {
    DrillDownReportGenerator printer =
      new DrillDownReportGenerator(new PrintStream(out), costModel, null, MAX_VALUE, 0);
    methodCost2.addCostSource(new MethodInvocationCost(new SourceLocation(null, 8), methodCost1,
        NON_OVERRIDABLE_METHOD_CALL, Cost.cyclomatic(1)));
    methodCost3.addCostSource(new MethodInvocationCost(new SourceLocation(null, 2), methodCost2,
        NON_OVERRIDABLE_METHOD_CALL, Cost.cyclomatic(3)));
    methodCost3.link();
    printer.print("", methodCost3, MAX_VALUE);
    assertStringEquals("c.g.t.A.method3()V [CC: 6 / CC: 3]\n" +
        "  line 2: c.g.t.A.method2()V [CC: 3 / CC: 2] " + NON_OVERRIDABLE_METHOD_CALL + "\n" +
View Full Code Here

  }

  public void test2DeepSupress0Cost() throws Exception {
    DrillDownReportGenerator printer =
      new DrillDownReportGenerator(new PrintStream(out), costModel, null, MAX_VALUE, 2);
    methodCost1.addCostSource(new MethodInvocationCost(new SourceLocation(null, 8), methodCost0,
        NON_OVERRIDABLE_METHOD_CALL, new Cost()));
    methodCost1.addCostSource(new MethodInvocationCost(new SourceLocation(null, 13), methodCost3,
        NON_OVERRIDABLE_METHOD_CALL, Cost.cyclomatic(3)));
    methodCost1.link();
    printer.print("", methodCost1, MAX_VALUE);
    assertStringEquals("c.g.t.A.method1()V [CC: 4 / CC: 1]\n" +
        "  line 13: c.g.t.A.method3()V [CC: 3 / CC: 3] " + NON_OVERRIDABLE_METHOD_CALL + "\n",
View Full Code Here

  }

  public void test3DeepPrint2Deep() throws Exception {
    DrillDownReportGenerator printer =
      new DrillDownReportGenerator(new PrintStream(out), costModel, null, MAX_VALUE, 0);
    methodCost3.addCostSource(new MethodInvocationCost(new SourceLocation(null, 2), methodCost2,
        NON_OVERRIDABLE_METHOD_CALL, Cost.cyclomatic(3)));
    methodCost2.addCostSource(new MethodInvocationCost(new SourceLocation(null, 2), methodCost1,
        NON_OVERRIDABLE_METHOD_CALL, Cost.cyclomatic(1)));
    methodCost3.link();
    printer.print("", methodCost3, 2);
    assertStringEquals("c.g.t.A.method3()V [CC: 6 / CC: 3]\n" +
      "  line 2: c.g.t.A.method2()V [CC: 3 / CC: 2] " + NON_OVERRIDABLE_METHOD_CALL + "\n",
View Full Code Here

  }

  public void testSupressAllWhenMinCostIs4() throws Exception {
    DrillDownReportGenerator printer =
      new DrillDownReportGenerator(new PrintStream(out), costModel, null, MAX_VALUE, 4);
    methodCost2.addCostSource(new MethodInvocationCost(new SourceLocation(null, 81), methodCost1,
        NON_OVERRIDABLE_METHOD_CALL, Cost.cyclomatic(1)));
    methodCost2.link();
    printer.print("", methodCost2, MAX_VALUE);
    assertStringEquals("", out.toString());
  }
View Full Code Here

TOP

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

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.