FileDocCategorySizeDatePackage
ReplaceRegExpTest.javaAPI DocApache Ant 1.703971Wed Dec 13 06:16:22 GMT 2006org.apache.tools.ant.taskdefs.optional

ReplaceRegExpTest

public class ReplaceRegExpTest extends org.apache.tools.ant.BuildFileTest
JUnit Testcase for the optional replaceregexp task.

Fields Summary
private static final String
PROJECT_PATH
private static final org.apache.tools.ant.util.FileUtils
FILE_UTILS
Constructors Summary
public ReplaceRegExpTest(String name)

    
       
        super(name);
    
Methods Summary
public voidsetUp()

        configureProject(PROJECT_PATH + "/replaceregexp.xml");
    
public voidtearDown()

        executeTarget("cleanup");
    
public voidtestDirectoryDateDoesNotChange()

        executeTarget("touchDirectory");
        File myFile = new File(System.getProperty("root"), PROJECT_PATH + "/" + getProject().getProperty("tmpregexp"));
        long timeStampBefore = myFile.lastModified();
        executeTarget("testDirectoryDateDoesNotChange");
        long timeStampAfter = myFile.lastModified();
        assertEquals("directory date should not change",
            timeStampBefore, timeStampAfter);
    
public voidtestDontAddNewline1()

        executeTarget("testDontAddNewline1");
        assertTrue("Files match",
                   FILE_UTILS
                   .contentEquals(new File(System.getProperty("root"), PROJECT_PATH + "/test.properties"),
                                  new File(System.getProperty("root"), PROJECT_PATH + "/replaceregexp2.result.properties")));
    
public voidtestDontAddNewline2()

        executeTarget("testDontAddNewline2");
        assertTrue("Files match",
                   FILE_UTILS
                   .contentEquals(new File(System.getProperty("root"), PROJECT_PATH + "/test.properties"),
                                  new File(System.getProperty("root"), PROJECT_PATH + "/replaceregexp2.result.properties")));
    
public voidtestReplace()

        Properties original = new Properties();
        FileInputStream propsFile = null;
        try {
            propsFile = new FileInputStream(new File(System.getProperty("root"), PROJECT_PATH + "/replaceregexp.properties"));
            original.load(propsFile);
        } finally {
            if (propsFile != null) {
                propsFile.close();
                propsFile = null;
            }
        }

        assertEquals("Def", original.get("OldAbc"));

        executeTarget("testReplace");

        Properties after = new Properties();
        try {
            propsFile = new FileInputStream(new File(System.getProperty("root"), PROJECT_PATH + "/test.properties"));
            after.load(propsFile);
        } finally {
            if (propsFile != null) {
                propsFile.close();
                propsFile = null;
            }
        }

        assertNull(after.get("OldAbc"));
        assertEquals("AbcDef", after.get("NewProp"));