use of org.junit.runners.Parameterized in project service-proxy by membrane.
the class ResolverTestTriggerTest method handleRequest.
@Override
public Outcome handleRequest(Exchange exc) {
try {
Class<?> clazz = Class.forName("com.predic8.membrane.core.resolver.ResolverTest");
clazz.getField("deployment").set(null, "J2EE");
Object value = router.getResolverMap().getFileSchemaResolver();
Object resolverMap = clazz.getField("resolverMap").get(null);
resolverMap.getClass().getMethod("addSchemaResolver", SchemaResolver.class).invoke(resolverMap, value);
Parameterized p = new Parameterized(clazz);
JUnitCore c = new JUnitCore();
Result run = c.run(Request.runner(p));
StringBuilder sb = new StringBuilder();
sb.append(MAGIC);
for (Failure f : run.getFailures()) {
sb.append(f.toString());
StringWriter stringWriter = new StringWriter();
f.getException().printStackTrace(new PrintWriter(stringWriter));
sb.append(stringWriter.toString());
sb.append("\n");
sb.append("\n");
}
exc.setResponse(Response.ok().header(Header.CONTENT_TYPE, MimeType.TEXT_PLAIN_UTF8).body(sb.toString()).build());
} catch (Throwable t) {
LOG.error(t.getMessage(), t);
}
return Outcome.RETURN;
}
use of org.junit.runners.Parameterized in project hbase by apache.
the class HBaseClassTestRule method getNumParameters.
/**
* @param clazz Test class that is running.
* @return the number of parameters for this given test class. If the test is not parameterized or
* if there is any issue determining the number of parameters, returns 1.
*/
static int getNumParameters(Class<?> clazz) {
RunWith[] runWiths = clazz.getAnnotationsByType(RunWith.class);
boolean testParameterized = runWiths != null && Arrays.stream(runWiths).anyMatch((r) -> r.value().equals(Parameterized.class));
if (!testParameterized) {
return 1;
}
for (Method method : clazz.getMethods()) {
if (!isParametersMethod(method)) {
continue;
}
// Found the parameters method. Figure out the number of parameters.
Object parameters;
try {
parameters = method.invoke(clazz);
} catch (IllegalAccessException | InvocationTargetException e) {
LOG.warn("Error invoking parameters method {} in test class {}", method.getName(), clazz, e);
continue;
}
if (parameters instanceof List) {
return ((List) parameters).size();
} else if (parameters instanceof Collection) {
return ((Collection) parameters).size();
} else if (parameters instanceof Iterable) {
return Iterables.size((Iterable) parameters);
} else if (parameters instanceof Object[]) {
return ((Object[]) parameters).length;
}
}
LOG.warn("Unable to determine parameters size. Returning the default of 1.");
return 1;
}
Aggregations