PageRenderTime 11ms CodeModel.GetById 1ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/testability-explorer/src/test/java/com/google/test/metric/example/WorkInTheConstructorTest.java

http://testability-explorer.googlecode.com/
Java | 64 lines | 41 code | 8 blank | 15 comment | 0 complexity | 1e28c58656badfeadc27991ccaf305f6 MD5 | raw file
 1/*
 2 * Copyright 2008 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.example;
17
18import com.google.test.metric.AutoFieldClearTestCase;
19import com.google.test.metric.ClassCost;
20import com.google.test.metric.ClassRepository;
21import com.google.test.metric.JavaClassRepository;
22import com.google.test.metric.MetricComputer;
23import com.google.test.metric.example.ExpensiveConstructor.Cost2ToConstruct;
24import com.google.test.metric.example.ExpensiveConstructor.ObjectInstantiationWorkInTheConstructor;
25import com.google.test.metric.example.ExpensiveConstructor.StaticWorkInTheConstructor;
26import com.google.test.metric.testing.MetricComputerBuilder;
27import com.google.test.metric.testing.MetricComputerJavaDecorator;
28
29public class WorkInTheConstructorTest extends AutoFieldClearTestCase {
30
31  MetricComputerJavaDecorator decoratedComputer;
32
33  @Override
34  protected void setUp() throws Exception {
35    ClassRepository repo = new JavaClassRepository();
36    MetricComputer toDecorate = new MetricComputerBuilder().withClassRepository(repo).build();
37    decoratedComputer = new MetricComputerJavaDecorator(toDecorate, repo);
38  }
39
40  public void testCostToConstructClassCost() throws Exception {
41    ClassCost classCost = decoratedComputer.compute(Cost2ToConstruct.class);
42    assertEquals(2, classCost.getHighestMethodComplexityCost());
43    assertEquals(0, classCost.getHighestMethodGlobalCost());
44    assertEquals(0, classCost.getTotalGlobalCost());
45    assertEquals(2, classCost.getTotalComplexityCost());
46  }
47
48  public void testStaticWorkInTheConstructorClassCost() throws Exception {
49    ClassCost classCost = decoratedComputer.compute(StaticWorkInTheConstructor.class);
50    assertEquals(2, classCost.getHighestMethodComplexityCost());
51    assertEquals(0, classCost.getHighestMethodGlobalCost());
52    assertEquals(0, classCost.getTotalGlobalCost());
53    assertEquals(2, classCost.getTotalComplexityCost());
54  }
55
56  public void testObjectInstantiationWorkInTheConstructorClassCost() throws Exception {
57    ClassCost classCost = decoratedComputer.compute(ObjectInstantiationWorkInTheConstructor.class);
58    assertEquals(2, classCost.getHighestMethodComplexityCost());
59    assertEquals(0, classCost.getHighestMethodGlobalCost());
60    assertEquals(0, classCost.getTotalGlobalCost());
61    assertEquals(2, classCost.getTotalComplexityCost());
62  }
63
64}