@Test
public void loadServiceClass_ClassNameServiceId() throws Exception {

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