### Question:
AbstractResource implements ResourceInterface, Serializable { protected String getUniqueBaseName(String originalFileName) { Assert.hasLength(originalFileName, "File name must not be null or empty"); String baseName = FilenameUtils.getBaseName(originalFileName); String extension = FilenameUtils.getExtension(originalFileName); baseName = this.purgeBaseName(baseName); String suggestedName = baseName; int fileOrder = 1; while(this.exists(this.createFileName(suggestedName, extension))) { suggestedName = baseName + '_' + fileOrder; fileOrder ++; } return suggestedName; } AbstractResource(); @Override String getId(); @Override void setId(String id); @Override String getType(); @Override void setType(String typeCode); @Override @Deprecated String getDescr(); @Override @Deprecated void setDescr(String descr); @Override String getDescription(); @Override void setDescription(String description); @Override String getMainGroup(); @Override void setMainGroup(String mainGroup); @Override String getMasterFileName(); @Override void setMasterFileName(String masterFileName); @Override Date getCreationDate(); @Override void setCreationDate(Date creationDate); @Override Date getLastModified(); @Override void setLastModified(Date lastModified); @Override void addCategory(Category category); @Override List<Category> getCategories(); @Override void setCategories(List<Category> categories); void removeCategory(Category category); @Override String getFolder(); @Override void setFolder(String folder); void setProtectedBaseURL(String protBaseURL); @Override String[] getAllowedFileTypes(); void setAllowedExtensions(String allowedExtensions); @Override Map<String, String> getMetadata(); @Override void setMetadata(Map<String, String> metadata); @Override ResourceInterface getResourcePrototype(); @Override InputStream getResourceStream(ResourceInstance instance); @Override String getDefaultUrlPath(); void setStorageManager(IStorageManager storageManager); @Override String getMetadataIgnoreKeys(); @Override void setMetadataIgnoreKeys(String metadataIgnoreKeys); @Override String getOwner(); @Override void setOwner(String owner); @Override String getFolderPath(); @Override void setFolderPath(String folderPath);  }### Answer:
@Test(expected = IllegalArgumentException.class) public void nullFilenameShouldReturnException() { resource.getUniqueBaseName(null); }
@Test public void regularFileNameShouldReturnFileNameBase() { String originalName = "myfile.jpg"; String baseName = "myfile"; String uniqueBaseName = resource.getUniqueBaseName(originalName); assertEquals(baseName, uniqueBaseName); }
@Test public void repeatedFileNameShouldReturnFileNameBase() { String originalName = "myfile.jpg"; String baseName = "myfile"; String uniqueBaseName = resource.getUniqueBaseName(originalName); assertEquals(baseName, uniqueBaseName); resource.setFileExistsCountdown(1); String secondBaseName = resource.getUniqueBaseName(originalName); assertEquals(baseName + "_1", secondBaseName); resource.setFileExistsCountdown(10); String tenthName = resource.getUniqueBaseName(originalName); assertEquals(baseName + "_10", tenthName); }