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 graal by oracle.
the class SLTestRunner method createTests.
protected static List<TestCase> createTests(final Class<?> c) throws IOException, InitializationError {
SLTestSuite suite = c.getAnnotation(SLTestSuite.class);
if (suite == null) {
throw new InitializationError(String.format("@%s annotation required on class '%s' to run with '%s'.", SLTestSuite.class.getSimpleName(), c.getName(), SLTestRunner.class.getSimpleName()));
}
String[] paths = suite.value();
Class<?> testCaseDirectory = c;
if (suite.testCaseDirectory() != SLTestSuite.class) {
testCaseDirectory = suite.testCaseDirectory();
}
Path root = getRootViaResourceURL(testCaseDirectory, paths);
if (root == null) {
for (String path : paths) {
Path candidate = FileSystems.getDefault().getPath(path);
if (Files.exists(candidate)) {
root = candidate;
break;
}
}
}
if (root == null && paths.length > 0) {
throw new FileNotFoundException(paths[0]);
}
final Path rootPath = root;
final List<TestCase> foundCases = new ArrayList<>();
Files.walkFileTree(rootPath, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path sourceFile, BasicFileAttributes attrs) throws IOException {
String sourceName = sourceFile.getFileName().toString();
if (sourceName.endsWith(SOURCE_SUFFIX)) {
String baseName = sourceName.substring(0, sourceName.length() - SOURCE_SUFFIX.length());
Path inputFile = sourceFile.resolveSibling(baseName + INPUT_SUFFIX);
String testInput = "";
if (Files.exists(inputFile)) {
testInput = readAllLines(inputFile);
}
Path outputFile = sourceFile.resolveSibling(baseName + OUTPUT_SUFFIX);
String expectedOutput = "";
if (Files.exists(outputFile)) {
expectedOutput = readAllLines(outputFile);
}
foundCases.add(new TestCase(c, baseName, sourceName, sourceFile, testInput, expectedOutput));
}
return FileVisitResult.CONTINUE;
}
});
return foundCases;
}
use of org.junit.runners.model.InitializationError in project xwiki-platform by xwiki.
the class ArchiveSuite method createRunners.
/**
* Read the archive and build a list of runners for its content.
*
* @param archivePath path to the archive to use
* @return a list of test runners
* @throws InitializationError on errors
*/
private List<Runner> createRunners(String archivePath) throws InitializationError {
File archiveFile = new File(archivePath);
if (!archiveFile.exists()) {
throw new InitializationError("Not a file or directory ({" + archivePath + "])");
}
List<Runner> list = new ArrayList<Runner>();
if (archiveFile.isDirectory()) {
createRunners(archiveFile, list);
} else {
try {
final ZipFile archive = new ZipFile(archivePath);
Enumeration<? extends ZipEntry> entries = archive.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
if (entry.isDirectory()) {
continue;
}
Reader reader = new InputStreamReader(archive.getInputStream(entry));
addTest(list, entry.getName(), reader);
}
archive.close();
} catch (IOException exception) {
throw new InitializationError(exception);
}
}
return list;
}
use of org.junit.runners.model.InitializationError in project st-js by st-js.
the class JUnitSession method startInParallel.
private void startInParallel(Collection<? extends AsyncProcess> processes) throws InitializationError {
List<Thread> threads = new ArrayList<Thread>();
final List<Throwable> errors = new CopyOnWriteArrayList<Throwable>();
// start all the dependencies in parallel
for (final AsyncProcess proc : processes) {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
proc.start();
} catch (Exception e) {
errors.add(e);
}
}
});
t.start();
threads.add(t);
}
// dependencies have started (or failed to start)
for (Thread t : threads) {
try {
t.join();
} catch (InterruptedException e) {
throw new InitializationError(e);
}
}
// check if any of the dependencies has failed to start. If some did, throw an exception
if (!errors.isEmpty()) {
throw new InitializationError(errors);
}
}
Aggregations