@Test public void testUTF8FileCRBreaks() throws URISyntaxException, IOException { final File testFileIso = new File(this.getClass().getResource("/test-file-utf8-cr-only.bin").toURI()); reversedLinesFileReader = new ReversedLinesFileReader(testFileIso, testParamBlockSize, UTF_8); assertFileWithShrinkingTestLines(reversedLinesFileReader); }
@Test public void testUTF8FileWindowsBreaksSmallBlockSize2VerifyBlockSpanningNewLines() throws URISyntaxException, IOException { final File testFileUtf8 = new File(this.getClass().getResource("/test-file-utf8-win-linebr.bin").toURI()); reversedLinesFileReader = new ReversedLinesFileReader(testFileUtf8, testParamBlockSize, UTF_8); assertFileWithShrinkingTestLines(reversedLinesFileReader); }
@Test(expected = UnsupportedEncodingException.class) public void testUnsupportedEncodingBig5() throws URISyntaxException, IOException { final File testFileEncodingBig5 = new File(this.getClass().getResource("/test-file-empty.bin").toURI()); new ReversedLinesFileReader(testFileEncodingBig5, testParamBlockSize, "Big5").close(); }
@Test public void testIsoFileDefaults() throws URISyntaxException, IOException { final File testFileIso = new File(this.getClass().getResource("/test-file-iso8859-1.bin").toURI()); reversedLinesFileReader = new ReversedLinesFileReader(testFileIso, testParamBlockSize, ISO_8859_1); assertFileWithShrinkingTestLines(reversedLinesFileReader); }
@Test public void testUTF8File() throws URISyntaxException, IOException { final File testFileIso = new File(this.getClass().getResource("/test-file-utf8.bin").toURI()); reversedLinesFileReader = new ReversedLinesFileReader(testFileIso, testParamBlockSize, UTF_8); assertFileWithShrinkingTestLines(reversedLinesFileReader); }
@Test public void testUTF16BEFile() throws URISyntaxException, IOException { final File testFileUTF16BE = new File(this.getClass().getResource("/test-file-utf16be.bin").toURI()); reversedLinesFileReader = new ReversedLinesFileReader(testFileUTF16BE, testParamBlockSize, "UTF-16BE"); assertFileWithShrinkingTestLines(reversedLinesFileReader); }
@Test public void testUTF8FileWindowsBreaks() throws URISyntaxException, IOException { final File testFileIso = new File(this.getClass().getResource("/test-file-utf8-win-linebr.bin").toURI()); reversedLinesFileReader = new ReversedLinesFileReader(testFileIso, testParamBlockSize, UTF_8); assertFileWithShrinkingTestLines(reversedLinesFileReader); }
@Test public void testUTF16LEFile() throws URISyntaxException, IOException { final File testFileUTF16LE = new File(this.getClass().getResource("/test-file-utf16le.bin").toURI()); reversedLinesFileReader = new ReversedLinesFileReader(testFileUTF16LE, testParamBlockSize, "UTF-16LE"); assertFileWithShrinkingTestLines(reversedLinesFileReader); }
@Test(expected = UnsupportedEncodingException.class) public void testUnsupportedEncodingUTF16() throws URISyntaxException, IOException { final File testFileEmpty = new File(this.getClass().getResource("/test-file-empty.bin").toURI()); new ReversedLinesFileReader(testFileEmpty, testParamBlockSize, "UTF-16").close(); }
@Test(expected=UnsupportedEncodingException.class) public void testUnsupportedEncodingUTF16() throws URISyntaxException, IOException { final File testFileEmpty = new File(this.getClass().getResource("/test-file-empty.bin").toURI()); new ReversedLinesFileReader(testFileEmpty, 4096, "UTF-16").close(); }
@Test(expected=UnsupportedEncodingException.class) public void testUnsupportedEncodingBig5() throws URISyntaxException, IOException { final File testFileEncodingBig5 = new File(this.getClass().getResource("/test-file-empty.bin").toURI()); new ReversedLinesFileReader(testFileEncodingBig5, 4096, "Big5").close(); }
@Test public void testEmptyFile() throws URISyntaxException, IOException { final File testFileEmpty = new File(this.getClass().getResource("/test-file-empty.bin").toURI()); reversedLinesFileReader = new ReversedLinesFileReader(testFileEmpty, testParamBlockSize, UTF_8); assertNull(reversedLinesFileReader.readLine()); }
@Test public void testGBK() throws URISyntaxException, IOException { final File testFileGBK = new File(this.getClass().getResource("/test-file-gbk.bin").toURI()); reversedLinesFileReader = new ReversedLinesFileReader(testFileGBK, testParamBlockSize, "GBK"); assertEqualsAndNoLineBreaks(TEST_LINE_GBK_2, reversedLinesFileReader.readLine()); assertEqualsAndNoLineBreaks(TEST_LINE_GBK_1, reversedLinesFileReader.readLine()); }
@Test public void testWindows31jFile() throws URISyntaxException, IOException { final File testFileWindows31J = new File(this.getClass().getResource("/test-file-windows-31j.bin").toURI()); reversedLinesFileReader = new ReversedLinesFileReader(testFileWindows31J, testParamBlockSize, "windows-31j"); assertEqualsAndNoLineBreaks(TEST_LINE_WINDOWS_31J_2, reversedLinesFileReader.readLine()); assertEqualsAndNoLineBreaks(TEST_LINE_WINDOWS_31J_1, reversedLinesFileReader.readLine()); }
@Test public void testxWindows950File() throws URISyntaxException, IOException { final File testFilexWindows950 = new File(this.getClass().getResource("/test-file-x-windows-950.bin").toURI()); reversedLinesFileReader = new ReversedLinesFileReader(testFilexWindows950, testParamBlockSize, "x-windows-950"); assertEqualsAndNoLineBreaks(TEST_LINE_X_WINDOWS_950_2, reversedLinesFileReader.readLine()); assertEqualsAndNoLineBreaks(TEST_LINE_X_WINDOWS_950_1, reversedLinesFileReader.readLine()); }
@Test // this test is run 3x for same block size as we want to test with 10 public void testFileSizeIsExactMultipleOfBlockSize() throws URISyntaxException, IOException { final int blockSize = 10; final File testFile20Bytes = new File(this.getClass().getResource("/test-file-20byteslength.bin").toURI()); reversedLinesFileReader = new ReversedLinesFileReader(testFile20Bytes, blockSize, ISO_8859_1); final String testLine = "123456789"; assertEqualsAndNoLineBreaks(testLine, reversedLinesFileReader.readLine()); assertEqualsAndNoLineBreaks(testLine, reversedLinesFileReader.readLine()); }
@Test public void testFileSizeIsExactMultipleOfBlockSize() throws URISyntaxException, IOException { final int blockSize = 10; final File testFile20Bytes = new File(this.getClass().getResource("/test-file-20byteslength.bin").toURI()); reversedLinesFileReader = new ReversedLinesFileReader(testFile20Bytes, blockSize, "ISO-8859-1"); final String testLine = "123456789"; assertEqualsAndNoLineBreaks(testLine, reversedLinesFileReader.readLine()); assertEqualsAndNoLineBreaks(testLine, reversedLinesFileReader.readLine()); }
@Test public void testxWindows949File() throws URISyntaxException, IOException { final File testFilexWindows949 = new File(this.getClass().getResource("/test-file-x-windows-949.bin").toURI()); reversedLinesFileReader = new ReversedLinesFileReader(testFilexWindows949, testParamBlockSize, "x-windows-949"); assertEqualsAndNoLineBreaks(TEST_LINE_X_WINDOWS_949_2, reversedLinesFileReader.readLine()); assertEqualsAndNoLineBreaks(TEST_LINE_X_WINDOWS_949_1, reversedLinesFileReader.readLine()); }
@Test public void testIsoFileManyWindowsBreaksSmallBlockSize2VerifyBlockSpanningNewLines() throws URISyntaxException, IOException { final File testFileIso = new File(this.getClass().getResource("/test-file-iso8859-1-shortlines-win-linebr.bin").toURI()); reversedLinesFileReader = new ReversedLinesFileReader(testFileIso, testParamBlockSize, ISO_8859_1); for (int i = 3; i > 0; i--) { for (int j = 1; j <= 3; j++) { assertEqualsAndNoLineBreaks("", reversedLinesFileReader.readLine()); } assertEqualsAndNoLineBreaks("" + i, reversedLinesFileReader.readLine()); } }
@Test public void testShiftJISFile() throws URISyntaxException, IOException { final File testFileShiftJIS = new File(this.getClass().getResource("/test-file-shiftjis.bin").toURI()); reversedLinesFileReader = new ReversedLinesFileReader(testFileShiftJIS, testParamBlockSize, "Shift_JIS"); assertEqualsAndNoLineBreaks(TEST_LINE_SHIFT_JIS2, reversedLinesFileReader.readLine()); assertEqualsAndNoLineBreaks(TEST_LINE_SHIFT_JIS1, reversedLinesFileReader.readLine()); }