01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.updates;
04:
05: import java.io.*;
06: import fitnesse.util.FileUtil;
07:
08: public class ReplacingFileUpdateTest extends UpdateTest {
09: public final String sourceFilename = "classes/testFile";
10: public final File sourceFile = new File(sourceFilename);
11:
12: public final String destDirName = "subDir";
13: public final String destPath = UpdateTest.testDir + "/"
14: + UpdateTest.rootName + "/" + destDirName + "/testFile";
15: public final File destFile = new File(destPath);
16:
17: public void setUp() throws Exception {
18: super .setUp();
19: sourceFile.createNewFile();
20: }
21:
22: public void tearDown() throws Exception {
23: super .tearDown();
24: sourceFile.delete();
25: }
26:
27: protected Update makeUpdate() throws Exception {
28: return new ReplacingFileUpdate(updater, "testFile", destDirName);
29: }
30:
31: public void testNoDestination() throws Exception {
32: assertTrue(update.shouldBeApplied());
33: update.doUpdate();
34: assertTrue(destFile.exists());
35: }
36:
37: public void testFileMatch() throws Exception {
38: update.doUpdate();
39: assertFalse(update.shouldBeApplied());
40: }
41:
42: public void testFileDiffer() throws Exception {
43: update.doUpdate();
44:
45: FileOutputStream output = new FileOutputStream(sourceFile);
46: output.write("hello".getBytes());
47: output.close();
48:
49: assertTrue(update.shouldBeApplied());
50: update.doUpdate();
51:
52: assertEquals("hello", FileUtil.getFileContent(destFile));
53: }
54: }
|