/testability-explorer/src/test/java/com/google/test/metric/report/issues/ClassIssuesTest.java
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 */ 16package com.google.test.metric.report.issues; 17 18import static com.google.test.metric.report.issues.IssueSubType.COMPLEXITY; 19import static com.google.test.metric.report.issues.IssueSubType.STATIC_METHOD; 20import static com.google.test.metric.report.issues.IssueType.COLLABORATOR; 21import static com.google.test.metric.report.issues.IssueType.DIRECT_COST; 22 23import java.util.List; 24import java.util.Map; 25 26import junit.framework.TestCase; 27 28import com.google.test.metric.SourceLocation; 29 30/** 31 * Tests for {@link com.google.test.metric.report.issues.ClassIssues} 32 * @author alexeagle@google.com (Alex Eagle) 33 */ 34public class ClassIssuesTest extends TestCase { 35 private String foo = "foo()"; 36 private SourceLocation location = new SourceLocation("foo", 1); 37 38 public void testIssuesAreSortedByContribution() throws Exception { 39 ClassIssues classIssues = new ClassIssues("Foo", 100); 40 classIssues.add(new Issue(location, foo, 0.1f, COLLABORATOR, COMPLEXITY)); 41 classIssues.add(new Issue(location, foo, 0.9f, COLLABORATOR, COMPLEXITY)); 42 classIssues.add(new Issue(location, foo, 0.5f, COLLABORATOR, COMPLEXITY)); 43 44 List<Issue> list = classIssues.getCollaboratorIssues().get(COMPLEXITY.toString()); 45 assertEquals(3, list.size()); 46 assertEquals(0.9f, list.get(0).getContributionToClassCost()); 47 assertEquals(0.5f, list.get(1).getContributionToClassCost()); 48 assertEquals(0.1f, list.get(2).getContributionToClassCost()); 49 50 } 51 52 public void testBucketizationOfIssuesIntoSubTypes() throws Exception { 53 ClassIssues classIssues = new ClassIssues("Foo", 100); 54 classIssues.add(new Issue(location, foo, 0.1f, COLLABORATOR, COMPLEXITY)); 55 classIssues.add(new Issue(location, foo, 0.9f, DIRECT_COST, COMPLEXITY)); 56 classIssues.add(new Issue(location, foo, 0.5f, DIRECT_COST, COMPLEXITY)); 57 classIssues.add(new Issue(location, foo, 0.5f, DIRECT_COST, STATIC_METHOD)); 58 59 Map<String, List<Issue>> issueMap = classIssues.bucketize(IssueType.DIRECT_COST); 60 assertEquals(2, issueMap.keySet().size()); 61 assertEquals(2, issueMap.get(COMPLEXITY.toString()).size()); 62 assertEquals(1, issueMap.get(STATIC_METHOD.toString()).size()); 63 64 65 } 66}