KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > InitializeClassTest


1 /*
2  * Copyright 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.taskdefs;
19
20 import java.io.File JavaDoc;
21 import java.io.FileOutputStream JavaDoc;
22 import java.io.IOException JavaDoc;
23 import java.io.PrintStream JavaDoc;
24 import org.apache.tools.ant.Project;
25 import org.apache.tools.ant.BuildFileTest;
26 import org.apache.tools.ant.util.FileUtils;
27
28 /**
29  * Test to see if static initializers are invoked the same way
30  * when <java> is invoked in forked and unforked modes.
31  *
32  */

33 public class InitializeClassTest extends BuildFileTest {
34
35     public InitializeClassTest(String JavaDoc name) {
36         super(name);
37     }
38
39     public void setUp() {
40         configureProject("src/etc/testcases/taskdefs/initializeclass.xml");
41     }
42
43     public void testAll() throws IOException JavaDoc {
44         executeTarget("forked");
45         PrintStream JavaDoc ps = System.out;
46         File JavaDoc f1 = new File JavaDoc("src/etc/testcases/taskdefs/forkedout");
47         File JavaDoc f2 = new File JavaDoc("src/etc/testcases/taskdefs/unforkedout");
48         PrintStream JavaDoc newps = new PrintStream JavaDoc(new FileOutputStream JavaDoc(f2));
49         System.setOut(newps);
50         project.executeTarget("unforked");
51         System.setOut(ps);
52         newps.close();
53         FileUtils fu = FileUtils.newFileUtils();
54         assertTrue("Forked - non-forked mismatch", fu.contentEquals(f1, f2));
55     }
56
57     public void tearDown() {
58         File JavaDoc f1 = new File JavaDoc("src/etc/testcases/taskdefs/forkedout");
59         File JavaDoc f2 = new File JavaDoc("src/etc/testcases/taskdefs/unforkedout");
60         f1.delete();
61         f2.delete();
62     }
63 }
64
Popular Tags