/testability-explorer/src/test/java/com/google/test/metric/report/issues/ClassIssuesTest.java

http://testability-explorer.googlecode.com/ · Java · 66 lines · 35 code · 12 blank · 19 comment · 0 complexity · 5607c0d882b86dbc190e31b9d666e1eb MD5 · raw file

  1. /*
  2. * Copyright 2009 Google Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.google.test.metric.report.issues;
  17. import static com.google.test.metric.report.issues.IssueSubType.COMPLEXITY;
  18. import static com.google.test.metric.report.issues.IssueSubType.STATIC_METHOD;
  19. import static com.google.test.metric.report.issues.IssueType.COLLABORATOR;
  20. import static com.google.test.metric.report.issues.IssueType.DIRECT_COST;
  21. import java.util.List;
  22. import java.util.Map;
  23. import junit.framework.TestCase;
  24. import com.google.test.metric.SourceLocation;
  25. /**
  26. * Tests for {@link com.google.test.metric.report.issues.ClassIssues}
  27. * @author alexeagle@google.com (Alex Eagle)
  28. */
  29. public class ClassIssuesTest extends TestCase {
  30. private String foo = "foo()";
  31. private SourceLocation location = new SourceLocation("foo", 1);
  32. public void testIssuesAreSortedByContribution() throws Exception {
  33. ClassIssues classIssues = new ClassIssues("Foo", 100);
  34. classIssues.add(new Issue(location, foo, 0.1f, COLLABORATOR, COMPLEXITY));
  35. classIssues.add(new Issue(location, foo, 0.9f, COLLABORATOR, COMPLEXITY));
  36. classIssues.add(new Issue(location, foo, 0.5f, COLLABORATOR, COMPLEXITY));
  37. List<Issue> list = classIssues.getCollaboratorIssues().get(COMPLEXITY.toString());
  38. assertEquals(3, list.size());
  39. assertEquals(0.9f, list.get(0).getContributionToClassCost());
  40. assertEquals(0.5f, list.get(1).getContributionToClassCost());
  41. assertEquals(0.1f, list.get(2).getContributionToClassCost());
  42. }
  43. public void testBucketizationOfIssuesIntoSubTypes() throws Exception {
  44. ClassIssues classIssues = new ClassIssues("Foo", 100);
  45. classIssues.add(new Issue(location, foo, 0.1f, COLLABORATOR, COMPLEXITY));
  46. classIssues.add(new Issue(location, foo, 0.9f, DIRECT_COST, COMPLEXITY));
  47. classIssues.add(new Issue(location, foo, 0.5f, DIRECT_COST, COMPLEXITY));
  48. classIssues.add(new Issue(location, foo, 0.5f, DIRECT_COST, STATIC_METHOD));
  49. Map<String, List<Issue>> issueMap = classIssues.bucketize(IssueType.DIRECT_COST);
  50. assertEquals(2, issueMap.keySet().size());
  51. assertEquals(2, issueMap.get(COMPLEXITY.toString()).size());
  52. assertEquals(1, issueMap.get(STATIC_METHOD.toString()).size());
  53. }
  54. }