source: trunk/JavaHelperLibTest/src/de/ugoe/cs/util/FileToolsTest.java @ 413

Last change on this file since 413 was 255, checked in by sherbold, 13 years ago
  • Property svn:mime-type set to text/plain
File size: 2.0 KB
RevLine 
[255]1package de.ugoe.cs.util;
2
3import org.junit.*;
4import static org.junit.Assert.*;
5
6/**
7 * The class <code>FileToolsTest</code> contains tests for the class
8 * <code>{@link FileTools}</code>.
9 *
10 * @author Steffen Herbold
11 * @version 1.0
12 */
13public class FileToolsTest {
14
15        final static String filenameNoCR = "testdata/de.ugoe.cs.util.FileToolsTest/testdata-nocr.txt";
16        final static String filenameCR = "testdata/de.ugoe.cs.util.FileToolsTest/testdata-cr.txt";
17        final static String filenameNotExists = "testdata/de.ugoe.cs.util.FileToolsTest/doesnotexist.txt";
18
19        final static String[] expectedLines = { "line1", "line2", "line3", "",
20                        "line5" };
21
22        final static String[] expectedLinesCR = { "line1\r", "line2\r", "line3\r",
23                        "\r", "line5" };
24
25        final static String[] expectedWrongCR = { "line1\nline2\nline3\n\nline5" };
26
27        @Test
28        public void testGetLinesFromFile_1() throws Exception {
29                String[] result = FileTools.getLinesFromFile(filenameCR, true);
30                assertArrayEquals(expectedLines, result);
31        }
32
33        @Test
34        public void testGetLinesFromFile_2() throws Exception {
35                String[] result = FileTools.getLinesFromFile(filenameNoCR, true);
36                assertArrayEquals(expectedWrongCR, result);
37        }
38
39        @Test
40        public void testGetLinesFromFile_3() throws Exception {
41                String[] result = FileTools.getLinesFromFile(filenameNoCR, false);
42                assertArrayEquals(expectedLines, result);
43        }
44
45        @Test
46        public void testGetLinesFromFile_4() throws Exception {
47                String[] result = FileTools.getLinesFromFile(filenameCR, false);
48                assertArrayEquals(expectedLinesCR, result);
49        }
50
51        @Test(expected = java.io.FileNotFoundException.class)
52        public void testGetLinesFromFile_5() throws Exception {
53                FileTools.getLinesFromFile(filenameNotExists, true);
54        }
55
56        @Test(expected = java.io.FileNotFoundException.class)
57        public void testGetLinesFromFile_6() throws Exception {
58                FileTools.getLinesFromFile(filenameNotExists, false);
59        }
60
61        public static void main(String[] args) {
62                new org.junit.runner.JUnitCore().run(FileToolsTest.class);
63        }
64}
Note: See TracBrowser for help on using the repository browser.