### Question:
FileChunkUtil { public static int getNumberOfChunks(File file, int chunkSize) { if (file == null || !file.exists()) { return 0; } else if (chunkSize <= 0) { return 0; } long fileSize = FileUtil.getFileSize(file); if (fileSize == 0) { return 1; } return (int) Math.ceil((double) fileSize / Math.abs(chunkSize)); } private  FileChunkUtil(); static int getNumberOfChunks(File file, int chunkSize); static Chunk getChunk(File file, int chunkSize, int chunkNumber, String chunkId); static void reassembly(List<File> fileParts, File destination);  }### Answer:
@Test public void testGetNumberOfChunksRandom() throws IOException { Random rnd = new Random(); for (int i = 0; i < 10; i++) { int genNOC = rnd.nextInt(100) + 1; File randomFile = FileTestUtil.createFileRandomContent(genNOC, parent); int resNOC = FileChunkUtil.getNumberOfChunks(randomFile, TestFileConfiguration.CHUNK_SIZE); assertEquals(genNOC, resNOC); randomFile.deleteOnExit(); } }
@Test public void testGetNumberOfChunksEmpty() throws IOException { File file = new File(parent, randomString()); FileUtils.write(file, ""); assertEquals(1, FileChunkUtil.getNumberOfChunks(file, TestFileConfiguration.CHUNK_SIZE)); assertEquals(1, FileChunkUtil.getNumberOfChunks(file, TestFileConfiguration.CHUNK_SIZE / 2)); file.deleteOnExit(); }
@Test public void testGetNumberOfChunksNotExisting() { File file = new File(parent, randomString()); assertEquals(0, FileChunkUtil.getNumberOfChunks(file, TestFileConfiguration.CHUNK_SIZE)); }
@Test public void testGetNumberOfChunksNull() { assertEquals(0, FileChunkUtil.getNumberOfChunks(null, TestFileConfiguration.CHUNK_SIZE)); }
@Test public void testGetNumberOfChunksSizeZero() throws IOException { File file = new File(parent, randomString()); FileUtils.write(file, "test"); assertEquals(0, FileChunkUtil.getNumberOfChunks(file, 0)); file.deleteOnExit(); }
@Test public void testGetNumberOfChunksSizeNegative() throws IOException { File file = new File(parent, randomString()); FileUtils.write(file, "test"); assertEquals(0, FileChunkUtil.getNumberOfChunks(file, -1 * TestFileConfiguration.CHUNK_SIZE)); file.deleteOnExit(); }