1 package com.atlassian.core.util;
2
3 import junit.framework.TestCase;
4
5 import java.io.IOException;
6 import java.io.File;
7 import java.io.FileInputStream;
8
9 import com.atlassian.core.util.FileUtils;
10
11 public class TestFileUtils extends TestCase
12 {
13 private final static String MAVEN_TARGET_DIR = "target";
14
15
16
17
18
19 public void testSaveTestFile() throws IOException
20 {
21
22 File tempFile = new File(MAVEN_TARGET_DIR + File.separator + "foo.tmp");
23 String expected = "Hello World";
24 FileUtils.saveTextFile(expected, tempFile);
25
26
27 String actual = FileUtils.getInputStreamTextContent(new FileInputStream(tempFile));
28 assertEquals(expected, actual);
29
30
31 String expected2 = "Hello";
32 FileUtils.saveTextFile(expected2, tempFile);
33
34
35 String actual2 = FileUtils.getInputStreamTextContent(new FileInputStream(tempFile));
36 assertEquals(expected2, actual2);
37 }
38
39 public void testMoveDir()
40 {
41 File fooDir = new File(new File(MAVEN_TARGET_DIR, "a"), "bar");
42 File destDir = new File(new File(MAVEN_TARGET_DIR, "b"), "bar");
43 fooDir.mkdirs();
44
45 assertTrue(FileUtils.moveDir(fooDir, destDir));
46 }
47 }