KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > hivemind > impl > TestMessageFormatter


1 // Copyright 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// 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 JavaDoc;
18 import java.net.URLClassLoader JavaDoc;
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 {
28
29     public void testWithNoPackage()
30         throws Exception JavaDoc
31     {
32         final ClassLoader JavaDoc loader = new NoPackageClassLoader();
33
34         new MessageFormatter(loader.loadClass(MessageFormatterTarget.class.getName()), "MessageFinder");
35     }
36
37     private class NoPackageClassLoader extends URLClassLoader JavaDoc
38     {
39
40         public NoPackageClassLoader()
41         {
42             super(new URL JavaDoc[] { TestMessageFormatter.class.getProtectionDomain().getCodeSource().getLocation() });
43         }
44
45         protected Package JavaDoc getPackage(String JavaDoc name)
46         {
47             return null;
48         }
49
50         public Class JavaDoc loadClass(String JavaDoc name)
51             throws ClassNotFoundException JavaDoc
52         {
53             try
54             {
55                 return findClass(name);
56             }
57             catch (ClassNotFoundException JavaDoc e)
58             {
59                 return super.loadClass(name);
60             }
61
62         }
63     }
64 }
65
Popular Tags