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