use of org.mockito.exceptions.misusing.MockitoConfigurationException in project j2objc by google.
the class ClassPathLoader method loadImplementations.
/**
* Equivalent to {@link java.util.ServiceLoader#load} but without requiring
* Java 6 / Android 2.3 (Gingerbread).
*/
static <T> List<T> loadImplementations(Class<T> service) {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (loader == null) {
loader = ClassLoader.getSystemClassLoader();
}
Enumeration<URL> resources;
try {
resources = loader.getResources("mockito-extensions/" + service.getName());
} catch (IOException e) {
throw new MockitoException("Failed to load " + service, e);
}
List<T> result = new ArrayList<T>();
for (URL resource : Collections.list(resources)) {
InputStream in = null;
try {
in = resource.openStream();
for (String line : readerToLines(new InputStreamReader(in, "UTF-8"))) {
String name = stripCommentAndWhitespace(line);
if (name.length() != 0) {
result.add(service.cast(loader.loadClass(name).newInstance()));
}
}
} catch (Exception e) {
throw new MockitoConfigurationException("Failed to load " + service + " using " + resource, e);
} finally {
closeQuietly(in);
}
}
return result;
}
Aggregations