@Test
public void loadServiceClass() throws Exception {

    // load from context loader
    assertNull(ClassLoaderUtil.loadServiceClass(null));
    try {
        ClassLoaderUtil.loadServiceClass("myservice.notexist");
        fail("expected ServiceNotFoundException");
    } catch (ServiceNotFoundException e) {
    }
    try {
        ClassLoaderUtil.loadServiceClass("myservice.notfound");
        fail("expected ClassNotFoundException");
    } catch (ClassNotFoundException e) {
        assertFalse(e instanceof ServiceNotFoundException);
    }
    assertEquals(MyService.class, ClassLoaderUtil.loadServiceClass("myservice"));
    // load from class referrer
    assertNull(ClassLoaderUtil.loadServiceClass(null, getClass()));
    assertNull(ClassLoaderUtil.loadServiceClass(null, (Class<?>) null));
    try {
        ClassLoaderUtil.loadServiceClass("myservice.notexist", getClass());
        fail("expected ServiceNotFoundException");
    } catch (ServiceNotFoundException e) {
    }
    try {
        ClassLoaderUtil.loadServiceClass("myservice.notfound", getClass());
        fail("expected ClassNotFoundException");
    } catch (ClassNotFoundException e) {
        assertFalse(e instanceof ServiceNotFoundException);
    }
    try {
        ClassLoaderUtil.loadServiceClass("myservice.notexist", (Class<?>) null);
        fail("expected ServiceNotFoundException");
    } catch (ServiceNotFoundException e) {
    }
    try {
        ClassLoaderUtil.loadServiceClass("myservice.notfound", (Class<?>) null);
        fail("expected ClassNotFoundException");
    } catch (ClassNotFoundException e) {
        assertFalse(e instanceof ServiceNotFoundException);
    }
    assertEquals(MyService.class, ClassLoaderUtil.loadServiceClass("myservice", getClass()));
    assertEquals(MyService.class, ClassLoaderUtil.loadServiceClass("myservice", (Class<?>) null));
    // load from specified loader
    assertNull(ClassLoaderUtil.loadServiceClass(null, getClass().getClassLoader()));
    assertNull(ClassLoaderUtil.loadServiceClass(null, (ClassLoader) null));
    try {
        ClassLoaderUtil.loadServiceClass("myservice.notexist", getClass().getClassLoader());
        fail("expected ServiceNotFoundException");
    } catch (ServiceNotFoundException e) {
    }
    try {
        ClassLoaderUtil.loadServiceClass("myservice.notfound", getClass().getClassLoader());
        fail("expected ClassNotFoundException");
    } catch (ClassNotFoundException e) {
        assertFalse(e instanceof ServiceNotFoundException);
    }
    try {
        ClassLoaderUtil.loadServiceClass("myservice.notexist", (ClassLoader) null);
        fail("expected ServiceNotFoundException");
    } catch (ServiceNotFoundException e) {
    }
    try {
        ClassLoaderUtil.loadServiceClass("myservice.notfound", (ClassLoader) null);
        fail("expected ClassNotFoundException");
    } catch (ClassNotFoundException e) {
        assertFalse(e instanceof ServiceNotFoundException);
    }
    assertEquals(MyService.class, ClassLoaderUtil.loadServiceClass("myservice", getClass().getClassLoader()));
    assertEquals(MyService.class, ClassLoaderUtil.loadServiceClass("myservice", (ClassLoader) null));
    try {
        assertEquals(MyService.class, ClassLoaderUtil.loadServiceClass("com.baidu.unbiz.common.sample.MyService",
                getClass().getClassLoader()));
        fail("expected ServiceNotFoundException");
    } catch (ServiceNotFoundException e) {
    }
    try {
        assertEquals(MyService.class,
                ClassLoaderUtil.loadServiceClass("com.baidu.unbiz.common.sample.MyService", (ClassLoader) null));
        fail("expected ServiceNotFoundException");
    } catch (ServiceNotFoundException e) {
    }
}