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