@Test
public void newInstance() throws Exception {

    // load from context loader
    assertNull(ClassLoaderUtil.newInstance((String) null));
    assertNull(ClassLoaderUtil.newInstance((Class<?>) null));
    assertInstance(String.class, ClassLoaderUtil.newInstance("java.lang.String"));
    try {
        ClassLoaderUtil.newInstance("com.baidu.unbiz.common.sample.MyErrorService");
        fail("Expected ClassInstantiationException");
    } catch (ClassInstantiationException e) {
    }
    // load from class referrer
    assertNull(ClassLoaderUtil.newInstance(null, getClass()));
    assertNull(ClassLoaderUtil.newInstance(null, (Class<?>) null));
    assertInstance(String.class, ClassLoaderUtil.newInstance("java.lang.String", getClass()));
    assertInstance(String.class, ClassLoaderUtil.newInstance("java.lang.String", (Class<?>) null));
    try {
        ClassLoaderUtil.newInstance("com.baidu.unbiz.common.sample.MyErrorService", getClass());
        fail("Expected ClassInstantiationException");
    } catch (ClassInstantiationException e) {
    }
    // load from specified loader
    assertNull(ClassLoaderUtil.newInstance(null, getClass().getClassLoader()));
    assertNull(ClassLoaderUtil.newInstance(null, (ClassLoader) null));
    assertInstance(String.class, ClassLoaderUtil.newInstance("java.lang.String", getClass().getClassLoader()));
    assertInstance(String.class, ClassLoaderUtil.newInstance("java.lang.String", (ClassLoader) null));
    try {
        ClassLoaderUtil.newInstance("com.baidu.unbiz.common.sample.MyErrorService", getClass().getClassLoader());
        fail("Expected ClassInstantiationException");
    } catch (ClassInstantiationException e) {
    }
}