use of org.apache.jena.rdf.model.test.helpers.TestingModelFactory in project jena by apache.
the class AbstractTestPackage method addTest.
/**
* Adds a test to the test suite by looking for the standard test methods.
* These are
* methods that start with "test" and have no arguments.
*
* @param testClass
* @param constructorArgs
* @throws SecurityException
* @throws NoSuchMethodException
* @throws IllegalArgumentException
* @throws InstantiationException
* @throws IllegalAccessException
* @throws InvocationTargetException
*/
private void addTest(final Class<? extends TestCase> testClass, final Object... constructorArgs) {
final Object[] args = new Object[constructorArgs.length + 1];
System.arraycopy(constructorArgs, 0, args, 0, constructorArgs.length);
final List<Class<?>> parameterTypes = new ArrayList<>();
for (final Object o : constructorArgs) {
if (o instanceof TestingModelFactory) {
parameterTypes.add(TestingModelFactory.class);
} else {
parameterTypes.add(o.getClass());
}
}
parameterTypes.add(String.class);
Constructor<TestCase> c;
try {
@SuppressWarnings("unchecked") Constructor<TestCase> cc = (Constructor<TestCase>) testClass.getConstructor(parameterTypes.toArray(new Class[parameterTypes.size()]));
c = cc;
} catch (final SecurityException | NoSuchMethodException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage(), e);
}
for (final Method m : testClass.getMethods()) {
if (m.getParameterTypes().length == 0) {
if (m.getName().startsWith("test")) {
args[constructorArgs.length] = m.getName();
try {
addTest(c.newInstance(args));
} catch (final IllegalArgumentException | InvocationTargetException | IllegalAccessException | InstantiationException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage(), e);
}
}
}
}
}
Aggregations