PageRenderTime 23ms CodeModel.GetById 9ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/testability-explorer/src/test/java/com/google/test/metric/WorkInConstructorTest.java

http://testability-explorer.googlecode.com/
Java | 80 lines | 50 code | 13 blank | 17 comment | 0 complexity | 19394733c3e7c09ed9910fe48d06bf4b MD5 | raw file
 1/*
 2 * Copyright 2009 Google Inc. All Rights Reserved.
 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;
17
18import com.google.test.metric.testing.MetricComputerBuilder;
19import com.google.test.metric.testing.MetricComputerJavaDecorator;
20
21public class WorkInConstructorTest extends AutoFieldClearTestCase {
22
23  private ClassRepository repo = new JavaClassRepository();
24  private MetricComputerJavaDecorator computer = new MetricComputerJavaDecorator(
25      new MetricComputerBuilder().withClassRepository(repo).build(), repo);
26
27  static class ConstructorDoesWork {
28    ConstructorDoesWork() {
29      CostUtil.staticCost3();
30    }
31
32    void method() {
33    }
34  }
35
36  public void testWorkInConstructorGetsPenalized() throws Exception {
37    ClassCost classCost = computer.compute(ConstructorDoesWork.class);
38    MethodCost constCost = classCost.getMethodCost("ConstructorDoesWork()");
39    assertNotNull(constCost);
40    assertEquals(3, constCost.getTotalCost().getCyclomaticComplexityCost());
41    assertEquals(0, constCost.getDirectCost().getCyclomaticComplexityCost());
42    assertEquals(3, constCost.getDependentCost().getCyclomaticComplexityCost());
43    assertEquals(0, constCost.getConstructorDependentCost().getCyclomaticComplexityCost());
44
45    MethodCost methodCost = classCost.getMethodCost("void method()");
46    assertNotNull(methodCost);
47    assertEquals(3, methodCost.getTotalCost().getCyclomaticComplexityCost());
48    assertEquals(0, methodCost.getDirectCost().getCyclomaticComplexityCost());
49    assertEquals(0, methodCost.getDependentCost().getCyclomaticComplexityCost());
50    assertEquals(3, methodCost.getConstructorDependentCost().getCyclomaticComplexityCost());
51
52    //fail("Add cost model assertions here");
53  }
54
55  static class DependantConstructorDoesWork {
56   void method() {
57     new ConstructorDoesWork().method();
58   }
59  }
60
61  public void testWorkInDependantConstructorDoesNotGetPenalized() throws Exception {
62    ClassCost classCost = computer.compute(DependantConstructorDoesWork.class);
63    MethodCost constCost = classCost.getMethodCost("DependantConstructorDoesWork()");
64    assertNotNull(constCost);
65    assertEquals(0, constCost.getTotalCost().getCyclomaticComplexityCost());
66    assertEquals(0, constCost.getDirectCost().getCyclomaticComplexityCost());
67    assertEquals(0, constCost.getDependentCost().getCyclomaticComplexityCost());
68    assertEquals(0, constCost.getConstructorDependentCost().getCyclomaticComplexityCost());
69
70    MethodCost methodCost = classCost.getMethodCost("void method()");
71    assertNotNull(methodCost);
72    assertEquals(3, methodCost.getTotalCost().getCyclomaticComplexityCost());
73    assertEquals(0, methodCost.getDirectCost().getCyclomaticComplexityCost());
74    assertEquals(0, methodCost.getDependentCost().getCyclomaticComplexityCost());
75    assertEquals(3, methodCost.getConstructorDependentCost().getCyclomaticComplexityCost());
76
77    //fail("Add cost model assertions here");
78  }
79
80}