use of junit.framework.Protectable in project jmeter by apache.
the class JUnitSampler method initializeTestObject.
/**
* Initialize test object
*/
private void initializeTestObject() {
String rlabel = getConstructorString();
if (rlabel.length() == 0) {
rlabel = JUnitSampler.class.getName();
}
this.testObject = getClassInstance(className, rlabel);
if (this.testObject != null) {
initMethodObjects(this.testObject);
final Method m = getMethod(this.testObject, methodName);
if (getJunit4()) {
Class<? extends Throwable> expectedException = None.class;
long timeout = 0;
Test annotation = m.getAnnotation(Test.class);
if (null != annotation) {
expectedException = annotation.expected();
timeout = annotation.timeout();
}
final AnnotatedTestCase at = new AnnotatedTestCase(m, expectedException, timeout);
testCase = at;
protectable = new Protectable() {
@Override
public void protect() throws Throwable {
at.runTest();
}
};
} else {
this.testCase = (TestCase) this.testObject;
// Must be final to create instance
final Object theClazz = this.testObject;
protectable = new Protectable() {
@Override
public void protect() throws Throwable {
try {
m.invoke(theClazz, new Object[0]);
} catch (InvocationTargetException e) {
/*
* Calling a method via reflection results in wrapping any
* Exceptions in ITE; unwrap these here so runProtected can
* allocate them correctly.
*/
Throwable t = e.getCause();
if (t != null) {
throw t;
}
throw e;
}
}
};
}
if (this.testCase != null) {
this.testCase.setName(methodName);
}
}
}
use of junit.framework.Protectable in project tomee by apache.
the class NumberedTestCase method run.
protected void run(final TestResult result, final Method testMethod) {
final Test test = createTest(testMethod);
result.startTest(test);
final Protectable p = new Protectable() {
public void protect() throws Throwable {
runTestMethod(testMethod);
}
};
// System.out.println(">>" + NumberedTestCase.class.getName() + "> started: " + testMethod.toGenericString());
result.runProtected(test, p);
result.endTest(test);
// System.out.println(">>" + NumberedTestCase.class.getName() + "> done: " + testMethod.toGenericString());
}
use of junit.framework.Protectable in project junit4 by junit-team.
the class TestSetup method run.
@Override
public void run(final TestResult result) {
Protectable p = new Protectable() {
public void protect() throws Exception {
setUp();
basicRun(result);
tearDown();
}
};
result.runProtected(this, p);
}
Aggregations