org.hyperic.sigar.test.SigarTestPrinter Maven / Gradle / Ivy
/*
* Copyright (c) 2006, 2008 Hyperic, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hyperic.sigar.test;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.Properties;
import junit.framework.AssertionFailedError;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestFailure;
import junit.framework.TestSuite;
import junit.textui.ResultPrinter;
import junit.textui.TestRunner;
import org.hyperic.sigar.cmd.Version;
import org.apache.log4j.PropertyConfigurator;
public class SigarTestPrinter extends ResultPrinter {
private HashMap failures = new HashMap();
private int maxNameLen = 0;
//just print once if we're run w/ "time 10 test"
private static boolean printedVersion;
private static final String PREFIX =
"org.hyperic.sigar.test.";
private static final String[][] LOG_PROPS = {
{
"log4j.rootLogger",
"DEBUG, R"
},
{
"log4j.appender.R",
"org.apache.log4j.ConsoleAppender"
},
{
"log4j.appender.R.layout",
"org.apache.log4j.PatternLayout"
},
{
"log4j.appender.R.layout.ConversionPattern",
"%d [%t] %-5p %c - %m%n"
},
};
public SigarTestPrinter(PrintStream writer) {
super(writer);
}
//output similar to perl TestHarness
//more interesting useful than the default '.', 'F', 'E'
//for each test success, failure or error.
public void startTest(Test test) {
PrintStream writer = getWriter();
String cls = test.getClass().getName();
cls = cls.substring(PREFIX.length());
String method = ((TestCase)test).getName();
String name = cls + "." + method;
writer.print(name);
int n = ((maxNameLen+3) - name.length());
for (int i=0; i printer.maxNameLen) {
printer.maxNameLen = len;
}
suite.addTestSuite(test);
}
private static Class findTest(Class[] tests, String name) {
String tname = "Test" + name;
for (int i=0; i 0) {
Properties props = new Properties();
for (int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy