Package com.google.test.metric

Examples of com.google.test.metric.MethodCost


    out = new ByteArrayOutputStream();
    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


        .contains("<a href=\"http://code.repository/basepath/com/google/FooClass.java&line"));
  }

  public void testConstructorCosts() throws Exception {
    ClassCost cost =
        new ClassCost("classFoo", Arrays.asList(new MethodCost("", "methodFoo", 1, false, false, false)));
    ClassIssues classIssues = new ClassIssues(cost.getClassName(), 0);
    classIssues.add(new Issue(new SourceLocation("", 1), null, 1f, null, null));
    importantIssues.add(classIssues);
    generator.printHeader();
    generator.addClassCost(cost);
View Full Code Here

    assertEquals(buf.toString(), out.toString());
  }

  private ClassCost classCost(String name, int cost) {
    List<MethodCost> methods = new ArrayList<MethodCost>();
    MethodCost methodCost = new MethodCost("", "method_" + cost, 1, false, false, false);
    for (int i = 0; i < cost; i++) {
      methodCost.addCostSource(new CyclomaticCost(new SourceLocation(null, i), Cost.cyclomatic(1)));
    }
    methodCost.link();
    methods.add(methodCost);
    ClassCost classCost = new ClassCost(name, methods);
    return classCost;
  }
View Full Code Here

}

  public void testSimpleCost() throws Exception {
    DrillDownReportGenerator printer =
      new DrillDownReportGenerator(new PrintStream(out), costModel, null, MAX_VALUE, 0);
    MethodCost costOnlyMethod1 = new MethodCost("", "c.g.t.A.method1()V", 0, false, false, false);
    costOnlyMethod1.addCostSource(new CyclomaticCost(new SourceLocation(null, 1), Cost.cyclomatic(1)));
    costOnlyMethod1.addCostSource(new GlobalCost(new SourceLocation(null, 0), null, Cost.global(1)));
    costOnlyMethod1.link();
    printer.print("", costOnlyMethod1, Integer.MAX_VALUE);
    assertStringEquals("c.g.t.A.method1()V [CC: 1, GC: 1 / CC: 1, GC: 1]\n", out.toString());
  }
View Full Code Here

* @author alexeagle@google.com (Alex Eagle)
*/
public class SourceElementFormattingTest extends TestCase {

  public void testMethodFormatting() throws Exception {
    MethodCost cost = new MethodCost("", "void translation_unit()", 1, false, false, false);
    assertEquals("void translation_unit()", cost.getDescription());
  }
View Full Code Here

        type, false, false), field);
    assertEquals("FinalGlobalExample$Gadget finalInstance", localField.getDescription());
  }

  public void testDotsInMethodParameters() throws Exception {
    MethodCost cost = new MethodCost(
        "",
        "com.google.test.metric.cpp.dom.TranslationUnit parse2(java.lang.String, java.lang.String)",
        12, false, false, false);
    assertEquals("TranslationUnit parse2(String, String)", cost.getDescription());
  }
View Full Code Here

  public void testCreateSourceReport() throws Exception {
    ClassCost classCost = computer.compute(TestClass.class.getCanonicalName());

    ClassReport classReport = report.createClassReport(classCost);
    Source source = classReport.getSource();
    MethodCost m1 = classCost.getMethodCost("void m1()");
    MethodCost m2 = classCost.getMethodCost("void m2()");
    Line l1 = source.getLine(m1.getMethodLineNumber());
    Line l2 = source.getLine(m2.getMethodLineNumber());

    assertTrue(l1.toString(), l1.toString().contains("staticCost4()"));
    assertEquals(4, l1.getCost().getCyclomaticComplexityCost());
    assertTrue(l2.toString(), l2.toString().contains("staticCost3()"));
    assertEquals(3, l2.getCost().getCyclomaticComplexityCost());
View Full Code Here

    model.setMessageBundle(bundleModel);
    generator = new FreemarkerReportGenerator(model, new PrintStream(out),
            "about/Report.html", configuration);
    generator.printHeader();
    generator.addClassCost(new ClassCost("com.google.test.metric.example.Lessons.SumOfPrimes1",
        asList(new MethodCost("", "foo()", 1, false, false, false))));
    generator.printFooter();

    String text = out.toString();
    assertTrue(text, text.contains(">SumOfPrimes1<"));
    assertTrue(text, text.contains(">Lessons<"));
View Full Code Here

    // TCC 4 because it doesn't double count for the same offense within one method
    assertEquals(4, methodCost.getTotalCost().getCyclomaticComplexityCost());
  }

  public void testPrivateTcc4Cost() throws Exception {
    MethodCost methodCost = cost("void methodPrivateTcc4()");
    assertEquals(4, methodCost.getCost().getCyclomaticComplexityCost());
    assertEquals(0, methodCost.getCost().getGlobalCost());
    assertEquals(0, methodCost.getTotalCost().getGlobalCost());
    assertEquals(4, methodCost.getTotalCost().getCyclomaticComplexityCost());

    methodCost = cost("void methodTcc4BecausePrivateMethodCalls()");
    assertEquals(0, methodCost.getCost().getCyclomaticComplexityCost());
    assertEquals(0, methodCost.getCost().getGlobalCost());
    assertEquals(0, methodCost.getTotalCost().getGlobalCost());
    // TCC 4 because it doesn't double count for the same offense within one method
    assertEquals(4, methodCost.getTotalCost().getCyclomaticComplexityCost());
  }
View Full Code Here

    // TCC 4 because it doesn't double count for the same offense within one method
    assertEquals(4, methodCost.getTotalCost().getCyclomaticComplexityCost());
  }

  public void testFinalTcc4Cost() throws Exception {
    MethodCost methodCost = cost("void methodFinalTcc4()");
    assertEquals(4, methodCost.getCost().getCyclomaticComplexityCost());
    assertEquals(0, methodCost.getCost().getGlobalCost());
    assertEquals(0, methodCost.getTotalCost().getGlobalCost());
    assertEquals(4, methodCost.getTotalCost().getCyclomaticComplexityCost());

    methodCost = cost("void methodTcc4BecauseFinalMethodCalls()");
    assertEquals(0, methodCost.getCost().getCyclomaticComplexityCost());
    assertEquals(0, methodCost.getCost().getGlobalCost());
    assertEquals(0, methodCost.getTotalCost().getGlobalCost());
    // TCC 4 because it doesn't double count for the same offense within one method
    assertEquals(4, methodCost.getTotalCost().getCyclomaticComplexityCost());
  }
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.