PageRenderTime 162ms CodeModel.GetById 131ms app.highlight 25ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://testability-explorer.googlecode.com/
Java | 116 lines | 85 code | 16 blank | 15 comment | 0 complexity | a9c381fa2dd7e6b4831f023abf49a53f MD5 | raw file
  1/*
  2 * Copyright 2009 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;
 17
 18import com.google.test.metric.ReportGeneratorProvider.ReportFormat;
 19
 20import org.kohsuke.args4j.CmdLineException;
 21
 22import java.io.ByteArrayOutputStream;
 23import java.io.PrintStream;
 24import java.util.Arrays;
 25
 26public class CommandLineConfigTest extends AutoFieldClearTestCase {
 27
 28  private ByteArrayOutputStream out = new ByteArrayOutputStream();
 29  private ByteArrayOutputStream err = new ByteArrayOutputStream();
 30  private CommandLineConfig commandLineConfig;
 31
 32  @Override
 33  public void setUp() {
 34    commandLineConfig = new CommandLineConfig(new PrintStream(out), new PrintStream(err));
 35  }
 36
 37  public void testCreateSummaryReport2() throws Exception {
 38    commandLineConfig.printer = "summary";
 39    commandLineConfig.cp = "a";
 40    commandLineConfig.validate();
 41    assertEquals(ReportFormat.summary, commandLineConfig.format);
 42  }
 43
 44  public void testCreateHtmlReport() throws Exception {
 45    commandLineConfig.printer = "html"; 
 46    commandLineConfig.cp = "a";
 47    commandLineConfig.validate();
 48    assertEquals(ReportFormat.html, commandLineConfig.format);
 49  }
 50
 51  public void testCreateDetailReport() throws Exception {
 52    commandLineConfig.printer = "detail"; 
 53    commandLineConfig.cp = "a";
 54    commandLineConfig.validate();
 55    assertEquals(ReportFormat.detail, commandLineConfig.format);
 56  }
 57  
 58  public void testCreatePropertiesReport() throws Exception {
 59    commandLineConfig.printer = "props"; 
 60    commandLineConfig.cp = "a";
 61    commandLineConfig.validate();
 62    assertEquals(ReportFormat.props, commandLineConfig.format);
 63  }
 64
 65  public void testCreateSourceReport() throws Exception {
 66    commandLineConfig.printer = "source"; 
 67    commandLineConfig.cp = "a";
 68    commandLineConfig.validate();
 69    assertEquals(ReportFormat.source, commandLineConfig.format);
 70  }
 71
 72  public void testCreateXmlReport() throws Exception {
 73    commandLineConfig.printer = "xml"; 
 74    commandLineConfig.cp = "a";
 75    commandLineConfig.validate();
 76    JavaTestabilityModule module = new JavaTestabilityModule(commandLineConfig);
 77    assertEquals(ReportFormat.xml, module.getFormat());
 78  }
 79
 80  public void testCreateNonexistantReportThrowsException() throws Exception {
 81    commandLineConfig.cp = "";
 82    commandLineConfig.printer = "i-dont-exist";
 83    try {
 84      commandLineConfig.validate();
 85      fail("CmdLineException exception expected but did not get thrown");
 86    } catch (CmdLineException expected) {
 87      assertTrue(expected.getMessage().startsWith("Don't understand"));
 88    }
 89  }
 90  
 91  public void testBuildTestabilityConfig() throws Exception {
 92    PrintStream errStream = new PrintStream(new ByteArrayOutputStream());
 93    commandLineConfig = new CommandLineConfig(null, errStream);
 94    commandLineConfig.entryList = Arrays.asList("com.example.io", "com.example.ext");
 95    commandLineConfig.cp = "fake/path";
 96    commandLineConfig.printDepth = 3;
 97    commandLineConfig.printer = "summary";
 98    commandLineConfig.validate();
 99    JavaTestabilityModule testabilityModule = new JavaTestabilityModule(commandLineConfig);
100    assertEquals(2, testabilityModule.getEntryList().size());
101    assertEquals(ReportFormat.summary, testabilityModule.getFormat());
102    assertEquals(errStream, testabilityModule.getErr());
103    assertEquals(3, testabilityModule.getPrintDepth());
104  }
105
106  public void testJavaWhitelistProvider() throws Exception {
107    commandLineConfig.wl = "com.foo:org.bar";
108    WhiteList whiteList = new JavaTestabilityModule(commandLineConfig).getWhiteList(commandLineConfig);
109    assertTrue(whiteList.isClassWhiteListed("com.foo.Hash"));
110    assertTrue(whiteList.isClassWhiteListed("org.bar.BiMap"));
111    assertTrue(whiteList.isClassWhiteListed("java.lang"));
112    assertTrue(whiteList.isClassWhiteListed("javax.swing.plaf"));
113    assertFalse(whiteList.isClassWhiteListed("com.example"));
114  }
115  
116}