http://vis.cs.ucdavis.edu/~ogawa/codeswarm/
于是RMS跳出来了,说,那视频的格式呢?我们一定要坚持使用自由的格式,
比如OGG格式。
谁还坚持这个原则呢?还有谁呢?
http://vis.cs.ucdavis.edu/~ogawa/codeswarm/
于是RMS跳出来了,说,那视频的格式呢?我们一定要坚持使用自由的格式,
比如OGG格式。
谁还坚持这个原则呢?还有谁呢?
下面两个方法使`latestUserDefinedLoader'的测试变得容易:
,----[ Class LatestUserDefinedLoaderUtil ]
| public static ClassLoader latestUserDefinedLoader() throws Exception {
| ClassLoader latestUserDefinedLoader = (ClassLoader) invokeStaticMethod(
| ObjectInputStream.class, "latestUserDefinedLoader");
| return latestUserDefinedLoader;
| }
|
| public static Object invokeStaticMethod(Class klass, String name)
| throws Exception {
| Method method = klass.getDeclaredMethod(name, new Class[0]);
| method.setAccessible(true);
| return method.invoke(null, null);
| }
`----
为了测试latestUserDefinedLoader的行为,再增加两个方法:
,----[ Class LatestUserDefinedLoaderUtil Continue ]
| public static String getClassName() {
| return LatestUserDefinedLoaderUtil.class.getName();
| }
|
| public static URL getResource() throws Exception {
| String resName = getClassName().replace('.', '/') + ".class";
| String resource = Thread.currentThread().getContextClassLoader().getResource(resName).toString();
| return new URL(resource.substring(0, resource.indexOf(resName)));
| }
`----
下面是一个不那么复杂的测试用例:
,----
| public void testLatestUserDefinedLoader() throws Exception {
| URL[] urls = new URL[1];
| urls[0] = LatestUserDefinedLoaderUtil.getResource();
| System.out.println(urls[0]);
| ClassLoader classLoader = new URLClassLoader(urls, null);
| Class klass = LatestUserDefinedLoaderUtil.class;
| Class theKlass = classLoader.loadClass(LatestUserDefinedLoaderUtil.getClassName());
| assertNotNull(theKlass);
| ClassLoader latestUserDefinedLoader = (ClassLoader)
| LatestUserDefinedLoaderUtil.invokeStaticMethod(theKlass, "latestUserDefinedLoader");
| assertEquals(classLoader, latestUserDefinedLoader);
| }
`----