@Test public void testRead() throws Exception { String[] s = IoUtil.readLines(new StringReader("abc \n\n xyz "), true); assertArrayEquals2(new String[] {"abc", "xyz"}, s); ByteArrayInputStream in = new ByteArrayInputStream("abc".getBytes()); assertEquals(3, IoUtil.read(in, new byte[4], 0, 4)); }
@Test public void testClosed() throws Exception { IoUtil.close(null); IOException e = new IOException(); Closeable c = mock(Closeable.class); doThrow(e).when(c).close(); assertSame(e, IoUtil.close(c)); }
@Test public void testCopy() throws Exception { File file1 = createTempFile("txt", "UTF-8", "abc"); File file2 = File.createTempFile("test", "txt"); try { IoUtil.copyFile(file1, file2); assertEquals("abc", read(file2)); } finally { file1.delete(); file2.delete(); } }
@Test public void testExtension() throws Exception { File f = new File("test.css"); assertEquals("test", IoUtil.cutExtension(f)); assertNull(null, IoUtil.getExtension("test")); assertNull(IoUtil.normExtension("")); assertNull(IoUtil.normExtension(null)); assertEquals("css", IoUtil.normExtension(".css")); assertEquals("css", IoUtil.normExtension("css")); }