1 17 18 package org.apache.tools.ant.taskdefs; 19 20 import org.apache.tools.ant.BuildFileTest; 21 22 import java.io.*; 23 24 import junit.framework.AssertionFailedError; 25 26 28 public class ReplaceTest extends BuildFileTest { 29 30 private static final String TEST_PATH = "src/etc/testcases/taskdefs/replace/"; 31 public ReplaceTest(String name) { 32 super(name); 33 } 34 35 public void setUp() { 36 configureProject("src/etc/testcases/taskdefs/replace.xml"); 37 } 38 39 public void test1() { 40 expectBuildException("test1", "required argument not specified"); 41 } 42 43 public void test2() { 44 expectBuildException("test2", "required argument not specified"); 45 } 46 47 public void test3() { 48 expectBuildException("test3", "required argument not specified"); 49 } 50 51 public void test4() { 52 expectBuildException("test4", "empty token not allowed"); 53 } 54 55 public void test5() { 56 executeTarget("test5"); 57 } 58 59 public void test6() { 60 expectBuildException("test6", "required argument not specified"); 61 } 62 63 public void test7() { 64 expectBuildException("test7", "empty token not allowed"); 65 } 66 67 public void test8() { 68 executeTarget("test8"); 69 } 70 71 public void test9() throws IOException{ 72 executeTarget("test9"); 73 String tmpdir = project.getProperty("tmp.dir"); 74 assertEqualContent(new File(tmpdir, "result.txt"), 75 new File(tmpdir, "output.txt")); 76 } 77 public void tearDown() { 78 executeTarget("cleanup"); 79 } 80 public void assertEqualContent(File expect, File result) 81 throws AssertionFailedError, IOException { 82 if (!result.exists()) { 83 fail("Expected file "+result+" doesn\'t exist"); 84 } 85 86 InputStream inExpect = null; 87 InputStream inResult = null; 88 try { 89 inExpect = new BufferedInputStream(new FileInputStream(expect)); 90 inResult = new BufferedInputStream(new FileInputStream(result)); 91 92 int expectedByte = inExpect.read(); 93 while (expectedByte != -1) { 94 assertEquals(expectedByte, inResult.read()); 95 expectedByte = inExpect.read(); 96 } 97 assertEquals("End of file", -1, inResult.read()); 98 } finally { 99 if (inResult != null) { 100 inResult.close(); 101 } 102 if (inExpect != null) { 103 inExpect.close(); 104 } 105 } 106 } 107 } 108 | Popular Tags |