org.powermock.modules.junit3.internal.impl.PowerMockJUnit3RunnerDelegateImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of powermock-module-junit3 Show documentation
Show all versions of powermock-module-junit3 Show documentation
PowerMock support module for JUnit 3.x.
/*
* Copyright 2008 the original author or authors.
*
* 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.powermock.modules.junit3.internal.impl;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestResult;
import junit.framework.TestSuite;
import org.powermock.core.spi.PowerMockTestListener;
import org.powermock.modules.junit3.internal.PowerMockJUnit3RunnerDelegate;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Vector;
@SuppressWarnings("unchecked")
public class PowerMockJUnit3RunnerDelegateImpl extends TestSuite implements PowerMockJUnit3RunnerDelegate {
private final Method[] methodsToRun;
private Class> testClass;
public PowerMockJUnit3RunnerDelegateImpl(final Class> theClass, Method[] methodsToRun, String name,
PowerMockTestListener[] powerListeners) {
this(theClass, methodsToRun, powerListeners);
testClass = theClass;
setName(name);
}
/**
* Constructs a TestSuite from the given class. Adds all the methods
* starting with "test" as test cases to the suite. Parts of this method was
* cut'n'pasted on the train between Malm� and Stockholm.
*
* @param theClass the test suite class
* @param methodsToRun array of methods to run
* @param powerMockTestListeners array of {@link PowerMockTestListener}
*/
public PowerMockJUnit3RunnerDelegateImpl(final Class> theClass, Method[] methodsToRun,
PowerMockTestListener[] powerMockTestListeners) {
testClass = theClass;
this.methodsToRun = methodsToRun;
setName(theClass.getName());
try {
getTestConstructor(theClass); // Avoid generating multiple error
// messages
} catch (NoSuchMethodException e) {
addTest(warning("Class " + theClass.getName() + " has no public constructor TestCase(String name) or TestCase()"));
return;
}
if (!Modifier.isPublic(theClass.getModifiers())) {
addTest(warning("Class " + theClass.getName() + " is not public"));
return;
}
Class> superClass = theClass;
Vector> names = new Vector