package de.ugoe.cs.util; import org.junit.*; import static org.junit.Assert.*; /** * The class FileToolsTest contains tests for the class * {@link FileTools}. * * @author Steffen Herbold * @version 1.0 */ public class FileToolsTest { final static String filenameNoCR = "testdata/de.ugoe.cs.util.FileToolsTest/testdata-nocr.txt"; final static String filenameCR = "testdata/de.ugoe.cs.util.FileToolsTest/testdata-cr.txt"; final static String filenameNotExists = "testdata/de.ugoe.cs.util.FileToolsTest/doesnotexist.txt"; final static String[] expectedLines = { "line1", "line2", "line3", "", "line5" }; final static String[] expectedLinesCR = { "line1\r", "line2\r", "line3\r", "\r", "line5" }; final static String[] expectedWrongCR = { "line1\nline2\nline3\n\nline5" }; @Test public void testGetLinesFromFile_1() throws Exception { String[] result = FileTools.getLinesFromFile(filenameCR, true); assertArrayEquals(expectedLines, result); } @Test public void testGetLinesFromFile_2() throws Exception { String[] result = FileTools.getLinesFromFile(filenameNoCR, true); assertArrayEquals(expectedWrongCR, result); } @Test public void testGetLinesFromFile_3() throws Exception { String[] result = FileTools.getLinesFromFile(filenameNoCR, false); assertArrayEquals(expectedLines, result); } @Test public void testGetLinesFromFile_4() throws Exception { String[] result = FileTools.getLinesFromFile(filenameCR, false); assertArrayEquals(expectedLinesCR, result); } @Test(expected = java.io.FileNotFoundException.class) public void testGetLinesFromFile_5() throws Exception { FileTools.getLinesFromFile(filenameNotExists, true); } @Test(expected = java.io.FileNotFoundException.class) public void testGetLinesFromFile_6() throws Exception { FileTools.getLinesFromFile(filenameNotExists, false); } public static void main(String[] args) { new org.junit.runner.JUnitCore().run(FileToolsTest.class); } }