1 | /*
|
---|
2 | * Copyright 2000-2002,2004 The Apache Software Foundation
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | *
|
---|
16 | */
|
---|
17 |
|
---|
18 | package org.apache.tools.ant.util;
|
---|
19 |
|
---|
20 | import java.io.File;
|
---|
21 | import java.io.IOException;
|
---|
22 | import java.util.Enumeration;
|
---|
23 | import junit.framework.TestCase;
|
---|
24 |
|
---|
25 | import org.apache.tools.ant.BuildException;
|
---|
26 | import org.apache.tools.ant.Project;
|
---|
27 | import org.apache.tools.ant.types.Path;
|
---|
28 |
|
---|
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 |
|
---|
48 | public void testOnlyOneInstance() {
|
---|
49 | Enumeration enumeration;
|
---|
50 | String list = "";
|
---|
51 | ClassLoader c = ClasspathUtils.getUniqueClassLoaderForPath(p, (Path) null, false);
|
---|
52 | try {
|
---|
53 | enumeration = c.getResources(
|
---|
54 | "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, count == 1);
|
---|
65 | }
|
---|
66 | }
|
---|