@TestTargetNew(
      level = TestLevel.COMPLETE,
      notes = "",
      method = "loadClass",
      args = {java.lang.String.class, boolean.class})
  public void test_loadClassLjava_lang_StringLZ()
      throws IllegalAccessException, InstantiationException, ClassNotFoundException {
    PackageClassLoader pcl = new PackageClassLoader(getClass().getClassLoader());
    String className = getClass().getPackage().getName() + ".A";

    Class<?> clazz = pcl.loadClass(className, false);
    assertEquals(className, clazz.getName());
    assertNotNull(clazz.newInstance());

    clazz = pcl.loadClass(className, true);
    assertEquals(className, clazz.getName());
    assertNotNull(clazz.newInstance());

    try {
      clazz = pcl.loadClass("UnknownClass", false);
      assertEquals("TestClass", clazz.getName());
      fail("ClassNotFoundException was not thrown.");
    } catch (ClassNotFoundException e) {
      // expected
    }
  }
  @TestTargetNew(
      level = TestLevel.COMPLETE,
      notes = "",
      method = "findSystemClass",
      args = {java.lang.String.class})
  public void test_findSystemClass() {
    PackageClassLoader pcl = new PackageClassLoader(getClass().getClassLoader());

    Class[] classes = {String.class, Integer.class, Object.class, Object[].class};

    for (Class clazz : classes) {
      try {
        String className = clazz.getName();
        assertEquals(clazz, pcl.findSystemClazz(className));
      } catch (ClassNotFoundException cnfe) {
        fail("ClassNotFoundException was thrown: " + cnfe.getMessage());
      }
    }
    try {
      pcl.findSystemClazz("unknownClass");
      fail("ClassNotFoundException was not thrown.");
    } catch (ClassNotFoundException cnfe) {
      // expected
    }
  }
 @TestTargetNew(
     level = TestLevel.COMPLETE,
     notes = "",
     method = "findLibrary",
     args = {java.lang.String.class})
 @AndroidOnly("findLibrary method is not supported, it returns null.")
 public void test_findLibrary() {
   PackageClassLoader pcl = new PackageClassLoader(getClass().getClassLoader());
   assertNull(pcl.findLibrary("libjvm.so"));
 }
  @TestTargetNew(
      level = TestLevel.COMPLETE,
      notes = "",
      method = "getPackages",
      args = {})
  @KnownFailure(
      "The package canot be found. Seems like the cache is not "
          + "shared between the class loaders. But this test seems to "
          + "expect exactly that. this tests works on the RI.")
  public void test_getPackages() {

    PackageClassLoader pcl = new PackageClassLoader(getClass().getClassLoader());

    String[] packageProperties = {
      "test.package", "title", "1.0", "Vendor", "Title", "1.1", "implementation vendor"
    };

    URL url = null;
    try {
      url = new URL("file:");
    } catch (MalformedURLException e) {
      fail("MalformedURLException was thrown.");
    }
    pcl.definePackage(
        packageProperties[0],
        packageProperties[1],
        packageProperties[2],
        packageProperties[3],
        packageProperties[4],
        packageProperties[5],
        packageProperties[6],
        url);

    Package[] packages = pcl.getPackages();
    assertTrue(packages.length != 0);

    pcl = new PackageClassLoader(getClass().getClassLoader());
    packages = pcl.getPackages();
    assertNotNull(packages);

    boolean isThisFound = false;
    for (Package p : packages) {
      if (p.equals(getClass().getPackage())) {
        isThisFound = true;
      }
    }
    assertTrue(isThisFound);
  }
  @TestTargetNew(
      level = TestLevel.COMPLETE,
      notes = "",
      method = "findLoadedClass",
      args = {java.lang.String.class})
  public void test_findLoadedClass() {
    PackageClassLoader pcl = new PackageClassLoader(getClass().getClassLoader());

    Class[] classes = {A.class, PublicTestClass.class, TestAnnotation.class, TestClass1.class};

    for (Class clazz : classes) {
      String className = clazz.getName();
      assertNull(pcl.findLoadedClazz(className));
    }

    assertNull(pcl.findLoadedClazz("unknownClass"));
  }
  @TestTargetNew(
      level = TestLevel.COMPLETE,
      notes = "",
      method = "getPackage",
      args = {java.lang.String.class})
  @KnownFailure("PackageClassLoader.getPackage returns null.")
  public void test_getPackageLjava_lang_String() {
    PackageClassLoader pcl = new PackageClassLoader(getClass().getClassLoader());

    String[] packageProperties = {
      "test.package", "title", "1.0", "Vendor", "Title", "1.1", "implementation vendor"
    };

    URL url = null;
    try {
      url = new URL("file:");
    } catch (MalformedURLException e) {
      fail("MalformedURLException was thrown.");
    }
    pcl.definePackage(
        packageProperties[0],
        packageProperties[1],
        packageProperties[2],
        packageProperties[3],
        packageProperties[4],
        packageProperties[5],
        packageProperties[6],
        url);

    assertNotNull(pcl.getPackage(packageProperties[0]));

    assertEquals(
        "should define current package",
        getClass().getPackage(),
        pcl.getPackage(getClass().getPackage().getName()));

    assertNull(pcl.getPackage("not.found.package"));
  }
  @TestTargetNew(
      level = TestLevel.COMPLETE,
      notes = "",
      method = "findClass",
      args = {java.lang.String.class})
  @AndroidOnly("findClass method throws ClassNotFoundException exception.")
  public void test_findClass() {

    try {
      PackageClassLoader pcl = new PackageClassLoader(getClass().getClassLoader());
      pcl.findClass(getClass().getPackage().getName() + ".A");
      fail("ClassNotFoundException was not thrown.");
    } catch (ClassNotFoundException cnfe) {
      // expected
    }

    try {
      PackageClassLoader pcl = new PackageClassLoader(getClass().getClassLoader());
      pcl.findClass("TestClass");
      fail("ClassNotFoundException was not thrown.");
    } catch (ClassNotFoundException cnfe) {
      // expected
    }
  }
  @TestTargetNew(
      level = TestLevel.COMPLETE,
      notes = "",
      method = "definePackage",
      args = {
        java.lang.String.class, java.lang.String.class,
        java.lang.String.class, java.lang.String.class,
        java.lang.String.class, java.lang.String.class,
        java.lang.String.class, java.net.URL.class
      })
  public void test_definePackage() {

    PackageClassLoader pcl = new PackageClassLoader(getClass().getClassLoader());

    String[] packageProperties = {
      "test.package", "title", "1.0", "Vendor", "Title", "1.1", "implementation vendor"
    };

    URL url = null;
    try {
      url = new URL("file:");
    } catch (MalformedURLException e) {
      fail("MalformedURLException was thrown.");
    }
    pcl.definePackage(
        packageProperties[0],
        packageProperties[1],
        packageProperties[2],
        packageProperties[3],
        packageProperties[4],
        packageProperties[5],
        packageProperties[6],
        url);

    Package pack = pcl.getPackage(packageProperties[0]);
    assertEquals(packageProperties[1], pack.getSpecificationTitle());
    assertEquals(packageProperties[2], pack.getSpecificationVersion());
    assertEquals(packageProperties[3], pack.getSpecificationVendor());
    assertEquals(packageProperties[4], pack.getImplementationTitle());
    assertEquals(packageProperties[5], pack.getImplementationVersion());
    assertEquals(packageProperties[6], pack.getImplementationVendor());
    assertTrue(pack.isSealed(url));
    assertTrue(pack.isSealed());

    try {
      pcl.definePackage(
          packageProperties[0],
          packageProperties[1],
          packageProperties[2],
          packageProperties[3],
          packageProperties[4],
          packageProperties[5],
          packageProperties[6],
          null);
      fail("IllegalArgumentException was not thrown.");
    } catch (IllegalArgumentException iae) {
      // expected
    }

    pcl.definePackage("test.package.test", null, null, null, null, null, null, null);
    pack = pcl.getPackage("test.package.test");
    assertNull(pack.getSpecificationTitle());
    assertNull(pack.getSpecificationVersion());
    assertNull(pack.getSpecificationVendor());
    assertNull(pack.getImplementationTitle());
    assertNull(pack.getImplementationVersion());
    assertNull(pack.getImplementationVendor());
    assertFalse(pack.isSealed());
  }