You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

InitializeClassTest.java 2.0 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. package org.apache.tools.ant.taskdefs;
  18. import java.io.File;
  19. import java.io.FileOutputStream;
  20. import java.io.IOException;
  21. import java.io.PrintStream;
  22. import org.apache.tools.ant.Project;
  23. import org.apache.tools.ant.BuildFileTest;
  24. import org.apache.tools.ant.util.FileUtils;
  25. /**
  26. * Test to see if static initializers are invoked the same way
  27. * when <java> is invoked in forked and unforked modes.
  28. *
  29. */
  30. public class InitializeClassTest extends BuildFileTest {
  31. private File f1 = new File(System.getProperty("root"), "src/etc/testcases/taskdefs/forkedout");
  32. private File f2 = new File(System.getProperty("root"), "src/etc/testcases/taskdefs/unforkedout");
  33. public InitializeClassTest(String name) {
  34. super(name);
  35. }
  36. public void setUp() {
  37. configureProject("src/etc/testcases/taskdefs/initializeclass.xml");
  38. }
  39. public void testAll() throws IOException {
  40. executeTarget("forked");
  41. PrintStream ps = System.out;
  42. PrintStream newps = new PrintStream(new FileOutputStream(f2));
  43. System.setOut(newps);
  44. project.executeTarget("unforked");
  45. System.setOut(ps);
  46. newps.close();
  47. FileUtils fu = FileUtils.newFileUtils();
  48. assertTrue("Forked - non-forked mismatch", fu.contentEquals(f1, f2));
  49. }
  50. public void tearDown() {
  51. f1.delete();
  52. f2.delete();
  53. }
  54. }