01: package com.mockrunner.test.util;
02:
03: import java.io.File;
04: import java.io.FileNotFoundException;
05: import java.io.IOException;
06: import java.util.List;
07:
08: import junit.framework.TestCase;
09:
10: import com.mockrunner.util.common.FileUtil;
11:
12: public class FileUtilTest extends TestCase {
13: public void testGetLinesFromFile() {
14: File file = new File(
15: "src/com/mockrunner/test/util/testlines.txt");
16: List lineList = FileUtil.getLinesFromFile(file);
17: doTestLines(lineList);
18: }
19:
20: public void testFindFile() throws IOException {
21: File file = FileUtil
22: .findFile("src/com/mockrunner/test/util/testlines.txt");
23: assertNotNull(file);
24: List lineList = FileUtil.getLinesFromFile(file);
25: doTestLines(lineList);
26: file = FileUtil
27: .findFile("/com/mockrunner/test/util/testlines.txt");
28: assertNotNull(file);
29: lineList = FileUtil.getLinesFromFile(file);
30: doTestLines(lineList);
31: file = FileUtil
32: .findFile("com/mockrunner/test/util/testlines.txt");
33: assertNotNull(file);
34: lineList = FileUtil.getLinesFromFile(file);
35: assertNotNull(FileUtil.findFile("FileUtil.class"));
36: assertNotNull(FileUtil
37: .findFile("com/mockrunner/test/util/file name with blanks.txt"));
38: try {
39: FileUtil.findFile("notfound");
40: fail();
41: } catch (FileNotFoundException exc) {
42: //should throw exception
43: }
44: }
45:
46: private void doTestLines(List lineList) {
47: assertTrue(lineList.size() == 6);
48: assertEquals("line1", lineList.get(0));
49: assertEquals("line2", lineList.get(1));
50: assertEquals("line3", lineList.get(2));
51: assertEquals("", lineList.get(3));
52: assertEquals("line4", lineList.get(4));
53: assertEquals("line5", lineList.get(5));
54: }
55: }
|