1 15 package org.apache.hivemind.impl; 16 17 import java.net.URL ; 18 import java.util.HashMap ; 19 import java.util.Iterator ; 20 import java.util.List ; 21 22 import org.apache.hivemind.ApplicationRuntimeException; 23 import org.apache.hivemind.ClassResolver; 24 import org.apache.hivemind.test.HiveMindTestCase; 25 26 32 public class TestDefaultClassResolver extends HiveMindTestCase 33 { 34 public void testDefaultClassLoader() 35 { 36 ClassResolver cr = new DefaultClassResolver(); 37 38 assertSame(Thread.currentThread().getContextClassLoader(), cr.getClassLoader()); 39 } 40 41 public void testGetResource() 42 { 43 ClassResolver cr = new DefaultClassResolver(); 44 45 URL normal = cr.getResource("org/apache/hivemind/impl/Privates.xml"); 46 URL withSlash = cr.getResource("/org/apache/hivemind/impl/Privates.xml"); 47 48 URL expected = Thread.currentThread().getContextClassLoader().getResource( 49 "org/apache/hivemind/impl/Privates.xml"); 50 51 assertEquals(expected, normal); 52 assertEquals(expected, withSlash); 53 } 54 55 public void testFindClassSuccess() 56 { 57 ClassResolver cr = new DefaultClassResolver(); 58 59 assertEquals(HashMap .class, cr.findClass("java.util.HashMap")); 60 } 61 62 public void testFindClassFailure() 63 { 64 ClassResolver cr = new DefaultClassResolver(); 65 66 try 67 { 68 cr.findClass("com.foo.Xyzzyx"); 69 unreachable(); 70 } 71 catch (ApplicationRuntimeException ex) 72 { 73 assertExceptionSubstring(ex, "Could not load class com.foo.Xyzzyx "); 74 } 75 } 76 77 public void testFindClassPrimitive() 78 { 79 ClassResolver cr = new DefaultClassResolver(); 80 81 assertSame(boolean.class, cr.findClass("boolean")); 82 } 83 84 public void testCheckClassExists() 85 { 86 ClassResolver cr = new DefaultClassResolver(); 87 88 assertSame(Iterator .class, cr.findClass("java.util.Iterator")); 89 } 90 91 public void testCheckClassMissing() 92 { 93 ClassResolver cr = new DefaultClassResolver(); 94 95 assertNull(cr.checkForClass("java.lang.Qbert")); 96 } 97 98 public void testFindClassArray() 99 { 100 ClassResolver cr = new DefaultClassResolver(); 101 102 assertSame(List [].class, cr.findClass("java.util.List[]")); 103 assertSame(List [][].class, cr.findClass("java.util.List[][]")); 104 } 105 106 public void testFindPrimitiveArray() 107 { 108 ClassResolver cr = new DefaultClassResolver(); 109 110 assertSame(int[].class, cr.findClass("int[]")); 111 assertSame(int[][].class, cr.findClass("int[][]")); 112 } 113 } | Popular Tags |