gw.test.TestClassWrapper Maven / Gradle / Ivy
/*
* Copyright 2014 Guidewire Software, Inc.
*/
package gw.test;
import gw.lang.reflect.java.JavaTypes;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestResult;
import junit.framework.TestSuite;
import junit.framework.AssertionFailedError;
import gw.lang.reflect.IType;
import gw.lang.reflect.IMethodInfo;
import gw.lang.reflect.IAnnotationInfo;
import gw.lang.reflect.ITypeInfo;
import gw.lang.reflect.IConstructorInfo;
import gw.lang.reflect.java.IJavaType;
import gw.lang.reflect.java.JavaTypes;
import gw.lang.reflect.gs.IGosuClass;
import gw.testharness.IncludeInTestResults;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.Set;
import java.util.HashSet;
import java.lang.annotation.Annotation;
public class TestClassWrapper extends TestSuite {
private IType _type;
private TestExecutionManager _executionManager;
public TestClassWrapper(TestExecutionManager executionManager, IType type, String... methods) {
_executionManager = executionManager;
_type = type;
for (String method : methods) {
addTest(makeTest(_type, method));
}
}
@Override
public void runTest(Test test, TestResult result) {
if (_executionManager.hasTimedOut()) {
result.addFailure(test, new AssertionFailedError(String.format("tests timed out")));
} else if (_executionManager.hasTimeOut()) {
long timeout = _executionManager.getTimeoutForCurrentTest();
runWithTimeout(test, result, timeout);
} else {
super.runTest(test, result);
}
}
private void runWithTimeout(final Test test, final TestResult result, long timeout) {
ExecutorService service = Executors.newSingleThreadExecutor();
Callable
© 2015 - 2024 Weber Informatics LLC | Privacy Policy