Esempio n. 1
0
  @Test
  public void testLoadInterface() {
    Extension e = new Extension();
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    e.setInterfaceName("no.such.Extension");
    try {
      e.loadInterface(cl);
    } catch (ExtensionException ex) {
      assertTrue(
          "ExtensionException does not wrap ClassNotFoundException",
          ex.getCause() instanceof ClassNotFoundException);
    }

    e.setInterfaceName(Assert.class.getName());
    Class<?> cls = e.loadInterface(cl);
    assertTrue("Object is not type Class", cls instanceof Class);
  }
Esempio n. 2
0
  @Test
  public void testLoad() throws ExtensionException {
    Extension e = new Extension();
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    e.setClassname("no.such.Extension");
    try {
      e.load(cl, null);
    } catch (ExtensionException ex) {
      assertTrue(
          "ExtensionException does not wrap ClassNotFoundException",
          ex.getCause() instanceof ClassNotFoundException);
    }

    e.setClassname("java.lang.System");
    try {
      e.load(cl, null);
    } catch (ExtensionException ex) {
      assertTrue(
          "ExtensionException does not wrap IllegalAccessException",
          ex.getCause() instanceof IllegalAccessException);
    }
    e.setClassname(MyServiceConstructorThrowsException.class.getName());
    try {
      e.load(cl, null);
    } catch (ExtensionException ex) {
      assertTrue(
          "ExtensionException does not wrap InstantiationException",
          ex.getCause() instanceof InstantiationException);
    }
    e.setClassname("java.lang.String");
    Object obj = e.load(cl, null);
    assertTrue("Object is not type String", obj instanceof String);
  }