Java 类com.alibaba.fastjson.util.ServiceLoader 实例源码

项目:GitHub    文件:ServiceLoaderTest.java   
public void test_0() throws Exception {
    new ServiceLoader();
}
项目:GitHub    文件:ClassLoaderTest.java   
public void test_error() throws Exception {
    Field field = ServiceLoader.class.getDeclaredField("loadedUrls");
    field.setAccessible(true);
    Set<String> loadedUrls = (Set<String>) field.get(null);

    Thread.currentThread().setContextClassLoader(new MyClassLoader(new ClassCastException()));
    JSON.toJSONString(new A());

    loadedUrls.clear();

    Thread.currentThread().setContextClassLoader(new MyClassLoader(new IOException()));
    JSON.toJSONString(new B());

    loadedUrls.clear();

    Thread.currentThread().setContextClassLoader(new EmptyClassLoader());
    JSON.toJSONString(new C());

    loadedUrls.clear();

    Thread.currentThread().setContextClassLoader(new ErrorClassLoader());
    JSON.toJSONString(new D());

    loadedUrls.clear();

    Thread.currentThread().setContextClassLoader(ctxLoader);
    JSON.toJSONString(new E());
}