01: // Copyright 2005 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.hivemind.impl;
16:
17: import java.net.URL;
18: import java.net.URLClassLoader;
19:
20: import org.apache.hivemind.test.HiveMindTestCase;
21:
22: /**
23: * @author James Carman
24: * @version 1.0
25: */
26: public class TestMessageFormatter extends HiveMindTestCase {
27: public void testWithNoPackage() throws Exception {
28: final ClassLoader loader = new NoPackageClassLoader();
29:
30: new MessageFormatter(loader
31: .loadClass(TestMessageFormatter.class.getName()),
32: "MessageFinder");
33: }
34:
35: private class NoPackageClassLoader extends URLClassLoader {
36:
37: public NoPackageClassLoader() {
38: super (new URL[] { TestMessageFormatter.class
39: .getProtectionDomain().getCodeSource()
40: .getLocation() });
41: }
42:
43: protected Package getPackage(String name) {
44: return null;
45: }
46:
47: public Class loadClass(String name)
48: throws ClassNotFoundException {
49: try {
50: return findClass(name);
51: } catch (ClassNotFoundException e) {
52: return super.loadClass(name);
53: }
54:
55: }
56: }
57: }
|