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

http://testability-explorer.googlecode.com/ · Java · 54 lines · 31 code · 8 blank · 15 comment · 0 complexity · aa0564e49c0eb50b8960a972782d1b76 MD5 · raw file

  1. /*
  2. * Copyright 2007 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;
  17. import com.google.test.metric.ClassCost;
  18. import com.google.test.metric.Cost;
  19. import com.google.test.metric.CostModel;
  20. import com.google.test.metric.CyclomaticCost;
  21. import com.google.test.metric.MethodCost;
  22. import com.google.test.metric.SourceLocation;
  23. import junit.framework.TestCase;
  24. import java.io.ByteArrayInputStream;
  25. import java.io.ByteArrayOutputStream;
  26. import java.util.Arrays;
  27. import java.util.Properties;
  28. public class PropertiesReportTest extends TestCase {
  29. ByteArrayOutputStream out = new ByteArrayOutputStream();
  30. CostModel costModel = new CostModel(1, 1, 1);
  31. PropertiesReportGenerator report = new PropertiesReportGenerator(out, costModel);
  32. private static final String CLASS_NAME = "com.google.foo.Bar";
  33. public void testReport() throws Exception {
  34. MethodCost methodCost = new MethodCost("", "doThing", 3, false, false, false);
  35. methodCost.addCostSource(new CyclomaticCost(new SourceLocation(null, 0), Cost.cyclomatic(1)));
  36. methodCost.link();
  37. final ClassCost classCost = new ClassCost(CLASS_NAME, Arrays.asList(methodCost));
  38. report.addClassCost(classCost);
  39. report.printFooter();
  40. String output = out.toString();
  41. assertTrue(output.contains("Bar"));
  42. Properties props = new Properties();
  43. props.load(new ByteArrayInputStream(out.toByteArray()));
  44. assertEquals(1, Integer.parseInt(props.getProperty(CLASS_NAME)));
  45. }
  46. }