AssembleUtil { public static String getName(final String path) { if (path.length() == 0) throw new IllegalArgumentException("Empty path"); if (path.length() == 0) return path; final boolean end = path.charAt(path.length() - 1) == File.separatorChar; final int start = end ? path.lastIndexOf(File.separatorChar, path.length() - 2) : path.lastIndexOf(File.separatorChar); return start == -1 ? (end ? path.substring(0, path.length() - 1) : path) : end ? path.substring(start + 1, path.length() - 1) : path.substring(start + 1); } private  AssembleUtil(); static boolean hasFileInJar(final File jarFile, final String name); static String readFileFromJar(final File jarFile, final String name); static Set<String> getLocations(final Class<?> ... classes); static byte[] readBytes(final URL url); static byte[] readBytes(final InputStream in); static String toIndentedString(final Object[] a); static String toIndentedString(final Collection<?> l); static String toIndentedString(final Map<?,?> m); static boolean recurseDir(final File dir, final Predicate<File> predicate); static FileVisitResult recurseDir(final File dir, final Function<File,FileVisitResult> function); static int compare(final T[] a, final T[] b); static int compare(final List<T> a, final List<T> b); static boolean containsAll(final T[] a, final T[] b); static boolean containsAll(final T[] a, final T[] b, final Comparator<T> c); @SuppressWarnings("unchecked") static T[] retain(final T[] a, final T[] b, final int i, final int j, final int r); static T[] sort(final T[] array); static List<T> sort(final List<T> list); static String getNameId(final Object obj); static String getSimpleNameId(final Object obj); static String toString(final Object[] a, final String del); static String toString(final Collection<?> c, final String del); static void absorbProperties(final String command); static void forEachClass(final URL[] urls, final T arg, final BiConsumer<String,T> consumer); static URL toURL(final File file); static URL[] toURLs(final File ... files); static URL[] toURLs(final List<File> files); static URL[] toURLs(final Collection<File> files); static String convertToRegex(String pattern); static String classNameToResource(final String className); static String classNameToResource(final Class<?> cls); static String resourceToClassName(final String resource); static boolean isSystemProperty(final String key, final String deprecatedKey); static Pattern convertToNameRegex(String pattern); static File getSourceLocation(final URL url, final String resourcePath); static String getName(final String path); static File[] classPathToFiles(final String classpath); static URL toURL(final String path);  }
@Test public void testGetName() { try { AssembleUtil.getName(""); fail("Expected IllegalArgumentException"); } catch (final IllegalArgumentException e) { } final String name = "opentracing-specialagent-1.3.3-SNAPSHOT.jar"; final String s = File.separator; assertEquals(name, AssembleUtil.getName(name)); assertEquals(name, AssembleUtil.getName("." + s + name)); assertEquals(name, AssembleUtil.getName("foo" + s + "bar" + s + name)); }