Exemplo n.º 1
0
  @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));
  }
Exemplo n.º 2
0
  @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));
  }
Exemplo n.º 3
0
 @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();
   }
 }
Exemplo n.º 4
0
  @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"));
  }