Search in sources :

Example 1 with MockitoConfigurationException

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;
}
Also used : ArrayList(java.util.ArrayList) URL(java.net.URL) MockitoException(org.mockito.exceptions.base.MockitoException) MockitoConfigurationException(org.mockito.exceptions.misusing.MockitoConfigurationException) MockitoException(org.mockito.exceptions.base.MockitoException) MockitoConfigurationException(org.mockito.exceptions.misusing.MockitoConfigurationException)

Aggregations

URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 MockitoException (org.mockito.exceptions.base.MockitoException)1 MockitoConfigurationException (org.mockito.exceptions.misusing.MockitoConfigurationException)1