Package com.google.test.metric

Examples of com.google.test.metric.ClassCost


    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


    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();
    assertXMLEquals("<testability excellent=\"0\" good=\"0\" " +
        "needsWork=\"2\" overall=\"2\">C1;C2;</testability>");
View Full Code Here

        doThingMethod, NON_OVERRIDABLE_METHOD_CALL, Cost.cyclomatic(33)));
    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

    MethodCost methodCost = doThingMethod;
    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 testHypotheticalModelGivesTheSameNumberWithNoOverrides() throws Exception {
    ClassInfo aClass = repo.getClass(Example.class.getCanonicalName());
    ClassCost cost = computer.compute(aClass);
    int originalCost = costModel.computeClass(cost);
    int newCost = hypotheticalCostModel.computeClass(cost);
    assertEquals(originalCost, newCost);
  }
View Full Code Here

    assertEquals(originalCost, newCost);
  }

  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
View Full Code Here

      CostUtil.staticCost4();
    }
  }

  public void testSeveralNonMockableMethodIssues() throws Exception {
    ClassCost cost = decoratedComputer.compute(SeveralNonMockableMethodIssues.class);
    ClassIssues classIssues = issuesReporter.determineIssues(
        cost);
    assertEquals(2, classIssues.getSize());
    List<Issue> issues = classIssues.getCollaboratorIssues().get(STATIC_METHOD.toString());
    Issue issue0 = issues.get(0);
    Issue issue1 = issues.get(1);
    assertEquals(6, cost.getTotalComplexityCost() + 10 * cost.getTotalGlobalCost());
    assertEquals(4/6f, issue0.getContributionToClassCost(), 0.001f);
    assertEquals(2/6f, issue1.getContributionToClassCost(), 0.001f);

  }
View Full Code Here

  public void testClassesWithNoIssuesAreStillAddedToQueue() throws Exception {
    TriageIssuesQueue<ClassIssues> queue =
        new TriageIssuesQueue<ClassIssues>(1, 10, new ClassIssues.TotalCostComparator());
    IssuesReporter issuesReporterWithRealQueue = new IssuesReporter(queue, costModel);
    ClassCost cost = decoratedComputer.compute(SeveralConstructionIssues.class);
    issuesReporterWithRealQueue.inspectClass(cost);
    assertEquals(1, queue.size());
  }
View Full Code Here

  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();
    assertTrue(output.contains("Bar"));
View Full Code Here

    //TODO: looks like we want IssuesReporter to be an interface
    IssuesReporter issuesReporter = new IssuesReporter(null, null) {
      @Override
      public List<ClassIssues> getMostImportantIssues() {
        ClassCost aClassCost = new ClassCost("com/google/FooClass", Arrays.asList(methodCost));
        importantIssues.add(determineIssues(aClassCost));
        return importantIssues;
      }

      @Override
      public void inspectClass(ClassCost classCost) {
      }

      @Override
      public ClassIssues determineIssues(ClassCost classCost) {
        return new ClassIssues("com/google/FooClass", 100, new LinkedList<Issue>(Arrays.asList(issue)));
      }
    };
    ReportOptions options = new ReportOptions(1, 10, 1, 10, 20, 5, 100, 100, 1, 10, "", "");
    SourceLinker linker = new SourceLinker("http://code.repository/basepath/{path}&line={line}",
        "http://code.repository/basepath/{path}");

    cost = new ClassCost(getClass().getName(), Arrays.asList(methodCost));
    HtmlReportModel report =
        new HtmlReportModel(costModel, new AnalysisModel(issuesReporter), options);
    BeansWrapper objectWrapper = new DefaultObjectWrapper();
    Configuration configuration = new Configuration();
    configuration.setObjectWrapper(objectWrapper);
View Full Code Here

TOP

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

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.