KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > atest > jmock > ClassLoaderAcceptanceTest


1 /* Copyright (c) 2000-2004 jMock.org
2  */

3 package atest.jmock;
4
5 import org.jmock.MockObjectTestCase;
6 import org.objectweb.asm.ClassWriter;
7 import org.objectweb.asm.Constants;
8
9
10 public class ClassLoaderAcceptanceTest extends MockObjectTestCase
11 {
12
13     static class EmptyInterfaceCreator extends ClassLoader JavaDoc
14     {
15         protected Class JavaDoc findClass( String JavaDoc name ) {
16             ClassWriter writer = new ClassWriter(true);
17             writer.visit(Constants.ACC_PUBLIC | Constants.ACC_INTERFACE,
18                          name.replace('.', '/'),
19                          "java/lang/Object",
20                          null, /* interfaces */
21                          null /* source file */);
22
23             byte[] b = writer.toByteArray();
24
25             return defineClass(name, b, 0, b.length);
26         }
27     }
28
29     public void testMockingTypeFromOtherClassLoader() throws ClassNotFoundException JavaDoc {
30         ClassLoader JavaDoc interfaceClassLoader = new EmptyInterfaceCreator();
31         Class JavaDoc interfaceClass = interfaceClassLoader.loadClass("$UniqueTypeName$");
32
33         mock(interfaceClass); // Should not throw an exception
34
}
35 }
36
Popular Tags