01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: package org.apache.tools.ant.util;
20:
21: import java.io.IOException;
22: import java.util.Enumeration;
23:
24: import junit.framework.TestCase;
25:
26: import org.apache.tools.ant.BuildException;
27: import org.apache.tools.ant.Project;
28: import org.apache.tools.ant.types.Path;
29:
30: /**
31: * Test case for ClasspathUtils
32: *
33: */
34: public class ClasspathUtilsTest extends TestCase {
35:
36: private Project p;
37:
38: public ClasspathUtilsTest(String name) {
39: super (name);
40: }
41:
42: public void setUp() {
43: p = new Project();
44: p.init();
45: }
46:
47: public void testOnlyOneInstance() {
48: Enumeration enumeration;
49: String list = "";
50: ClassLoader c = ClasspathUtils.getUniqueClassLoaderForPath(p,
51: (Path) null, false);
52: try {
53: enumeration = c
54: .getResources("org/apache/tools/ant/taskdefs/defaults.properties");
55: } catch (IOException e) {
56: throw new BuildException(
57: "Could not get the defaults.properties resource");
58: }
59: int count = 0;
60: while (enumeration.hasMoreElements()) {
61: list = list + " " + enumeration.nextElement();
62: count++;
63: }
64: assertTrue("Should be only one and not " + count + " " + list,
65: count == 1);
66: }
67: }
|