FilepathUtils { public static String append(final String... fragments) { return append(fragments, 0, fragments.length - 1); }  static String[] getCanonicalFragments(final String path); static String getCanonicalForm(final String path); static String[] split(final String path); static String getParentPath(final String path); static String getFilename(final String path); static String concat(final String... fragments); static String append(final String... fragments); static String append(final String[] fragments, final int start, final int end);  }
@Test public void testAppend() { final Object[][] testParameters = new Object[][] {{new String[] {"/Users"}, "/Users"}, {new String[] {"/Users", "/tester"}, "/Users/tester"}, {new String[] {"/Users", "/admin", "/systems"}, "/Users/admin/systems"}, {new String[] {"/Users", "/admin", "/systems", "/subsystem"}, "/Users/admin/systems/subsystem"}}; try { FilepathUtils.append((String[]) null); } catch (Exception e) { assertSame(NullPointerException.class, e.getClass()); } for (Object[] testParameter : testParameters) { String expected = (String) testParameter[1]; String[] fragments = (String[]) testParameter[0]; assertEquals(expected, FilepathUtils.append(fragments)); } }
@Test public void testAppendWithStartAndEnd() { final Object[][] testParameters = new Object[][] {{new String[] {"/Users"}, 0, 0, "/Users"}, {new String[] {"/Users", "/tester"}, 0, 1, "/Users/tester"}, {new String[] {"/Users", "/admin", "/systems"}, 0, 2, "/Users/admin/systems"}, {new String[] {"/Users", "/admin", "/systems"}, 1, 2, "/admin/systems"}, {new String[] {"/Users", "/admin", "/systems"}, 2, 2, "/systems"}}; assertEquals("", FilepathUtils.append(null, null, null)); for (final Object[] testParameter : testParameters) { String expected = (String) testParameter[3]; String[] fragments = (String[]) testParameter[0]; int start = (Integer) testParameter[1]; int end = (Integer) testParameter[2]; assertEquals(expected, FilepathUtils.append(fragments, start, end)); } }