use of org.junit.runners.model.InitializationError in project gerrit by GerritCodeReview.
the class ConfigSuite method runnersFor.
private static List<Runner> runnersFor(Class<?> clazz) {
Method defaultConfig = getDefaultConfig(clazz);
List<Method> configs = getConfigs(clazz);
Map<String, org.eclipse.jgit.lib.Config> configMap = callConfigMapMethod(getConfigMap(clazz), configs);
Field parameterField = getOnlyField(clazz, Parameter.class);
checkArgument(parameterField != null, "No @ConfigSuite.Parameter found");
Field nameField = getOnlyField(clazz, Name.class);
List<Runner> result = Lists.newArrayListWithCapacity(configs.size() + 1);
try {
result.add(new ConfigRunner(clazz, parameterField, nameField, null, callConfigMethod(defaultConfig)));
for (Method m : configs) {
result.add(new ConfigRunner(clazz, parameterField, nameField, m.getName(), callConfigMethod(m)));
}
for (Map.Entry<String, org.eclipse.jgit.lib.Config> e : configMap.entrySet()) {
result.add(new ConfigRunner(clazz, parameterField, nameField, e.getKey(), e.getValue()));
}
return result;
} catch (InitializationError e) {
System.err.println("Errors initializing runners:");
for (Throwable t : e.getCauses()) {
t.printStackTrace();
}
throw new RuntimeException(e);
}
}
use of org.junit.runners.model.InitializationError in project pact-jvm by DiUS.
the class PactRunner method getPactSource.
protected PactLoader getPactSource(final TestClass clazz) throws InitializationError {
final PactSource pactSource = clazz.getAnnotation(PactSource.class);
final List<Annotation> pactLoaders = Arrays.stream(clazz.getAnnotations()).filter(annotation -> annotation.annotationType().getAnnotation(PactSource.class) != null).collect(toList());
if ((pactSource == null ? 0 : 1) + pactLoaders.size() != 1) {
throw new InitializationError("Exactly one pact source should be set");
}
try {
if (pactSource != null) {
final Class<? extends PactLoader> pactLoaderClass = pactSource.value();
try {
// Checks if there is a constructor with one argument of type Class.
final Constructor<? extends PactLoader> contructorWithClass = pactLoaderClass.getDeclaredConstructor(Class.class);
contructorWithClass.setAccessible(true);
return contructorWithClass.newInstance(clazz.getJavaClass());
} catch (NoSuchMethodException e) {
LOGGER.error(e.getMessage(), e);
return pactLoaderClass.newInstance();
}
} else {
final Annotation annotation = pactLoaders.iterator().next();
return annotation.annotationType().getAnnotation(PactSource.class).value().getConstructor(annotation.annotationType()).newInstance(annotation);
}
} catch (final InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
LOGGER.error("Error while creating pact source", e);
throw new InitializationError(e);
}
}
use of org.junit.runners.model.InitializationError in project drools-wb by kiegroup.
the class ScenarioRunnerService method run.
public TestScenarioResult run(final String identifier, final Scenario scenario, final KieModule module) {
try {
final HashMap<String, KieSession> ksessions = new HashMap<String, KieSession>();
final String ksessionName = getKSessionName(scenario.getKSessions());
ksessions.put(ksessionName, loadKSession(module, ksessionName));
final AuditLogger auditLogger = new AuditLogger(ksessions);
final ScenarioRunner4JUnit scenarioRunner = new ScenarioRunner4JUnit(scenario, ksessions, getMaxRuleFirings());
run(identifier, scenarioRunner, defaultTestResultMessageEvent);
return new TestScenarioResult(scenario, auditLogger.getLog());
} catch (InitializationError initializationError) {
throw new GenericPortableException(initializationError.getMessage());
}
}
use of org.junit.runners.model.InitializationError in project janusgraph by JanusGraph.
the class BerkeleyProcessStandardSuite method getTestList.
private static Class<?>[] getTestList() throws InitializationError {
try {
final Field field = ProcessStandardSuite.class.getDeclaredField("allTests");
field.setAccessible(true);
return (Class<?>[]) ArrayUtils.removeElement((Class<?>[]) field.get(null), TraversalInterruptionTest.class);
} catch (ReflectiveOperationException e) {
throw new InitializationError("Unable to create test list");
}
}
Aggregations