1 package com.atlassian.plugin.classloader;
2
3 import junit.framework.TestCase;
4
5
6
7
8 public class TestDelegationClassLoader extends TestCase {
9
10 public void testLoadSystemClassWithOutDelegateSet() throws ClassNotFoundException {
11 DelegationClassLoader classLoader = new DelegationClassLoader();
12 Class c = classLoader.loadClass("java.lang.String");
13 assertNotNull(c);
14 }
15
16 public void testLoadSystemClassWithDelegateSet() throws ClassNotFoundException {
17 ClassLoader parentClassLoader = TestDelegationClassLoader.class.getClassLoader();
18 DelegationClassLoader classLoader = new DelegationClassLoader();
19 classLoader.setDelegateClassLoader(parentClassLoader);
20 Class c = classLoader.loadClass("java.lang.String");
21 assertNotNull(c);
22 }
23
24 public void testCantLoadUnknownClassWithOutDelegateSet() {
25 DelegationClassLoader classLoader = new DelegationClassLoader();
26 try {
27 classLoader.loadClass("not.a.real.class.path.NotARealClass");
28 fail("ClassNotFoundException expected");
29 } catch (ClassNotFoundException e) {
30
31 }
32 }
33
34 public void testCantLoadUnknownClassWithDelegateSet() {
35 ClassLoader parentClassLoader = TestDelegationClassLoader.class.getClassLoader();
36 DelegationClassLoader classLoader = new DelegationClassLoader();
37 classLoader.setDelegateClassLoader(parentClassLoader);
38 try {
39 classLoader.loadClass("not.a.real.class.path.NotARealClass");
40 fail("ClassNotFoundException expected");
41 } catch (ClassNotFoundException e) {
42
43 }
44 }
45
46 public void testCantSetNullDelegate() {
47 DelegationClassLoader dcl = new DelegationClassLoader();
48 try {
49 dcl.setDelegateClassLoader(null);
50 fail("expected IllegalArgumentException with null delegate");
51 } catch (NullPointerException e) {
52
53 }
54 }
55
56 public void testCanSetDelegate() {
57 DelegationClassLoader dcl = new DelegationClassLoader();
58 dcl.setDelegateClassLoader(getClass().getClassLoader());
59 }
60
61 }