/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. */
  16. package com.google.test.metric.example;
  17. import com.google.test.metric.AutoFieldClearTestCase;
  18. import com.google.test.metric.ClassCost;
  19. import com.google.test.metric.ClassRepository;
  20. import com.google.test.metric.JavaClassRepository;
  21. import com.google.test.metric.MetricComputer;
  22. import com.google.test.metric.example.ExpensiveConstructor.Cost2ToConstruct;
  23. import com.google.test.metric.example.ExpensiveConstructor.ObjectInstantiationWorkInTheConstructor;
  24. import com.google.test.metric.example.ExpensiveConstructor.StaticWorkInTheConstructor;
  25. import com.google.test.metric.testing.MetricComputerBuilder;
  26. import com.google.test.metric.testing.MetricComputerJavaDecorator;
  27. public class WorkInTheConstructorTest extends AutoFieldClearTestCase {
  28. MetricComputerJavaDecorator decoratedComputer;
  29. @Override
  30. protected void setUp() throws Exception {
  31. ClassRepository repo = new JavaClassRepository();
  32. MetricComputer toDecorate = new MetricComputerBuilder().withClassRepository(repo).build();
  33. decoratedComputer = new MetricComputerJavaDecorator(toDecorate, repo);
  34. }
  35. public void testCostToConstructClassCost() throws Exception {
  36. ClassCost classCost = decoratedComputer.compute(Cost2ToConstruct.class);
  37. assertEquals(2, classCost.getHighestMethodComplexityCost());
  38. assertEquals(0, classCost.getHighestMethodGlobalCost());
  39. assertEquals(0, classCost.getTotalGlobalCost());
  40. assertEquals(2, classCost.getTotalComplexityCost());
  41. }
  42. public void testStaticWorkInTheConstructorClassCost() throws Exception {
  43. ClassCost classCost = decoratedComputer.compute(StaticWorkInTheConstructor.class);
  44. assertEquals(2, classCost.getHighestMethodComplexityCost());
  45. assertEquals(0, classCost.getHighestMethodGlobalCost());
  46. assertEquals(0, classCost.getTotalGlobalCost());
  47. assertEquals(2, classCost.getTotalComplexityCost());
  48. }
  49. public void testObjectInstantiationWorkInTheConstructorClassCost() throws Exception {
  50. ClassCost classCost = decoratedComputer.compute(ObjectInstantiationWorkInTheConstructor.class);
  51. assertEquals(2, classCost.getHighestMethodComplexityCost());
  52. assertEquals(0, classCost.getHighestMethodGlobalCost());
  53. assertEquals(0, classCost.getTotalGlobalCost());
  54. assertEquals(2, classCost.getTotalComplexityCost());
  55. }
  56. }