source: trunk/java-utils-test/src/test/java/de/ugoe/cs/util/FileToolsTest.java @ 1314

Last change on this file since 1314 was 927, checked in by sherbold, 12 years ago
  • added copyright under the Apache License, Version 2.0
  • Property svn:mime-type set to text/plain
File size: 2.6 KB
Line 
1//   Copyright 2012 Georg-August-Universität Göttingen, Germany
2//
3//   Licensed under the Apache License, Version 2.0 (the "License");
4//   you may not use this file except in compliance with the License.
5//   You may obtain a copy of the License at
6//
7//       http://www.apache.org/licenses/LICENSE-2.0
8//
9//   Unless required by applicable law or agreed to in writing, software
10//   distributed under the License is distributed on an "AS IS" BASIS,
11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//   See the License for the specific language governing permissions and
13//   limitations under the License.
14
15package de.ugoe.cs.util;
16
17import org.junit.*;
18import static org.junit.Assert.*;
19
20/**
21 * The class <code>FileToolsTest</code> contains tests for the class
22 * <code>{@link FileTools}</code>.
23 *
24 * @author Steffen Herbold
25 * @version 1.0
26 */
27public class FileToolsTest {
28
29        final static String filenameNoCR = "testdata/de.ugoe.cs.util.FileToolsTest/testdata-nocr.txt";
30        final static String filenameCR = "testdata/de.ugoe.cs.util.FileToolsTest/testdata-cr.txt";
31        final static String filenameNotExists = "testdata/de.ugoe.cs.util.FileToolsTest/doesnotexist.txt";
32
33        final static String[] expectedLines = { "line1", "line2", "line3", "",
34                        "line5" };
35
36        final static String[] expectedLinesCR = { "line1\r", "line2\r", "line3\r",
37                        "\r", "line5" };
38
39        final static String[] expectedWrongCR = { "line1\nline2\nline3\n\nline5" };
40
41        @Test
42        public void testGetLinesFromFile_1() throws Exception {
43                String[] result = FileTools.getLinesFromFile(filenameCR, true);
44                assertArrayEquals(expectedLines, result);
45        }
46
47        @Test
48        public void testGetLinesFromFile_2() throws Exception {
49                String[] result = FileTools.getLinesFromFile(filenameNoCR, true);
50                assertArrayEquals(expectedWrongCR, result);
51        }
52
53        @Test
54        public void testGetLinesFromFile_3() throws Exception {
55                String[] result = FileTools.getLinesFromFile(filenameNoCR, false);
56                assertArrayEquals(expectedLines, result);
57        }
58
59        @Test
60        public void testGetLinesFromFile_4() throws Exception {
61                String[] result = FileTools.getLinesFromFile(filenameCR, false);
62                assertArrayEquals(expectedLinesCR, result);
63        }
64
65        @Test(expected = java.io.FileNotFoundException.class)
66        public void testGetLinesFromFile_5() throws Exception {
67                FileTools.getLinesFromFile(filenameNotExists, true);
68        }
69
70        @Test(expected = java.io.FileNotFoundException.class)
71        public void testGetLinesFromFile_6() throws Exception {
72                FileTools.getLinesFromFile(filenameNotExists, false);
73        }
74
75        public static void main(String[] args) {
76                new org.junit.runner.JUnitCore().run(FileToolsTest.class);
77        }
78}
Note: See TracBrowser for help on using the repository browser.