private String FILE_PATH = "com/levelup/java/io/sample.md";
@Test public void get_file_name_with_out_extension_java () { String separator = System.getProperty("file.separator"); int indexOfLastSeparator = FILE_PATH.lastIndexOf(separator); String filename = FILE_PATH.substring(indexOfLastSeparator + 1); int extensionIndex = filename.lastIndexOf("."); String fileExtension = filename.substring(0, extensionIndex); assertEquals("sample", fileExtension); }
@Test public void get_file_name_with_out_extension_guava () { String fileName = Files.getNameWithoutExtension(FILE_PATH); assertEquals("sample", fileName); }
@Test public void get_file_name_with_out_extension_apache () { String fileName = FilenameUtils.getBaseName(FILE_PATH); assertEquals("sample", fileName); }