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;
|
---|
19 |
|
---|
20 | import java.io.File;
|
---|
21 | import java.io.IOException;
|
---|
22 | import java.net.URL;
|
---|
23 | import java.util.ArrayList;
|
---|
24 | import java.util.Arrays;
|
---|
25 | import java.util.Collections;
|
---|
26 | import java.util.Enumeration;
|
---|
27 | import java.util.List;
|
---|
28 | import junit.framework.TestCase;
|
---|
29 | import org.apache.tools.ant.BuildException;
|
---|
30 | import org.apache.tools.ant.Project;
|
---|
31 | import org.apache.tools.ant.types.Path;
|
---|
32 | import org.apache.tools.ant.util.FileUtils;
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Test case for ant class loader
|
---|
36 | *
|
---|
37 | */
|
---|
38 | public class AntClassLoaderTest extends TestCase {
|
---|
39 |
|
---|
40 | private Project p;
|
---|
41 |
|
---|
42 | public AntClassLoaderTest(String name) {
|
---|
43 | super(name);
|
---|
44 | }
|
---|
45 |
|
---|
46 | public void setUp() {
|
---|
47 | p = new Project();
|
---|
48 | p.init();
|
---|
49 | }
|
---|
50 |
|
---|
51 | public void testCleanup() throws BuildException {
|
---|
52 | Path path = new Path(p, ".");
|
---|
53 | AntClassLoader loader = new AntClassLoader(p, path);
|
---|
54 | try {
|
---|
55 | // we don't expect to find this
|
---|
56 | loader.findClass("fubar");
|
---|
57 | fail("Did not expect to find fubar class");
|
---|
58 | } catch (ClassNotFoundException e) {
|
---|
59 | // ignore expected
|
---|
60 | }
|
---|
61 |
|
---|
62 | loader.cleanup();
|
---|
63 | try {
|
---|
64 | // we don't expect to find this
|
---|
65 | loader.findClass("fubar");
|
---|
66 | fail("Did not expect to find fubar class");
|
---|
67 | } catch (ClassNotFoundException e) {
|
---|
68 | // ignore expected
|
---|
69 | } catch (NullPointerException e) {
|
---|
70 | fail("loader should not fail even if cleaned up");
|
---|
71 | }
|
---|
72 |
|
---|
73 | // tell the build it is finished
|
---|
74 | p.fireBuildFinished(null);
|
---|
75 | try {
|
---|
76 | // we don't expect to find this
|
---|
77 | loader.findClass("fubar");
|
---|
78 | fail("Did not expect to find fubar class");
|
---|
79 | } catch (ClassNotFoundException e) {
|
---|
80 | // ignore expected
|
---|
81 | } catch (NullPointerException e) {
|
---|
82 | fail("loader should not fail even if project finished");
|
---|
83 | }
|
---|
84 | }
|
---|
85 | }
|
---|