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 AbstractUpdateTestCase {
09: public final String sourceFilename = testDir + "/testFile";
10:
11: public final File sourceFile = new File(sourceFilename);
12:
13: public final String destDirName = "subDir";
14:
15: public final String destPath = testDir + "/" + rootName + "/"
16: + destDirName + "/testFile";
17:
18: public final File destFile = new File(destPath);
19:
20: public void setUp() throws Exception {
21: super .setUp();
22: sourceFile.createNewFile();
23: }
24:
25: public void tearDown() throws Exception {
26: super .tearDown();
27: sourceFile.delete();
28: }
29:
30: protected Update makeUpdate() throws Exception {
31: return new ReplacingFileUpdate(updater, sourceFilename,
32: destDirName);
33: }
34:
35: public void testNoDestination() throws Exception {
36: assertTrue(update.shouldBeApplied());
37: update.doUpdate();
38: assertTrue(destFile.exists());
39: }
40:
41: public void testFileMatch() throws Exception {
42: update.doUpdate();
43: assertFalse(update.shouldBeApplied());
44: }
45:
46: public void testFileDiffer() throws Exception {
47: update.doUpdate();
48:
49: FileOutputStream output = new FileOutputStream(sourceFile);
50: output.write("hello".getBytes());
51: output.close();
52:
53: assertTrue(update.shouldBeApplied());
54: update.doUpdate();
55:
56: assertEquals("hello", FileUtil.getFileContent(destFile));
57: }
58: }
|