### Question:
FileUtils { public static void copyFile(MultipartFile file, String destFilename) { try { File destFile = new File(destFilename); File destParentDir = new File(destFile.getParent()); if (!destParentDir.exists()) { org.apache.commons.io.FileUtils.forceMkdir(destParentDir); } Files.copy(file.getInputStream(), Paths.get(destFilename)); } catch (IOException e) { logger.error("failed to copy file , {} is empty file", file.getOriginalFilename(), e); } }  static void copyFile(MultipartFile file, String destFilename); static Resource file2Resource(String filename); static String file2String(MultipartFile file);  }### Answer:
@Test public void testCopyFile() throws IOException { String destFilename = rootPath + System.getProperty("file.separator") + "data.txt"; logger.info("destFilename: "+destFilename); String data = "data text"; InputStream targetStream = new ByteArrayInputStream(data.getBytes()); MultipartFile file = Mockito.mock(MultipartFile.class); Mockito.when(file.getInputStream()).thenReturn(targetStream); FileUtils.copyFile(file,destFilename); File destFile = new File(destFilename); assertTrue(destFile.exists()); }