SurveyFileNameGenerator { @NonNull public String generateFileName(@NonNull String entryName) { if (entryName.isEmpty()) { return ""; } int fileSeparatorPosition = entryName.lastIndexOf("/"); return fileSeparatorPosition < 0 ? entryName : entryName.substring(fileSeparatorPosition + 1); } SurveyFileNameGenerator(); @NonNull String generateFileName(@NonNull String entryName);  }
@Test public void generateFileName_shouldReturnEmptyIfOnlySlash() throws Exception { SurveyFileNameGenerator fileNameGenerator = new SurveyFileNameGenerator(); String fileName = fileNameGenerator.generateFileName("/"); assertEquals("", fileName); }
@Test public void generateFileName_shouldReturnCorrectSurveyName() throws Exception { SurveyFileNameGenerator fileNameGenerator = new SurveyFileNameGenerator(); String fileName = fileNameGenerator.generateFileName("file.xml"); assertEquals("file.xml", fileName); fileName = fileNameGenerator.generateFileName("folder/file.xml"); assertEquals("file.xml", fileName); fileName = fileNameGenerator.generateFileName("folder/folder/file.xml"); assertEquals("file.xml", fileName); }