MagicCommitPaths { public static List<String> finalDestination(List<String> elements) { if (isMagicPath(elements)) { List<String> destDir = magicPathParents(elements); List<String> children = magicPathChildren(elements); checkArgument(!children.isEmpty(), "No path found under " + MAGIC); ArrayList<String> dest = new ArrayList<>(destDir); if (containsBasePath(children)) { List<String> baseChildren = basePathChildren(children); checkArgument(!baseChildren.isEmpty(), "No path found under " + BASE); dest.addAll(baseChildren); } else { dest.add(filename(children)); } return dest; } else { return elements; } } private  MagicCommitPaths(); static List<String> splitPathToElements(Path path); static boolean isMagicPath(List<String> elements); static boolean containsBasePath(List<String> elements); static int magicElementIndex(List<String> elements); static List<String> magicPathParents(List<String> elements); static List<String> magicPathChildren(List<String> elements); static List<String> basePathChildren(List<String> elements); static String elementsToKey(List<String> elements); static String filename(List<String> elements); static String lastElement(List<String> strings); static Path magicSubdir(Path destDir); static List<String> finalDestination(List<String> elements);  }
@Test public void testFinalDestinationNoMagic() { assertEquals(l("first", "2"), finalDestination(l("first", "2"))); }
@Test public void testFinalDestinationMagic1() { assertEquals(l("first", "2"), finalDestination(l("first", MAGIC, "2"))); }
@Test public void testFinalDestinationMagic2() { assertEquals(l("first", "3.txt"), finalDestination(l("first", MAGIC, "2", "3.txt"))); }
@Test public void testFinalDestinationRootMagic2() { assertEquals(l("3.txt"), finalDestination(l(MAGIC, "2", "3.txt"))); }
@Test(expected = IllegalArgumentException.class) public void testFinalDestinationMagicNoChild() { finalDestination(l(MAGIC)); }
@Test public void testFinalDestinationBaseDirectChild() { finalDestination(l(MAGIC, BASE, "3.txt")); }
@Test(expected = IllegalArgumentException.class) public void testFinalDestinationBaseNoChild() { assertEquals(l(), finalDestination(l(MAGIC, BASE))); }
@Test public void testFinalDestinationBaseSubdirsChild() { assertEquals(l("2", "3.txt"), finalDestination(l(MAGIC, "4", BASE, "2", "3.txt"))); }
@Test public void testFinalDestinationIgnoresBaseBeforeMagic() { assertEquals(l(BASE, "home", "3.txt"), finalDestination(l(BASE, "home", MAGIC, "2", "3.txt"))); }