Skip to content

Commit e413d91

Browse files
author
Niall Pemberton
committed
IO-127 - Changes so that the tests run on JDK 1.3 using the Ant build:
- Remove RegexFileFilter tests from FileFilterTestCase and put them in a new separate test case (RegexFileFilterTestCase) - Remove the other JDK 1.4 dependant classes from the package test suites - change the Ant build to conditionally compile and run the tests based on whether Java version is JDK 1.3 or higher git-svn-id: https://svn.apache.org/repos/asf/commons/proper/io/trunk@612686 13f79535-47bb-0310-9956-ffa450edef68
1 parent 89e59da commit e413d91

7 files changed

Lines changed: 209 additions & 105 deletions

File tree

build.xml

Lines changed: 81 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158
description="Compile ALL classes">
159159
<echo message="*** Compiling all classes ***" />
160160

161-
<!-- check JDK 1.3 -->
161+
<!-- check JDK 1.4 -->
162162
<fail message="switch to JDK 1.4+">
163163
<condition>
164164
<equals arg1="${ant.java.version}" arg2="1.3" />
@@ -181,6 +181,7 @@
181181
description="Compile ONLY JDK 1.3 compatible classes ">
182182
<echo message="*** Compiling ONLY JDK 1.3 compatible classes ***" />
183183

184+
<!-- check JDK 1.3 -->
184185
<fail message="switch to JDK 1.3">
185186
<condition>
186187
<not><equals arg1="${ant.java.version}" arg2="1.3" /></not>
@@ -203,64 +204,99 @@
203204

204205
<!-- ========== Unit Test Targets ========================================= -->
205206

206-
207-
<target name="compile.tests" depends="compile,download-dependencies"
208-
description="Compile unit test cases">
209-
<javac srcdir="${test.home}"
210-
destdir="${build.home}/test-classes"
207+
<target name="compile.tests" depends="compile, download-dependencies" description="Compile unit test cases dependant on JDK version">
208+
<antcall target="compile.tests.jdk13" />
209+
<antcall target="compile.tests.all" />
210+
</target>
211+
212+
<!-- Compile all classes -->
213+
<target name="compile.tests.all" unless="is.jdk13"
214+
description="Compile ALL test classes">
215+
<echo message="*** Compiling all test classes ***" />
216+
217+
<!-- check JDK 1.4 -->
218+
<fail message="switch to JDK 1.4+">
219+
<condition>
220+
<equals arg1="${ant.java.version}" arg2="1.3" />
221+
</condition>
222+
</fail>
223+
224+
<javac srcdir="${test.home}"
225+
destdir="${build.home}/test-classes"
211226
debug="${compile.debug}"
212-
deprecation="${compile.deprecation}"
213-
optimize="${compile.optimize}">
214-
<classpath refid="test.classpath"/>
215-
</javac>
216-
</target>
227+
deprecation="${compile.deprecation}"
228+
optimize="${compile.optimize}">
229+
<classpath refid="test.classpath"/>
230+
</javac>
231+
</target>
217232

233+
<!-- Compile excluding JDK 1.4 classes -->
234+
<target name="compile.tests.jdk13" unless="not.jdk13"
235+
description="Compile ONLY JDK 1.3 compatible test classes ">
236+
<echo message="*** Compiling ONLY JDK 1.3 compatible test classes ***" />
237+
238+
<fail message="switch to JDK 1.3">
239+
<condition>
240+
<not><equals arg1="${ant.java.version}" arg2="1.3" /></not>
241+
</condition>
242+
</fail>
243+
<javac srcdir="${test.home}"
244+
destdir="${build.home}/test-classes"
245+
debug="${compile.debug}"
246+
deprecation="${compile.deprecation}"
247+
optimize="${compile.optimize}">
248+
<classpath refid="test.classpath"/>
249+
<include name="**/*.java"/>
250+
<exclude name="**/RegexFileFilterTestCase.java"/>
251+
<exclude name="**/FileWriterWithEncodingTest.java"/>
252+
<exclude name="**/IOExceptionWithCauseTestCase.java"/>
253+
<exclude name="**/CharSequenceReaderTest.java"/>
254+
</javac>
255+
</target>
218256

219-
<target name="test" depends="compile.tests,test.main,test.comparator,test.filefilter,test.input,test.output"
257+
<target name="test" depends="compile.tests"
220258
description="Run all unit test cases">
259+
<antcall target="run.tests.jdk13" />
260+
<antcall target="run.tests.jdk14" />
221261
</target>
222262

223-
<target name="test.main" depends="compile.tests" description="Run main unit test cases">
224-
<echo message="Running main tests ..."/>
225-
<java classname="${test.runner}" fork="yes"
226-
failonerror="${test.failonerror}">
227-
<arg value="org.apache.commons.io.PackageTestSuite"/>
228-
<classpath refid="test.classpath"/>
229-
</java>
230-
</target>
263+
<target name="run.tests.jdk13"
264+
description="Run ONLY JDK 1.3 compatible test classes ">
231265

232-
<target name="test.comparator" depends="compile.tests" description="Run comparator unit test cases">
233-
<echo message="Running comparator tests ..."/>
234-
<java classname="${test.runner}" fork="yes"
235-
failonerror="${test.failonerror}">
236-
<arg value="org.apache.commons.io.comparator.PackageTestSuite"/>
237-
<classpath refid="test.classpath"/>
238-
</java>
239-
</target>
266+
<echo message="**** Running JDK 1.3 compatible test classes ****"/>
267+
268+
<antcall target="exec.test"><param name="testclass" value="org.apache.commons.io.PackageTestSuite"/></antcall>
269+
<antcall target="exec.test"><param name="testclass" value="org.apache.commons.io.comparator.PackageTestSuite"/></antcall>
270+
<antcall target="exec.test"><param name="testclass" value="org.apache.commons.io.filefilter.PackageTestSuite"/></antcall>
271+
<antcall target="exec.test"><param name="testclass" value="org.apache.commons.io.input.PackageTestSuite"/></antcall>
272+
<antcall target="exec.test"><param name="testclass" value="org.apache.commons.io.output.PackageTestSuite"/></antcall>
240273

241-
<target name="test.filefilter" depends="compile.tests" description="Run filefilter unit test cases">
242-
<echo message="Running filefilter tests ..."/>
243-
<java classname="${test.runner}" fork="yes"
244-
failonerror="${test.failonerror}">
245-
<arg value="org.apache.commons.io.filefilter.PackageTestSuite"/>
246-
<classpath refid="test.classpath"/>
247-
</java>
248274
</target>
249275

250-
<target name="test.input" depends="compile.tests" description="Run input unit test cases">
251-
<echo message="Running input tests ..."/>
252-
<java classname="${test.runner}" fork="yes"
253-
failonerror="${test.failonerror}">
254-
<arg value="org.apache.commons.io.input.PackageTestSuite"/>
255-
<classpath refid="test.classpath"/>
256-
</java>
276+
<target name="run.tests.jdk14" unless="is.jdk13"
277+
description="Run ONLY tests requiring JDK 1.4">
278+
279+
<echo message="**** Running tests requiring JDK 1.4 ****"/>
280+
281+
<!-- check JDK 1.4 -->
282+
<fail message="switch to JDK 1.4+">
283+
<condition>
284+
<equals arg1="${ant.java.version}" arg2="1.3" />
285+
</condition>
286+
</fail>
287+
288+
<antcall target="exec.test"><param name="testclass" value="org.apache.commons.io.IOExceptionWithCauseTestCase"/></antcall>
289+
<antcall target="exec.test"><param name="testclass" value="org.apache.commons.io.filefilter.RegexFileFilterTestCase"/></antcall>
290+
<antcall target="exec.test"><param name="testclass" value="org.apache.commons.io.input.CharSequenceReaderTest"/></antcall>
291+
<antcall target="exec.test"><param name="testclass" value="org.apache.commons.io.output.FileWriterWithEncodingTest"/></antcall>
292+
257293
</target>
258294

259-
<target name="test.output" depends="compile.tests" description="Run output unit test cases">
260-
<echo message="Running output tests ..."/>
295+
<target name="exec.test" description="Run a unit test case">
296+
<echo message="Running Test ${testclass} ..."/>
261297
<java classname="${test.runner}" fork="yes"
262298
failonerror="${test.failonerror}">
263-
<arg value="org.apache.commons.io.output.PackageTestSuite"/>
299+
<arg value="${testclass}"/>
264300
<classpath refid="test.classpath"/>
265301
</java>
266302
</target>

src/test/org/apache/commons/io/PackageTestSuite.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public static void main(String[] args) {
3535

3636
public static Test suite() {
3737
TestSuite suite = new TestSuite("IO Utilities");
38-
suite.addTest(new TestSuite(IOExceptionWithCauseTestCase.class));
3938
suite.addTest(new TestSuite(CopyUtilsTest.class));
4039
suite.addTest(new TestSuite(DemuxTestCase.class));
4140
suite.addTest(new TestSuite(DirectoryWalkerTestCase.class));

src/test/org/apache/commons/io/filefilter/FileFilterTestCase.java

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.util.Arrays;
2424
import java.util.Date;
2525
import java.util.List;
26-
import java.util.regex.Pattern;
2726

2827
import junit.framework.TestSuite;
2928
import junit.textui.TestRunner;
@@ -822,61 +821,6 @@ public void testEmpty() throws Exception {
822821
FileUtils.forceDelete(emptyDir);
823822
}
824823

825-
public void testRegex() throws Exception {
826-
IOFileFilter filter = new RegexFileFilter("^.*[tT]est(-\\d+)?\\.java$");
827-
assertFiltering(filter, new File("Test.java"), true);
828-
assertFiltering(filter, new File("test-10.java"), true);
829-
assertFiltering(filter, new File("test-.java"), false);
830-
831-
filter = new RegexFileFilter("^[Tt]est.java$");
832-
assertFiltering(filter, new File("Test.java"), true);
833-
assertFiltering(filter, new File("test.java"), true);
834-
assertFiltering(filter, new File("tEST.java"), false);
835-
836-
filter = new RegexFileFilter(Pattern.compile("^test.java$", Pattern.CASE_INSENSITIVE));
837-
assertFiltering(filter, new File("Test.java"), true);
838-
assertFiltering(filter, new File("test.java"), true);
839-
assertFiltering(filter, new File("tEST.java"), true);
840-
841-
filter = new RegexFileFilter("^test.java$", Pattern.CASE_INSENSITIVE);
842-
assertFiltering(filter, new File("Test.java"), true);
843-
assertFiltering(filter, new File("test.java"), true);
844-
assertFiltering(filter, new File("tEST.java"), true);
845-
846-
filter = new RegexFileFilter("^test.java$", IOCase.INSENSITIVE);
847-
assertFiltering(filter, new File("Test.java"), true);
848-
assertFiltering(filter, new File("test.java"), true);
849-
assertFiltering(filter, new File("tEST.java"), true);
850-
851-
try {
852-
new RegexFileFilter((String)null);
853-
fail();
854-
} catch (IllegalArgumentException ex) {
855-
// expected
856-
}
857-
858-
try {
859-
new RegexFileFilter((String)null, Pattern.CASE_INSENSITIVE);
860-
fail();
861-
} catch (IllegalArgumentException ex) {
862-
// expected
863-
}
864-
865-
try {
866-
new RegexFileFilter((String)null, IOCase.INSENSITIVE);
867-
fail();
868-
} catch (IllegalArgumentException ex) {
869-
// expected
870-
}
871-
872-
try {
873-
new RegexFileFilter((java.util.regex.Pattern)null);
874-
fail();
875-
} catch (IllegalArgumentException ex) {
876-
// expected
877-
}
878-
}
879-
880824
//-----------------------------------------------------------------------
881825
public void testMakeDirectoryOnly() throws Exception {
882826
assertSame(DirectoryFileFilter.DIRECTORY, FileFilterUtils.makeDirectoryOnly(null));
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* 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+
package org.apache.commons.io.filefilter;
18+
19+
import java.io.File;
20+
import java.util.regex.Pattern;
21+
22+
import junit.framework.TestSuite;
23+
import junit.textui.TestRunner;
24+
25+
import org.apache.commons.io.FileUtils;
26+
import org.apache.commons.io.IOCase;
27+
import org.apache.commons.io.testtools.FileBasedTestCase;
28+
29+
/**
30+
* Used to test RegexFileFilterUtils.
31+
*/
32+
public class RegexFileFilterTestCase extends FileBasedTestCase {
33+
34+
public RegexFileFilterTestCase(String name) {
35+
super(name);
36+
}
37+
38+
public static void main(String[] args) {
39+
TestRunner.run(suite());
40+
}
41+
42+
public static TestSuite suite() {
43+
return new TestSuite(RegexFileFilterTestCase.class);
44+
}
45+
46+
public void setUp() {
47+
getTestDirectory().mkdirs();
48+
}
49+
50+
public void tearDown() throws Exception {
51+
FileUtils.deleteDirectory(getTestDirectory());
52+
}
53+
54+
public void assertFiltering(IOFileFilter filter, File file, boolean expected) throws Exception {
55+
// Note. This only tests the (File, String) version if the parent of
56+
// the File passed in is not null
57+
assertTrue(
58+
"Filter(File) " + filter.getClass().getName() + " not " + expected + " for " + file,
59+
(filter.accept(file) == expected));
60+
61+
if (file != null && file.getParentFile() != null) {
62+
assertTrue(
63+
"Filter(File, String) " + filter.getClass().getName() + " not " + expected + " for " + file,
64+
(filter.accept(file.getParentFile(), file.getName()) == expected));
65+
} else if (file == null) {
66+
assertTrue(
67+
"Filter(File, String) " + filter.getClass().getName() + " not " + expected + " for null",
68+
filter.accept(file) == expected);
69+
}
70+
}
71+
72+
public void testRegex() throws Exception {
73+
IOFileFilter filter = new RegexFileFilter("^.*[tT]est(-\\d+)?\\.java$");
74+
assertFiltering(filter, new File("Test.java"), true);
75+
assertFiltering(filter, new File("test-10.java"), true);
76+
assertFiltering(filter, new File("test-.java"), false);
77+
78+
filter = new RegexFileFilter("^[Tt]est.java$");
79+
assertFiltering(filter, new File("Test.java"), true);
80+
assertFiltering(filter, new File("test.java"), true);
81+
assertFiltering(filter, new File("tEST.java"), false);
82+
83+
filter = new RegexFileFilter(Pattern.compile("^test.java$", Pattern.CASE_INSENSITIVE));
84+
assertFiltering(filter, new File("Test.java"), true);
85+
assertFiltering(filter, new File("test.java"), true);
86+
assertFiltering(filter, new File("tEST.java"), true);
87+
88+
filter = new RegexFileFilter("^test.java$", Pattern.CASE_INSENSITIVE);
89+
assertFiltering(filter, new File("Test.java"), true);
90+
assertFiltering(filter, new File("test.java"), true);
91+
assertFiltering(filter, new File("tEST.java"), true);
92+
93+
filter = new RegexFileFilter("^test.java$", IOCase.INSENSITIVE);
94+
assertFiltering(filter, new File("Test.java"), true);
95+
assertFiltering(filter, new File("test.java"), true);
96+
assertFiltering(filter, new File("tEST.java"), true);
97+
98+
try {
99+
new RegexFileFilter((String)null);
100+
fail();
101+
} catch (IllegalArgumentException ex) {
102+
// expected
103+
}
104+
105+
try {
106+
new RegexFileFilter((String)null, Pattern.CASE_INSENSITIVE);
107+
fail();
108+
} catch (IllegalArgumentException ex) {
109+
// expected
110+
}
111+
112+
try {
113+
new RegexFileFilter((String)null, IOCase.INSENSITIVE);
114+
fail();
115+
} catch (IllegalArgumentException ex) {
116+
// expected
117+
}
118+
119+
try {
120+
new RegexFileFilter((java.util.regex.Pattern)null);
121+
fail();
122+
} catch (IllegalArgumentException ex) {
123+
// expected
124+
}
125+
}
126+
127+
}

src/test/org/apache/commons/io/input/PackageTestSuite.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public static void main(String[] args) {
3434
public static Test suite() {
3535
TestSuite suite = new TestSuite("IO Utilities - input");
3636
suite.addTest(new TestSuite(AutoCloseInputStreamTest.class));
37-
suite.addTest(new TestSuite(CharSequenceReaderTest.class));
3837
suite.addTest(new TestSuite(ClassLoaderObjectInputStreamTest.class));
3938
suite.addTest(new TestSuite(ClosedInputStreamTest.class));
4039
suite.addTest(new TestSuite(CloseShieldInputStreamTest.class));

src/test/org/apache/commons/io/output/PackageTestSuite.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public static Test suite() {
3838
suite.addTest(new TestSuite(CloseShieldOutputStreamTest.class));
3939
suite.addTest(new TestSuite(CountingOutputStreamTest.class));
4040
suite.addTest(new TestSuite(DeferredFileOutputStreamTest.class));
41-
suite.addTest(new TestSuite(FileWriterWithEncodingTest.class));
4241
suite.addTest(new TestSuite(LockableFileWriterTest.class));
4342
suite.addTest(new TestSuite(NullOutputStreamTest.class));
4443
suite.addTest(new TestSuite(NullWriterTest.class));

xdocs/building.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ limitations under the License.
8787
</p>
8888
<ul>
8989
<li><code>ant clean</code> - clean up</li>
90-
<li><code>ant test</code> - compile and run the unit tests (requires JDK 1.4+)</li>
90+
<li><code>ant test</code> - compile and run the unit tests</li>
9191
<li><code>ant javadoc</code> - create javadocs</li>
9292
<li><code>ant jar</code> - build the jar</li>
9393
<li><code>ant dist</code> - Create the source and binary distributions</li>

0 commit comments

Comments
 (0)