01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */
18:
19: package org.apache.tools.ant.taskdefs;
20:
21: import java.io.File;
22: import java.io.FileOutputStream;
23: import java.io.IOException;
24: import java.io.PrintStream;
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: /** Utilities used for file operations */
36: private static final FileUtils FILE_UTILS = FileUtils
37: .getFileUtils();
38:
39: private File f1 = new File(System.getProperty("root"),
40: "src/etc/testcases/taskdefs/forkedout");
41: private File f2 = new File(System.getProperty("root"),
42: "src/etc/testcases/taskdefs/unforkedout");
43:
44: public InitializeClassTest(String name) {
45: super (name);
46: }
47:
48: public void setUp() {
49: configureProject("src/etc/testcases/taskdefs/initializeclass.xml");
50: }
51:
52: public void testAll() throws IOException {
53: executeTarget("forked");
54: PrintStream ps = System.out;
55: PrintStream newps = new PrintStream(new FileOutputStream(f2));
56: System.setOut(newps);
57: project.executeTarget("unforked");
58: System.setOut(ps);
59: newps.close();
60: assertTrue("Forked - non-forked mismatch", FILE_UTILS
61: .contentEquals(f1, f2));
62: }
63:
64: public void tearDown() {
65: f1.delete();
66: f2.delete();
67: }
68: }
|