public void testDeleteFileTreeExceptions() { try { FileUtils.deleteTree(null); fail("invalid null argument"); } catch (IllegalArgumentException e) { } }
fail("unable to create file");
public void testGetDisplayText() { try { FileUtils.getDisplayText(null, 50); fail("NPE expected"); } catch (NullPointerException e) { // ok } try { FileUtils.getDisplayText(new File("alpha/bravo/charly"), 3); fail("IAE expected"); } catch (IllegalArgumentException e) { // ok } // "5432109876543210987654321098765432109876543210987654321" File file = new File("alpha/bravo/charly/delta/echo/foxtrott/golf/hotel/india"); char sep = File.separatorChar; assertEquals("...ndia", FileUtils.getDisplayText(file, 7)); assertEquals(".../india".replace('/', sep), FileUtils.getDisplayText(file, 12)); assertEquals(".../golf/hotel/india".replace('/', sep), FileUtils.getDisplayText(file, 20)); assertEquals("alpha/bravo/charly/delta/echo/foxtrott/golf/hotel/india".replace('/', sep), FileUtils.getDisplayText(file, 80)); } }
public void testExtractFileName() { String path1 = "home" + File.separator + "tom" + File.separator + "tesfile1.dim"; String path2 = "C:" + File.separator + "Data" + File.separator + "TestFiles" + File.separator + "tesfile2.dim"; String path3 = File.separator + "tesfile3.dim"; String expected1 = "tesfile1.dim"; String expected2 = "tesfile2.dim"; String expected3 = "tesfile3.dim"; // check that null is not allowed as argument try { FileUtils.getFileNameFromPath(null); fail("Exception expected here!"); } catch (IllegalArgumentException e) { } assertEquals(expected1, FileUtils.getFileNameFromPath(path1)); assertEquals(expected2, FileUtils.getFileNameFromPath(path2)); assertEquals(expected3, FileUtils.getFileNameFromPath(path3)); }