source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/src/testcases/org/apache/tools/ant/taskdefs/optional/depend/DependTest.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 5.0 KB
Line 
1/*
2 * Copyright 2001-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
18package org.apache.tools.ant.taskdefs.optional.depend;
19
20import java.io.File;
21import java.io.FileReader;
22import java.io.IOException;
23import java.util.Date;
24import java.util.Vector;
25import java.util.Enumeration;
26import java.util.Hashtable;
27import org.apache.tools.ant.BuildFileTest;
28import org.apache.tools.ant.Project;
29import org.apache.tools.ant.types.FileSet;
30import org.apache.tools.ant.DirectoryScanner;
31
32/**
33 * Testcase for the Depend optional task.
34 *
35 */
36public class DependTest extends BuildFileTest {
37 public static final String RESULT_FILESET = "result";
38
39 public static final String TEST_BUILD_FILE
40 = "src/etc/testcases/taskdefs/optional/depend/depend.xml";
41
42 public DependTest(String name) {
43 super(name);
44 }
45
46 public void setUp() {
47 configureProject(TEST_BUILD_FILE);
48 }
49
50 public void tearDown() {
51 executeTarget("clean");
52 }
53
54 /**
55 * Test direct dependency removal
56 */
57 public void testDirect() {
58 executeTarget("testdirect");
59 Hashtable files = getResultFiles();
60 assertEquals("Depend did not leave correct number of files", 3,
61 files.size());
62 assertTrue("Result did not contain A.class",
63 files.containsKey("A.class"));
64 assertTrue("Result did not contain D.class",
65 files.containsKey("D.class"));
66 }
67
68 /**
69 * Test dependency traversal (closure)
70 */
71 public void testClosure() {
72 executeTarget("testclosure");
73 Hashtable files = getResultFiles();
74 assertTrue("Depend did not leave correct number of files",
75 files.size() <= 2);
76 assertTrue("Result did not contain D.class",
77 files.containsKey("D.class"));
78 }
79
80 /**
81 * Test that inner class dependencies trigger deletion of the outer class
82 */
83 public void testInner() {
84 executeTarget("testinner");
85 assertEquals("Depend did not leave correct number of files", 0,
86 getResultFiles().size());
87 }
88
89 /**
90 * Test that multi-leve inner class dependencies trigger deletion of
91 * the outer class
92 */
93 public void testInnerInner() {
94 executeTarget("testinnerinner");
95 assertEquals("Depend did not leave correct number of files", 0,
96 getResultFiles().size());
97 }
98
99 /**
100 * Test that an exception is thrown when there is no source
101 */
102 public void testNoSource() {
103 expectBuildExceptionContaining("testnosource",
104 "No source specified", "srcdir attribute must be set");
105 }
106
107 /**
108 * Test that an exception is thrown when the source attribute is empty
109 */
110 public void testEmptySource() {
111 expectBuildExceptionContaining("testemptysource",
112 "No source specified", "srcdir attribute must be non-empty");
113 }
114
115 /**
116 * Read the result fileset into a Hashtable
117 *
118 * @return a Hashtable containing the names of the files in the result
119 * fileset
120 */
121 private Hashtable getResultFiles() {
122 FileSet resultFileSet = (FileSet) project.getReference(RESULT_FILESET);
123 DirectoryScanner scanner = resultFileSet.getDirectoryScanner(project);
124 String[] scannedFiles = scanner.getIncludedFiles();
125 Hashtable files = new Hashtable();
126 for (int i = 0; i < scannedFiles.length; ++i) {
127 files.put(scannedFiles[i], scannedFiles[i]);
128 }
129 return files;
130 }
131
132
133 /**
134 * Test mutual dependency between inner and outer do not cause both to be
135 * deleted
136 */
137 public void testInnerClosure() {
138 executeTarget("testinnerclosure");
139 assertEquals("Depend did not leave correct number of files", 4,
140 getResultFiles().size());
141 }
142
143 /**
144 * Test the operation of the cache
145 */
146 public void testCache() {
147 executeTarget("testcache");
148 }
149
150 /**
151 * Test the detection and warning of non public classes
152 */
153 public void testNonPublic() {
154 executeTarget("testnonpublic");
155 String log = getLog();
156 assertTrue("Expected warning about APrivate",
157 log.indexOf("The class APrivate in file") != -1);
158 assertTrue("but has not been deleted because its source file "
159 + "could not be determined",
160 log.indexOf("The class APrivate in file") != -1);
161 }
162
163}
Note: See TracBrowser for help on using the repository browser.