HarddriveStorage implements FileStorage { @Override public boolean renameFile(final File file, final String newName) { if (contains(newName)) { return false; } final String oldName = file.getName(); final File renamedFile = getFile(oldName); if (renamedFile != null) { renamedFile.setName(newName); renamedFile.setTransactionTime(0); fileNameList.remove(oldName); fileNameList.add(newName); return true; } return false; } HarddriveStorage(final String name, final long capacity);  HarddriveStorage(final long capacity); @Override int getNumStoredFile(); @Override boolean reserveSpace(int fileSize); @Override double addReservedFile(final File file); @Override boolean hasPotentialAvailableSpace(final int fileSize); @Override boolean hasFile(final String fileName); @Override String getName(); @Override void setLatency(final double latency); @Override double getLatency(); @Override void setMaxTransferRate(final double maxTransferRate); @Override double getMaxTransferRate(); boolean setAvgSeekTime(final double seekTime); boolean setAvgSeekTime(final double seekTime, final ContinuousDistribution gen); double getAvgSeekTime(); @Override File getFile(final String fileName); @Override List<String> getFileNameList(); @Override List<File> getFileList(); @Override double getTransferTime(final String fileName); @Override double getTransferTime(final File file); @Override double getTransferTime(final int fileSize); @Override double addFile(final File file); @Override double addFile(final List<File> list); @Override File deleteFile(final String fileName); @Override double deleteFile(final File file); @Override boolean contains(final String fileName); @Override boolean contains(final File file); @Override boolean renameFile(final File file, final String newName); @Override long getCapacity(); @Override long getAvailableResource(); @Override long getAllocatedResource(); @Override boolean isAmountAvailable(long amountToCheck); @Override boolean isAmountAvailable(double amountToCheck); @Override boolean isFull();  }
@Test public void testRenameFile() { final HarddriveStorage instance = createHardDrive(); final List<File> fileList = createListOfFilesAndAddToHardDrive(instance); for(final File file: fileList){ final String oldName = file.getName(); final String newName = String.format("renamed-%s", oldName); assertTrue(instance.contains(oldName)); assertTrue(instance.renameFile(file, newName)); assertFalse(instance.contains(oldName)); final File result = instance.getFile(newName); assertEquals(file, result); assertEquals(file.getName(), result.getName()); } final File file1 = new File(FILE1, 100), file2 = new File("file2.txt", 100); instance.addFile(file1); instance.addFile(file2); assertFalse(instance.renameFile(file1, file2.getName())); final File notAddedFile = new File("file3.txt", 100); assertFalse(instance.renameFile(notAddedFile, "new-name.txt")); }