BlockManipulationServiceImpl implements IBlockManipulationService { @Override public String getBlockUuidByNumber(Metafile metafile, int blockNumber) throws MetafileIsFolderException, BlockDoesNotExistException { List<String> blockUuidList = metafile.getBlockUuidList(); if (metafile.getProperties().containsValue(FileType.DIR.toString())) { StringBuilder sb = new StringBuilder(); sb.append(getMetafileInfoForLog(metafile, "getBlockUuidByNumber")); sb.append(", is folder."); throw new MetafileIsFolderException(sb.toString()); } else { if (blockUuidList.size() < blockNumber) { StringBuilder sb = new StringBuilder(); sb.append(getMetafileInfoForLog(metafile, "getBlockUuidByNumber")); sb.append(", has block count: "); sb.append(blockUuidList.size()); sb.append(", requested number is: "); sb.append(blockNumber); throw new BlockDoesNotExistException(sb.toString()); } } return blockUuidList.get(blockNumber); }  @Override String getNextBlockUuid(Metafile metafile); @Override String getBlockUuidByNumber(Metafile metafile, int blockNumber);  }
@Test(expected = BlockDoesNotExistException.class) public void getBlockUuidByNumber() throws BlockDoesNotExistException, MetafileIsFolderException { Map<String, String> properties = new HashMap<>(); properties.put("typeOnFs", FileType.FILE_BIN.toString()); metafile.setProperties(properties); String blockUuid1 = UUID.randomUUID().toString(); String blockUuid2 = UUID.randomUUID().toString(); String blockUuid3 = UUID.randomUUID().toString(); String blockUuid4 = UUID.randomUUID().toString(); String blockUuid5 = UUID.randomUUID().toString(); metafile.addBlockUuid(blockUuid1); metafile.addBlockUuid(blockUuid2); metafile.addBlockUuid(blockUuid3); metafile.addBlockUuid(blockUuid4); metafile.addBlockUuid(blockUuid5); String blockUuid = blockManipulationService.getBlockUuidByNumber(metafile, 0); assertEquals(blockUuid1, blockUuid); blockUuid = blockManipulationService.getBlockUuidByNumber(metafile, 1); assertEquals(blockUuid2, blockUuid); blockManipulationService.getBlockUuidByNumber(metafile, 9); }
@Test(expected = MetafileIsFolderException.class) public void getBlockUuidByNumberByFolder() throws BlockDoesNotExistException, MetafileIsFolderException { Map<String, String> properties = new HashMap<>(); properties.put("typeOnFs", FileType.DIR.toString()); metafile.setProperties(properties); blockManipulationService.getBlockUuidByNumber(metafile, 9); }