use of org.junit.runners.model.TestClass in project hazelcast by hazelcast.
the class AbstractHazelcastClassRunner method getTestRules.
@Override
protected List<TestRule> getTestRules(Object target) {
List<TestRule> testRules = super.getTestRules(target);
Set<Class<? extends TestRule>> testRuleClasses = new HashSet<Class<? extends TestRule>>();
TestClass testClass = getTestClass();
// find the required test rule classes from test class itself
Annotation[] classAnnotations = testClass.getAnnotations();
for (Annotation annotation : classAnnotations) {
Class<? extends Annotation> annotationType = annotation.annotationType();
AutoRegisteredTestRule autoFilterRule = annotationType.getAnnotation(AutoRegisteredTestRule.class);
if (autoFilterRule != null) {
Class<? extends TestRule> testRuleClass = autoFilterRule.testRule();
testRuleClasses.add(testRuleClass);
}
}
// find the required test rule classes from methods
List<FrameworkMethod> annotatedMethods = testClass.getAnnotatedMethods();
for (FrameworkMethod annotatedMethod : annotatedMethods) {
Annotation[] methodAnnotations = annotatedMethod.getAnnotations();
for (Annotation annotation : methodAnnotations) {
Class<? extends Annotation> annotationType = annotation.annotationType();
AutoRegisteredTestRule autoFilterRule = annotationType.getAnnotation(AutoRegisteredTestRule.class);
if (autoFilterRule != null) {
Class<? extends TestRule> testRuleClass = autoFilterRule.testRule();
testRuleClasses.add(testRuleClass);
}
}
}
// create and register test rules
for (Class<? extends TestRule> testRuleClass : testRuleClasses) {
try {
TestRule testRule = testRuleClass.newInstance();
testRules.add(testRule);
} catch (Throwable t) {
System.err.println("Unable to create test rule instance of test rule class " + testRuleClass.getName() + " because of " + t);
}
}
return testRules;
}
use of org.junit.runners.model.TestClass in project intellij-community by JetBrains.
the class GuiTestRunner method loadClassesWithIdeClassLoader.
private void loadClassesWithIdeClassLoader() throws Exception {
ClassLoader ideClassLoader = IdeTestApplication.getInstance().getIdeClassLoader();
Thread.currentThread().setContextClassLoader(ideClassLoader);
Class<?> testClass = getTestClass().getJavaClass();
myTestClass = new TestClass(ideClassLoader.loadClass(testClass.getName()));
}
use of org.junit.runners.model.TestClass in project robolectric by robolectric.
the class SandboxTestRunner method invokeBeforeClass.
private void invokeBeforeClass(final Class clazz) throws Throwable {
if (!loadedTestClasses.contains(clazz)) {
loadedTestClasses.add(clazz);
final TestClass testClass = new TestClass(clazz);
final List<FrameworkMethod> befores = testClass.getAnnotatedMethods(BeforeClass.class);
for (FrameworkMethod before : befores) {
before.invokeExplosively(null);
}
}
}
use of org.junit.runners.model.TestClass in project randomizedtesting by randomizedtesting.
the class RandomizedRunner method getAnnotatedFieldValues.
/*
* We're using JUnit infrastructure here, but provide constant
* ordering of the result. The returned list has class...super order.
*/
private <T> List<T> getAnnotatedFieldValues(Object test, Class<? extends Annotation> annotationClass, Class<T> valueClass) {
TestClass info = AccessController.doPrivileged(new PrivilegedAction<TestClass>() {
@Override
public TestClass run() {
return new TestClass(suiteClass);
}
});
List<T> results = new ArrayList<T>();
List<FrameworkField> annotatedFields = new ArrayList<FrameworkField>(info.getAnnotatedFields(annotationClass));
// Split fields by class
final HashMap<Class<?>, List<FrameworkField>> byClass = new HashMap<Class<?>, List<FrameworkField>>();
for (FrameworkField field : annotatedFields) {
Class<?> clz = field.getField().getDeclaringClass();
if (!byClass.containsKey(clz)) {
byClass.put(clz, new ArrayList<FrameworkField>());
}
byClass.get(clz).add(field);
}
// Consistent order at class level.
for (List<FrameworkField> fields : byClass.values()) {
Collections.sort(fields, new Comparator<FrameworkField>() {
@Override
public int compare(FrameworkField o1, FrameworkField o2) {
return o1.getField().getName().compareTo(o2.getField().getName());
}
});
Collections.shuffle(fields, new Random(runnerRandomness.getSeed()));
}
annotatedFields.clear();
for (Class<?> clz = suiteClass; clz != null; clz = clz.getSuperclass()) {
List<FrameworkField> clzFields = byClass.get(clz);
if (clzFields != null) {
annotatedFields.addAll(clzFields);
}
}
for (FrameworkField each : annotatedFields) {
try {
Object fieldValue = each.get(test);
if (valueClass.isInstance(fieldValue))
results.add(valueClass.cast(fieldValue));
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
return results;
}
use of org.junit.runners.model.TestClass in project deltaspike by apache.
the class MyFacesContainerAdapter method boot.
public void boot() {
final ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
this.mockedMyFacesTestContainer = new MyFacesContainer(new TestClass(this.testClass)) {
@Override
protected String getWebappResourcePath() {
TestConfig testConfig = testClass.getJavaClass().getAnnotation(TestConfig.class);
if (testConfig == null || DEFAULT_TEST_CONFIG_LITERAL.webappResourcePath().equals(testConfig.webappResourcePath())) {
return MyFacesTestBaseConfig.WEBAPP_RESOURCE_PATH;
}
return testConfig.webappResourcePath();
}
@Override
protected void setUpServletObjects() {
//just needed for MyFaces-Test util v1.0.7
//(to bypass issues with the outdated URLClassLoader used by AbstractJsfTestContainer)
setCurrentClassLoader(originalClassLoader);
super.setUpServletObjects();
}
@Override
protected void setUpWebConfigParams() {
servletContext.addInitParameter("org.apache.myfaces.config.annotation.LifecycleProvider", "org.apache.myfaces.config.annotation.NoInjectionAnnotationLifecycleProvider");
servletContext.addInitParameter("org.apache.myfaces.CHECKED_VIEWID_CACHE_ENABLED", "false");
servletContext.addInitParameter(ExpressionFactory.class.getName(), "org.apache.el.ExpressionFactoryImpl");
super.setUpWebConfigParams();
initContainerConfig();
//add custom values (might replace the default values)
for (Map.Entry<String, String> entry : containerConfig.entrySet()) {
servletContext.addInitParameter(entry.getKey(), entry.getValue());
}
}
};
this.mockedMyFacesTestContainer.setUp(new Object());
}
Aggregations