FileUtility { public static void mergeFile(List<String> fileList, String newFile) { checkAbsolutePath(newFile); File newFileObject = new File(newFile); if (newFileObject.exists() && checkFileExist) { boolean result = newFileObject.delete(); if (!result) { throw new FileException("File control operation was failed.", newFile); } } else if (newFileObject.exists() && !checkFileExist) { throw new FileException(newFile + " is exist.", newFile); } FileOutputStream fos = null; FileChannel outputFileChannel = null; FileLock outputFileLock = null; try { fos = new FileOutputStream(newFileObject, true); outputFileChannel = fos.getChannel(); outputFileLock = outputFileChannel.lock(0L, Long.MAX_VALUE, false); File srcFileObject = null; for (String srcFile : fileList) { checkAbsolutePath(srcFile); srcFileObject = new File(srcFile); if (!srcFileObject.exists()) { throw new FileException(srcFile + " is not exist.", srcFile); } FileInputStream fis = null; FileChannel inputFileChannel = null; FileLock inputFileLock = null; try { fis = new FileInputStream(srcFileObject); inputFileChannel = fis.getChannel(); ByteBuffer buffer = ByteBuffer.allocate(1024); inputFileLock = inputFileChannel.lock(0L, Long.MAX_VALUE, true); while (inputFileChannel.position() < inputFileChannel .size()) { buffer.clear(); inputFileChannel.read(buffer); buffer.flip(); outputFileChannel.write(buffer); } } finally { if (inputFileLock != null) { inputFileLock.release(); } if (fis != null) { fis.close(); } if (inputFileChannel != null) { inputFileChannel.close(); } } } } catch (FileNotFoundException e) { throw new FileException("File control operation was failed.", e); } catch (IOException e) { throw new FileException("File control operation was failed.", e); } finally { try { if (outputFileLock != null) { outputFileLock.release(); } if (fos != null) { fos.close(); } if (outputFileChannel != null) { outputFileChannel.close(); } } catch (IOException e) { } } }  static void copyFile(String srcFile, String newFile); static void deleteFile(String srcFile); static void mergeFile(List<String> fileList, String newFile); static void renameFile(String srcFile, String newFile); static boolean isCheckFileExist(); static void setCheckFileExist(boolean checkFileExist);  }
@Test public void testMergeFile01() throws Exception { List<String> fileList = new ArrayList<String>(); String classFileName = this.getClass().getSimpleName() + ".class"; URL url = this.getClass().getResource(classFileName); String directoryPath = url.getPath().substring(0, url.getPath().length() - classFileName.length()); String newFile = directoryPath + "testMergeFile01_new.txt"; Field field = FileUtility.class.getDeclaredField("checkFileExist"); field.setAccessible(true); field.set(FileUtility.class, false); File testNewFile = new File(newFile); testNewFile.delete(); BufferedReader postReader = null; try { PowerMockito.mockStatic(FileUtility.class, Mockito.CALLS_REAL_METHODS); FileUtility.mergeFile(fileList, newFile); PowerMockito.verifyPrivate(FileUtility.class).invoke("checkAbsolutePath", newFile); File mergeFile = new File(newFile); assertTrue(mergeFile.exists()); postReader = new BufferedReader(new InputStreamReader( new FileInputStream(newFile))); assertFalse(postReader.ready()); } finally { if (postReader != null) { postReader.close(); } File file = new File(newFile); file.delete(); } }
@Test public void testMergeFile02() throws Exception { List<String> fileList = new ArrayList<String>(); String classFileName = this.getClass().getSimpleName() + ".class"; URL url = this.getClass().getResource(classFileName); String directoryPath = url.getPath().substring(0, url.getPath().length() - classFileName.length()); String newFile = directoryPath + "testMergeFile02_new.txt"; Field field = FileUtility.class.getDeclaredField("checkFileExist"); field.setAccessible(true); field.set(FileUtility.class, true); File testNewFile = new File(newFile); testNewFile.delete(); testNewFile.createNewFile(); FileWriter testNewFileFileWriter = null; BufferedReader postReader = null; try { testNewFileFileWriter = new FileWriter(testNewFile); testNewFileFileWriter.write("testMergeFile02_new.txtデータ"); testNewFileFileWriter.flush(); testNewFileFileWriter.close(); PowerMockito.mockStatic(FileUtility.class, Mockito.CALLS_REAL_METHODS); FileUtility.mergeFile(fileList, newFile); PowerMockito.verifyPrivate(FileUtility.class).invoke("checkAbsolutePath", newFile); File mergeFile = new File(newFile); assertTrue(mergeFile.exists()); postReader = new BufferedReader(new InputStreamReader( new FileInputStream(mergeFile))); assertFalse(postReader.ready()); } finally { if (testNewFileFileWriter != null) { testNewFileFileWriter.close(); } if (postReader != null) { postReader.close(); } File file = new File(newFile); file.delete(); } }
@Test public void testMergeFile03() throws Exception { List<String> fileList = new ArrayList<String>(); String classFileName = this.getClass().getSimpleName() + ".class"; URL url = this.getClass().getResource(classFileName); String directoryPath = url.getPath().substring(0, url.getPath().length() - classFileName.length()); String newFile = directoryPath + "testMergeFile03_new.txt"; Field field = FileUtility.class.getDeclaredField("checkFileExist"); field.setAccessible(true); field.set(FileUtility.class, false); File testNewFile = new File(newFile); testNewFile.delete(); testNewFile.createNewFile(); FileWriter testNewFileFileWriter = null; BufferedReader postReader = null; try { testNewFileFileWriter = new FileWriter(testNewFile); testNewFileFileWriter.write("testMergeFile03_new.txtデータ"); testNewFileFileWriter.flush(); testNewFileFileWriter.close(); PowerMockito.mockStatic(FileUtility.class, Mockito.CALLS_REAL_METHODS); FileUtility.mergeFile(fileList, newFile); fail("FileExceptionが発生しませんでした。失敗です。"); } catch (FileException e) { assertTrue(FileException.class.isAssignableFrom(e.getClass())); assertEquals(newFile + " is exist.", e.getMessage()); assertEquals(newFile, e.getFileName()); PowerMockito.verifyPrivate(FileUtility.class).invoke("checkAbsolutePath", newFile); File mergeFile = new File(newFile); assertTrue(mergeFile.exists()); postReader = new BufferedReader(new InputStreamReader( new FileInputStream(mergeFile))); assertTrue(postReader.ready()); String expectationResultData = "testMergeFile03_new.txtデータ"; String data = ""; for (int i = 0; i < expectationResultData.length(); i++) { assertTrue(i + "回目の判定で失敗しました。", postReader.ready()); data += (char) postReader.read(); } assertEquals(expectationResultData, data); assertFalse(postReader.ready()); } finally { if (testNewFileFileWriter != null) { testNewFileFileWriter.close(); } if (postReader != null) { postReader.close(); } File file = new File(newFile); file.delete(); } }
@Test public void testMergeFile04() throws Exception { String classFileName = this.getClass().getSimpleName() + ".class"; URL url = this.getClass().getResource(classFileName); String directoryPath = url.getPath().substring(0, url.getPath().length() - classFileName.length()); List<String> fileList = new ArrayList<String>(); String srcFile1 = directoryPath + "testMergeFile04_src1.txt"; fileList.add(srcFile1); String newFile = directoryPath + "testMergeFile04_new.txt"; Field field = FileUtility.class.getDeclaredField("checkFileExist"); field.setAccessible(true); field.set(FileUtility.class, true); File testSrcFile1 = new File(srcFile1); testSrcFile1.delete(); testSrcFile1.createNewFile(); File testNewFile = new File(newFile); testNewFile.delete(); FileWriter testSrcFile1FileWriter = null; FileWriter testNewFileFileWriter = null; try { testSrcFile1FileWriter = new FileWriter(testSrcFile1); testSrcFile1FileWriter.write("testMergeFile04_src1.txtデータ"); testSrcFile1FileWriter.flush(); testSrcFile1FileWriter.close(); testNewFileFileWriter = new FileWriter(testNewFile); testNewFileFileWriter.write("testMergeFile04_new.txtデータ"); testNewFileFileWriter.flush(); testNewFileFileWriter.close(); PowerMockito.mockStatic(FileUtility.class, Mockito.CALLS_REAL_METHODS); FileUtility.mergeFile(fileList, newFile); PowerMockito.verifyPrivate(FileUtility.class, Mockito.times(2)).invoke("checkAbsolutePath", Mockito.anyString()); PowerMockito.verifyPrivate(FileUtility.class).invoke("checkAbsolutePath", srcFile1); PowerMockito.verifyPrivate(FileUtility.class).invoke("checkAbsolutePath", newFile); File getFile = new File(newFile); FileContent testFileContent = new FileContent(testSrcFile1); FileContent fileContent = new FileContent(getFile); assertTrue(testFileContent.equals(fileContent)); } finally { if (testSrcFile1FileWriter != null) { testSrcFile1FileWriter.close(); } if (testNewFileFileWriter != null) { testNewFileFileWriter.close(); } File file = new File(srcFile1); file.delete(); file = new File(newFile); file.delete(); } }
@Test public void testMergeFile05() throws Exception { String classFileName = this.getClass().getSimpleName() + ".class"; URL url = this.getClass().getResource(classFileName); String directoryPath = url.getPath().substring(0, url.getPath().length() - classFileName.length()); List<String> fileList = new ArrayList<String>(); String srcFile1 = directoryPath + "testMergeFile05_src1.txt"; fileList.add(srcFile1); String srcFile2 = directoryPath + "testMergeFile05_src2.txt"; fileList.add(srcFile2); String srcFile3 = directoryPath + "testMergeFile05_src3.txt"; fileList.add(srcFile3); String newFile = directoryPath + "testMergeFile05_new.txt"; Field field = FileUtility.class.getDeclaredField("checkFileExist"); field.setAccessible(true); field.set(FileUtility.class, true); File testSrcFile1 = new File(srcFile1); testSrcFile1.delete(); testSrcFile1.createNewFile(); File testSrcFile2 = new File(srcFile2); testSrcFile2.delete(); testSrcFile2.createNewFile(); File testSrcFile3 = new File(srcFile3); testSrcFile3.delete(); testSrcFile3.createNewFile(); File testNewFile = new File(newFile); testNewFile.delete(); testNewFile.createNewFile(); FileWriter testSrcFile1FileWriter = null; FileWriter testSrcFile2FileWriter = null; FileWriter testSrcFile3FileWriter = null; FileWriter testNewFileFileWriter = null; BufferedReader postReader = null; try { testSrcFile1FileWriter = new FileWriter(testSrcFile1); testSrcFile1FileWriter.write("testMergeFile05_src1.txtデータ"); testSrcFile1FileWriter.flush(); testSrcFile1FileWriter.close(); testSrcFile2FileWriter = new FileWriter(testSrcFile2); testSrcFile2FileWriter.write("testMergeFile05_src2.txtデータ"); testSrcFile2FileWriter.flush(); testSrcFile2FileWriter.close(); testSrcFile3FileWriter = new FileWriter(testSrcFile3); testSrcFile3FileWriter.write("testMergeFile05_src3.txtデータ"); testSrcFile3FileWriter.flush(); testSrcFile3FileWriter.close(); testNewFileFileWriter = new FileWriter(testNewFile); testNewFileFileWriter.write("testMergeFile05_new.txtデータ"); testNewFileFileWriter.flush(); testNewFileFileWriter.close(); PowerMockito.mockStatic(FileUtility.class, Mockito.CALLS_REAL_METHODS); FileUtility.mergeFile(fileList, newFile); PowerMockito.verifyPrivate(FileUtility.class, Mockito.times(4)).invoke("checkAbsolutePath", Mockito.anyString()); PowerMockito.verifyPrivate(FileUtility.class).invoke("checkAbsolutePath", newFile); PowerMockito.verifyPrivate(FileUtility.class).invoke("checkAbsolutePath", srcFile1); PowerMockito.verifyPrivate(FileUtility.class).invoke("checkAbsolutePath", srcFile2); PowerMockito.verifyPrivate(FileUtility.class).invoke("checkAbsolutePath", srcFile3); File mergeFile = new File(newFile); assertTrue(mergeFile.exists()); postReader = new BufferedReader(new InputStreamReader( new FileInputStream(mergeFile))); assertTrue(postReader.ready()); String expectationResultData = "testMergeFile05_src1.txtデータ" + "testMergeFile05_src2.txtデータtestMergeFile05_src3.txtデータ"; String data = ""; for (int i = 0; i < expectationResultData.length(); i++) { assertTrue(i + "回目の判定で失敗しました。", postReader.ready()); data += (char) postReader.read(); } assertEquals(expectationResultData, data); assertFalse(postReader.ready()); } finally { if (testSrcFile1FileWriter != null) { testSrcFile1FileWriter.close(); } if (testSrcFile2FileWriter != null) { testSrcFile2FileWriter.close(); } if (testSrcFile3FileWriter != null) { testSrcFile3FileWriter.close(); } if (testNewFileFileWriter != null) { testNewFileFileWriter.close(); } if (postReader != null) { postReader.close(); } File file = new File(srcFile1); file.delete(); file = new File(srcFile2); file.delete(); file = new File(srcFile3); file.delete(); file = new File(newFile); file.delete(); } }
@Test public void testMergeFile06() throws Exception { String classFileName = this.getClass().getSimpleName() + ".class"; URL url = this.getClass().getResource(classFileName); String directoryPath = url.getPath().substring(0, url.getPath().length() - classFileName.length()); List<String> fileList = new ArrayList<String>(); String srcFile1 = directoryPath + "testMergeFile06_src1.txt"; fileList.add(srcFile1); String srcFile2 = directoryPath + "testMergeFile06_src2.txt"; fileList.add(srcFile2); String srcFile3 = directoryPath + "testMergeFile06_src3.txt"; fileList.add(srcFile3); String newFile = directoryPath + "testMergeFile06_new.txt"; Field field = FileUtility.class.getDeclaredField("checkFileExist"); field.setAccessible(true); field.set(FileUtility.class, true); File testSrcFile1 = new File(srcFile1); testSrcFile1.delete(); File testSrcFile2 = new File(srcFile2); testSrcFile2.delete(); File testSrcFile3 = new File(srcFile3); testSrcFile3.delete(); File testNewFile = new File(newFile); testNewFile.delete(); testNewFile.createNewFile(); FileWriter testNewFileFileWriter = null; BufferedReader postReader = null; try { testNewFileFileWriter = new FileWriter(testNewFile); testNewFileFileWriter.write("testMergeFile06_new.txtデータ"); testNewFileFileWriter.flush(); testNewFileFileWriter.close(); PowerMockito.mockStatic(FileUtility.class, Mockito.CALLS_REAL_METHODS); FileUtility.mergeFile(fileList, newFile); fail("FileExceptionが発生しませんでした。失敗です。"); } catch (FileException e) { assertTrue(FileException.class.isAssignableFrom(e.getClass())); assertEquals(srcFile1 + " is not exist.", e.getMessage()); assertEquals(srcFile1, e.getFileName()); PowerMockito.verifyPrivate(FileUtility.class, Mockito.times(2)).invoke("checkAbsolutePath", Mockito.anyString()); PowerMockito.verifyPrivate(FileUtility.class).invoke("checkAbsolutePath", srcFile1); PowerMockito.verifyPrivate(FileUtility.class).invoke("checkAbsolutePath", newFile); File mergeFile = new File(newFile); assertTrue(mergeFile.exists()); postReader = new BufferedReader(new InputStreamReader( new FileInputStream(mergeFile))); assertFalse(postReader.ready()); } finally { if (testNewFileFileWriter != null) { testNewFileFileWriter.close(); } if (postReader != null) { postReader.close(); } File file = new File(srcFile1); file.delete(); file = new File(srcFile2); file.delete(); file = new File(srcFile3); file.delete(); file = new File(newFile); file.delete(); } }
@Test public void testMergeFile07() throws Exception { String classFileName = this.getClass().getSimpleName() + ".class"; URL url = this.getClass().getResource(classFileName); String directoryPath = url.getPath().substring(0, url.getPath().length() - classFileName.length()); List<String> fileList = new ArrayList<String>(); String srcFile1 = directoryPath + "testMergeFile07_src1.txt"; fileList.add(srcFile1); String srcFile2 = directoryPath + "testMergeFile07_src2.txt"; fileList.add(srcFile2); String srcFile3 = directoryPath + "testMergeFile07_src3.txt"; fileList.add(srcFile3); String newFile = directoryPath + "testMergeFile07_new.txt"; Field field = FileUtility.class.getDeclaredField("checkFileExist"); field.setAccessible(true); field.set(FileUtility.class, true); File testSrcFile1 = new File(srcFile1); testSrcFile1.delete(); testSrcFile1.createNewFile(); File testSrcFile2 = new File(srcFile2); testSrcFile2.delete(); testSrcFile2.createNewFile(); File testSrcFile3 = new File(srcFile3); testSrcFile3.delete(); File testNewFile = new File(newFile); testNewFile.delete(); testNewFile.createNewFile(); FileWriter testSrcFile1FileWriter = null; FileWriter testSrcFile2FileWriter = null; FileWriter testNewFileFileWriter = null; BufferedReader postReader = null; try { testSrcFile1FileWriter = new FileWriter(testSrcFile1); testSrcFile1FileWriter.write("testMergeFile07_src1.txtデータ"); testSrcFile1FileWriter.flush(); testSrcFile1FileWriter.close(); testSrcFile2FileWriter = new FileWriter(testSrcFile2); testSrcFile2FileWriter.write("testMergeFile07_src2.txtデータ"); testSrcFile2FileWriter.flush(); testSrcFile2FileWriter.close(); testNewFileFileWriter = new FileWriter(testNewFile); testNewFileFileWriter.write("testMergeFile07_new.txtデータ"); testNewFileFileWriter.flush(); testNewFileFileWriter.close(); PowerMockito.mockStatic(FileUtility.class, Mockito.CALLS_REAL_METHODS); FileUtility.mergeFile(fileList, newFile); fail("FileExceptionが発生しませんでした。失敗です。"); } catch (FileException e) { assertTrue(FileException.class.isAssignableFrom(e.getClass())); assertEquals(srcFile3 + " is not exist.", e.getMessage()); assertEquals(srcFile3, e.getFileName()); PowerMockito.verifyPrivate(FileUtility.class, Mockito.times(4)).invoke("checkAbsolutePath", Mockito.anyString()); PowerMockito.verifyPrivate(FileUtility.class).invoke("checkAbsolutePath", newFile); PowerMockito.verifyPrivate(FileUtility.class).invoke("checkAbsolutePath", srcFile1); PowerMockito.verifyPrivate(FileUtility.class).invoke("checkAbsolutePath", srcFile2); PowerMockito.verifyPrivate(FileUtility.class).invoke("checkAbsolutePath", srcFile3); File mergeFile = new File(newFile); assertTrue(mergeFile.exists()); postReader = new BufferedReader(new InputStreamReader( new FileInputStream(mergeFile))); assertTrue(postReader.ready()); String expectationResultData = "testMergeFile07_src1.txtデータ" + "testMergeFile07_src2.txtデータ"; String data = ""; for (int i = 0; i < expectationResultData.length(); i++) { assertTrue(i + "回目の判定で失敗しました。", postReader.ready()); data += (char) postReader.read(); } assertEquals(expectationResultData, data); assertFalse(postReader.ready()); } finally { if (testSrcFile1FileWriter != null) { testSrcFile1FileWriter.close(); } if (testSrcFile2FileWriter != null) { testSrcFile2FileWriter.close(); } if (testNewFileFileWriter != null) { testNewFileFileWriter.close(); } if (postReader != null) { postReader.close(); } File file = new File(srcFile1); file.delete(); file = new File(srcFile2); file.delete(); file = new File(srcFile3); file.delete(); file = new File(newFile); file.delete(); } }
@Test public void testMergeFile08() throws Exception { String classFileName = this.getClass().getSimpleName() + ".class"; URL url = this.getClass().getResource(classFileName); String directoryPath = url.getPath().substring(0, url.getPath().length() - classFileName.length()); List<String> fileList = new ArrayList<String>(); String srcFile1 = directoryPath + "testMergeFile08_src1.txt"; fileList.add(srcFile1); String srcFile2 = directoryPath + "testMergeFile08_src2.txt"; fileList.add(srcFile2); String srcFile3 = directoryPath + "testMergeFile08_src3.txt"; fileList.add(srcFile3); String newFile = directoryPath + "testMergeFile08_new.txt"; Field field = FileUtility.class.getDeclaredField("checkFileExist"); field.setAccessible(true); field.set(FileUtility.class, true); File testSrcFile1 = new File(srcFile1); testSrcFile1.delete(); testSrcFile1.createNewFile(); File testSrcFile2 = new File(srcFile2); testSrcFile2.delete(); testSrcFile2.createNewFile(); File testSrcFile3 = new File(srcFile3); testSrcFile3.delete(); testSrcFile3.createNewFile(); File testNewFile = new File(newFile); testNewFile.delete(); testNewFile.createNewFile(); IOException ioException = new IOException("testMergeFile08例外"); FileChannel fileChannel = PowerMockito.mock(FileChannel.class, Mockito.CALLS_REAL_METHODS); Mockito.doNothing().when(fileChannel).close(); Mockito.when(fileChannel.position()).thenThrow(ioException); FileInputStream fis = Mockito.mock(FileInputStream.class, Mockito.RETURNS_DEFAULTS); Mockito.when(fis.getChannel()).thenReturn(fileChannel); PowerMockito.spy(FileInputStream.class); PowerMockito.whenNew(FileInputStream.class).withAnyArguments().thenReturn(fis); FileWriter testSrcFile1FileWriter = null; FileWriter testSrcFile2FileWriter = null; FileWriter testSrcFile3FileWriter = null; FileWriter testNewFileFileWriter = null; BufferedReader postReader = null; try { testSrcFile1FileWriter = new FileWriter(testSrcFile1); testSrcFile1FileWriter.write("testMergeFile08_src1.txtデータ"); testSrcFile1FileWriter.flush(); testSrcFile1FileWriter.close(); testSrcFile2FileWriter = new FileWriter(testSrcFile2); testSrcFile2FileWriter.write("testMergeFile08_src2.txtデータ"); testSrcFile2FileWriter.flush(); testSrcFile2FileWriter.close(); testSrcFile3FileWriter = new FileWriter(testSrcFile3); testSrcFile3FileWriter.write("testMergeFile08_src3.txtデータ"); testSrcFile3FileWriter.flush(); testSrcFile3FileWriter.close(); testNewFileFileWriter = new FileWriter(testNewFile); testNewFileFileWriter.write("testMergeFile08_new.txtデータ"); testNewFileFileWriter.flush(); testNewFileFileWriter.close(); PowerMockito.mockStatic(FileUtility.class, Mockito.CALLS_REAL_METHODS); FileUtility.mergeFile(fileList, newFile); fail("FileExceptionが発生しませんでした。失敗です。"); } catch (FileException e) { assertTrue(FileException.class.isAssignableFrom(e.getClass())); assertEquals("File control operation was failed.", e.getMessage()); assertSame(ioException, e.getCause()); PowerMockito.verifyPrivate(FileUtility.class, Mockito.times(2)).invoke("checkAbsolutePath", Mockito.anyString()); PowerMockito.verifyPrivate(FileUtility.class).invoke("checkAbsolutePath", newFile); PowerMockito.verifyPrivate(FileUtility.class).invoke("checkAbsolutePath", srcFile1); File mergeFile = new File(newFile); assertTrue(mergeFile.exists()); postReader = new BufferedReader(new InputStreamReader( new FileInputStream(mergeFile))); assertFalse(postReader.ready()); } finally { if (testSrcFile1FileWriter != null) { testSrcFile1FileWriter.close(); } if (testSrcFile2FileWriter != null) { testSrcFile2FileWriter.close(); } if (testSrcFile3FileWriter != null) { testSrcFile3FileWriter.close(); } if (testNewFileFileWriter != null) { testNewFileFileWriter.close(); } if (postReader != null) { postReader.close(); } File file = new File(srcFile1); file.delete(); file = new File(srcFile2); file.delete(); file = new File(srcFile3); file.delete(); file = new File(newFile); file.delete(); } }
@Test public void testMergeFile09() throws Exception { String classFileName = this.getClass().getSimpleName() + ".class"; URL url = this.getClass().getResource(classFileName); String directoryPath = url.getPath().substring(0, url.getPath().length() - classFileName.length()); List<String> fileList = new ArrayList<String>(); String srcFile1 = directoryPath + "testMergeFile09_src1.txt"; fileList.add(srcFile1); String srcFile2 = directoryPath + "testMergeFile09_src2.txt"; fileList.add(srcFile2); String srcFile3 = directoryPath + "testMergeFile09_src3.txt"; fileList.add(srcFile3); String newFile = directoryPath + "testMergeFile09_new.txt"; Field field = FileUtility.class.getDeclaredField("checkFileExist"); field.setAccessible(true); field.set(FileUtility.class, true); File testSrcFile1 = new File(srcFile1); testSrcFile1.delete(); testSrcFile1.createNewFile(); File testSrcFile2 = new File(srcFile2); testSrcFile2.delete(); testSrcFile2.createNewFile(); File testSrcFile3 = new File(srcFile3); testSrcFile3.delete(); testSrcFile3.createNewFile(); File testNewFile = new File(newFile); testNewFile.delete(); testNewFile.createNewFile(); IOException ioException = new IOException("testMergeFile09例外"); FileOutputStream fos = Mockito.mock(FileOutputStream.class, Mockito.RETURNS_MOCKS); Mockito.doThrow(ioException).when(fos).close(); PowerMockito.spy(FileOutputStream.class); PowerMockito.whenNew(FileOutputStream.class).withArguments(testNewFile, true).thenReturn(fos); FileWriter testSrcFile1FileWriter = null; FileWriter testSrcFile2FileWriter = null; FileWriter testSrcFile3FileWriter = null; FileWriter testNewFileFileWriter = null; BufferedReader postReader = null; try { testSrcFile1FileWriter = new FileWriter(testSrcFile1); testSrcFile1FileWriter.write("testMergeFile09_src1.txtデータ"); testSrcFile1FileWriter.flush(); testSrcFile1FileWriter.close(); testSrcFile2FileWriter = new FileWriter(testSrcFile2); testSrcFile2FileWriter.write("testMergeFile09_src2.txtデータ"); testSrcFile2FileWriter.flush(); testSrcFile2FileWriter.close(); testSrcFile3FileWriter = new FileWriter(testSrcFile3); testSrcFile3FileWriter.write("testMergeFile09_src3.txtデータ"); testSrcFile3FileWriter.flush(); testSrcFile3FileWriter.close(); testNewFileFileWriter = new FileWriter(testNewFile); testNewFileFileWriter.write("testMergeFile09_new.txtデータ"); testNewFileFileWriter.flush(); testNewFileFileWriter.close(); PowerMockito.mockStatic(FileUtility.class, Mockito.CALLS_REAL_METHODS); FileUtility.mergeFile(fileList, newFile); PowerMockito.verifyPrivate(FileUtility.class, Mockito.times(4)).invoke("checkAbsolutePath", Mockito.anyString()); PowerMockito.verifyPrivate(FileUtility.class).invoke("checkAbsolutePath", newFile); PowerMockito.verifyPrivate(FileUtility.class).invoke("checkAbsolutePath", srcFile1); PowerMockito.verifyPrivate(FileUtility.class).invoke("checkAbsolutePath", srcFile2); PowerMockito.verifyPrivate(FileUtility.class).invoke("checkAbsolutePath", srcFile3); } finally { if (testSrcFile1FileWriter != null) { testSrcFile1FileWriter.close(); } if (testSrcFile2FileWriter != null) { testSrcFile2FileWriter.close(); } if (testSrcFile3FileWriter != null) { testSrcFile3FileWriter.close(); } if (testNewFileFileWriter != null) { testNewFileFileWriter.close(); } if (postReader != null) { postReader.close(); } File file = new File(srcFile1); file.delete(); file = new File(srcFile2); file.delete(); file = new File(srcFile3); file.delete(); file = new File(newFile); file.delete(); } }
@Test public void testMergeFile10() throws Exception { String classFileName = this.getClass().getSimpleName() + ".class"; URL url = this.getClass().getResource(classFileName); String directoryPath = url.getPath().substring(0, url.getPath().length() - classFileName.length()); List<String> fileList = new ArrayList<String>(); String srcFile1 = directoryPath + "testMergeFile10_src1.txt"; fileList.add(srcFile1); String srcFile2 = directoryPath + "testMergeFile10_src2.txt"; fileList.add(srcFile2); String srcFile3 = directoryPath + "testMergeFile10_src3.txt"; fileList.add(srcFile3); String newFile = directoryPath + "testMergeFile10_new.txt"; Field field = FileUtility.class.getDeclaredField("checkFileExist"); field.setAccessible(true); field.set(FileUtility.class, true); File testSrcFile1 = new File(srcFile1); testSrcFile1.delete(); testSrcFile1.createNewFile(); File testSrcFile2 = new File(srcFile2); testSrcFile2.delete(); testSrcFile2.createNewFile(); File testSrcFile3 = new File(srcFile3); testSrcFile3.delete(); testSrcFile3.createNewFile(); File testNewFile = new File(newFile); testNewFile.delete(); testNewFile.createNewFile(); FileNotFoundException fileNotFoundException = new FileNotFoundException( "testMergeFile10例外"); PowerMockito.spy(FileWriter.class); PowerMockito.whenNew(FileOutputStream.class).withArguments(testNewFile, true).thenThrow(fileNotFoundException); FileWriter testSrcFile1FileWriter = null; FileWriter testSrcFile2FileWriter = null; FileWriter testSrcFile3FileWriter = null; FileWriter testNewFileFileWriter = null; try { testSrcFile1FileWriter = new FileWriter(testSrcFile1); testSrcFile1FileWriter.write("testMergeFile10_src1.txtデータ"); testSrcFile1FileWriter.flush(); testSrcFile1FileWriter.close(); testSrcFile2FileWriter = new FileWriter(testSrcFile2); testSrcFile2FileWriter.write("testMergeFile10_src2.txtデータ"); testSrcFile2FileWriter.flush(); testSrcFile2FileWriter.close(); testSrcFile3FileWriter = new FileWriter(testSrcFile3); testSrcFile3FileWriter.write("testMergeFile10_src3.txtデータ"); testSrcFile3FileWriter.flush(); testSrcFile3FileWriter.close(); testNewFileFileWriter = new FileWriter(testNewFile); testNewFileFileWriter.write("testMergeFile10_new.txtデータ"); testNewFileFileWriter.flush(); testNewFileFileWriter.close(); PowerMockito.mockStatic(FileUtility.class, Mockito.CALLS_REAL_METHODS); FileUtility.mergeFile(fileList, newFile); fail("FileExceptionが発生しませんでした。失敗です。"); } catch (FileException e) { assertTrue(FileException.class.isAssignableFrom(e.getClass())); assertEquals("File control operation was failed.", e.getMessage()); assertSame(fileNotFoundException, e.getCause()); PowerMockito.verifyPrivate(FileUtility.class).invoke("checkAbsolutePath", Mockito.anyString()); PowerMockito.verifyPrivate(FileUtility.class).invoke("checkAbsolutePath", newFile); File mergeFile = new File(newFile); assertFalse(mergeFile.exists()); } finally { if (testSrcFile1FileWriter != null) { testSrcFile1FileWriter.close(); } if (testSrcFile2FileWriter != null) { testSrcFile2FileWriter.close(); } if (testSrcFile3FileWriter != null) { testSrcFile3FileWriter.close(); } if (testNewFileFileWriter != null) { testNewFileFileWriter.close(); } File file = new File(srcFile1); file.delete(); file = new File(srcFile2); file.delete(); file = new File(srcFile3); file.delete(); file = new File(newFile); file.delete(); } }
@Test public void testMergeFile11() throws Exception { List<String> fileList = null; String classFileName = this.getClass().getSimpleName() + ".class"; URL url = this.getClass().getResource(classFileName); String directoryPath = url.getPath().substring(0, url.getPath().length() - classFileName.length()); String newFile = directoryPath + "testMergeFile11_new.txt"; Field field = FileUtility.class.getDeclaredField("checkFileExist"); field.setAccessible(true); field.set(FileUtility.class, true); File testNewFile = new File(newFile); testNewFile.delete(); testNewFile.createNewFile(); FileWriter testNewFileFileWriter = null; BufferedReader postReader = null; try { testNewFileFileWriter = new FileWriter(testNewFile); testNewFileFileWriter.write("testMergeFile11_new.txtデータ"); testNewFileFileWriter.flush(); testNewFileFileWriter.close(); PowerMockito.mockStatic(FileUtility.class, Mockito.CALLS_REAL_METHODS); FileUtility.mergeFile(fileList, newFile); fail("NullPointerExceptionが発生しませんでした。失敗です。"); } catch (NullPointerException e) { assertTrue(NullPointerException.class .isAssignableFrom(e.getClass())); PowerMockito.verifyPrivate(FileUtility.class).invoke("checkAbsolutePath", newFile); File mergeFile = new File(newFile); assertTrue(mergeFile.exists()); postReader = new BufferedReader(new InputStreamReader( new FileInputStream(mergeFile))); assertFalse(postReader.ready()); } finally { if (testNewFileFileWriter != null) { testNewFileFileWriter.close(); } if (postReader != null) { postReader.close(); } File file = new File(newFile); file.delete(); } }
@Test public void testMergeFile12() throws Exception { String classFileName = this.getClass().getSimpleName() + ".class"; URL url = this.getClass().getResource(classFileName); String directoryPath = url.getPath().substring(0, url.getPath().length() - classFileName.length()); List<String> fileList = new ArrayList<String>(); String srcFile1 = directoryPath + "testMergeFile12_src1.txt"; fileList.add(srcFile1); String srcFile2 = directoryPath + "testMergeFile12_src2.txt"; fileList.add(srcFile2); String srcFile3 = directoryPath + "testMergeFile12_src3.txt"; fileList.add(srcFile3); String newFile = null; Field field = FileUtility.class.getDeclaredField("checkFileExist"); field.setAccessible(true); field.set(FileUtility.class, true); File testSrcFile1 = new File(srcFile1); testSrcFile1.delete(); testSrcFile1.createNewFile(); File testSrcFile2 = new File(srcFile2); testSrcFile2.delete(); testSrcFile2.createNewFile(); File testSrcFile3 = new File(srcFile3); testSrcFile3.delete(); testSrcFile3.createNewFile(); FileWriter testSrcFile1FileWriter = null; FileWriter testSrcFile2FileWriter = null; FileWriter testSrcFile3FileWriter = null; try { testSrcFile1FileWriter = new FileWriter(testSrcFile1); testSrcFile1FileWriter.write("testMergeFile12_src1.txtデータ"); testSrcFile1FileWriter.flush(); testSrcFile1FileWriter.close(); testSrcFile2FileWriter = new FileWriter(testSrcFile2); testSrcFile2FileWriter.write("testMergeFile12_src2.txtデータ"); testSrcFile2FileWriter.flush(); testSrcFile2FileWriter.close(); testSrcFile3FileWriter = new FileWriter(testSrcFile3); testSrcFile3FileWriter.write("testMergeFile12_src3.txtデータ"); testSrcFile3FileWriter.flush(); testSrcFile3FileWriter.close(); PowerMockito.mockStatic(FileUtility.class, Mockito.CALLS_REAL_METHODS); FileUtility.mergeFile(fileList, newFile); fail("FileExceptionが発生しませんでした。失敗です。"); } catch (FileException e) { assertTrue(FileException.class.isAssignableFrom(e.getClass())); assertEquals("File path is not set.", e.getMessage()); assertNull(e.getFileName()); PowerMockito.verifyPrivate(FileUtility.class).invoke("checkAbsolutePath", newFile); } finally { if (testSrcFile1FileWriter != null) { testSrcFile1FileWriter.close(); } if (testSrcFile2FileWriter != null) { testSrcFile2FileWriter.close(); } if (testSrcFile3FileWriter != null) { testSrcFile3FileWriter.close(); } File file = new File(srcFile1); file.delete(); file = new File(srcFile2); file.delete(); file = new File(srcFile3); file.delete(); } }
@Test public void testMergeFile13() throws Exception { String classFileName = this.getClass().getSimpleName() + ".class"; URL url = this.getClass().getResource(classFileName); String directoryPath = url.getPath().substring(0, url.getPath().length() - classFileName.length()); List<String> fileList = new ArrayList<String>(); String srcFile1 = directoryPath + "testMergeFile13_src1.txt"; fileList.add(srcFile1); String srcFile2 = directoryPath + "testMergeFile13_src2.txt"; fileList.add(srcFile2); String srcFile3 = directoryPath + "testMergeFile13_src3.txt"; fileList.add(srcFile3); String newFile = "testMergeFile13_new.txt"; Field field = FileUtility.class.getDeclaredField("checkFileExist"); field.setAccessible(true); field.set(FileUtility.class, false); File testSrcFile1 = new File(srcFile1); testSrcFile1.delete(); testSrcFile1.createNewFile(); File testSrcFile2 = new File(srcFile2); testSrcFile2.delete(); testSrcFile2.createNewFile(); File testSrcFile3 = new File(srcFile3); testSrcFile3.delete(); testSrcFile3.createNewFile(); File testNewFile = new File(directoryPath + newFile); testNewFile.delete(); testNewFile.createNewFile(); FileWriter testSrcFile1FileWriter = null; FileWriter testSrcFile2FileWriter = null; FileWriter testSrcFile3FileWriter = null; FileWriter testNewFileFileWriter = null; BufferedReader postReader = null; try { testSrcFile1FileWriter = new FileWriter(testSrcFile1); testSrcFile1FileWriter.write("testMergeFile13_src1.txtデータ"); testSrcFile1FileWriter.flush(); testSrcFile1FileWriter.close(); testSrcFile2FileWriter = new FileWriter(testSrcFile2); testSrcFile2FileWriter.write("testMergeFile13_src2.txtデータ"); testSrcFile2FileWriter.flush(); testSrcFile2FileWriter.close(); testSrcFile3FileWriter = new FileWriter(testSrcFile3); testSrcFile3FileWriter.write("testMergeFile13_src3.txtデータ"); testSrcFile3FileWriter.flush(); testSrcFile3FileWriter.close(); testNewFileFileWriter = new FileWriter(testNewFile); testNewFileFileWriter.write("testMergeFile13_new.txtデータ"); testNewFileFileWriter.flush(); testNewFileFileWriter.close(); PowerMockito.mockStatic(FileUtility.class, Mockito.CALLS_REAL_METHODS); FileUtility.mergeFile(fileList, newFile); fail("FileExceptionが発生しませんでした。失敗です。"); } catch (FileException e) { assertTrue(FileException.class.isAssignableFrom(e.getClass())); assertEquals("File path is not absolute.", e.getMessage()); assertEquals(newFile, e.getFileName()); PowerMockito.verifyPrivate(FileUtility.class).invoke("checkAbsolutePath", newFile); File mergeFile = new File(directoryPath + newFile); assertTrue(mergeFile.exists()); postReader = new BufferedReader(new InputStreamReader( new FileInputStream(mergeFile))); assertTrue(postReader.ready()); String expectationResultData = "testMergeFile13_new.txtデータ"; String data = ""; for (int i = 0; i < expectationResultData.length(); i++) { assertTrue(i + "回目の判定で失敗しました。", postReader.ready()); data += (char) postReader.read(); } assertEquals(expectationResultData, data); assertFalse(postReader.ready()); } finally { if (testSrcFile1FileWriter != null) { testSrcFile1FileWriter.close(); } if (testSrcFile2FileWriter != null) { testSrcFile2FileWriter.close(); } if (testSrcFile3FileWriter != null) { testSrcFile3FileWriter.close(); } if (postReader != null) { postReader.close(); } File file = new File(srcFile1); file.delete(); file = new File(srcFile2); file.delete(); file = new File(srcFile3); file.delete(); file = new File(directoryPath + newFile); file.delete(); } }
@Test public void testMergeFile14() throws Exception { String classFileName = this.getClass().getSimpleName() + ".class"; URL url = this.getClass().getResource(classFileName); String directoryPath = url.getPath().substring(0, url.getPath().length() - classFileName.length()); List<String> fileList = new ArrayList<String>(); String srcFile1 = directoryPath + "testMergeFile14_src1.txt"; fileList.add(srcFile1); String srcFile2 = null; fileList.add(srcFile2); String srcFile3 = directoryPath + "testMergeFile14_src3.txt"; fileList.add(srcFile3); String newFile = directoryPath + "testMergeFile14_new.txt"; Field field = FileUtility.class.getDeclaredField("checkFileExist"); field.setAccessible(true); field.set(FileUtility.class, true); File testSrcFile1 = new File(srcFile1); testSrcFile1.delete(); testSrcFile1.createNewFile(); File testSrcFile3 = new File(srcFile3); testSrcFile3.delete(); testSrcFile3.createNewFile(); File testNewFile = new File(newFile); testNewFile.delete(); testNewFile.createNewFile(); FileWriter testSrcFile1FileWriter = null; FileWriter testSrcFile3FileWriter = null; FileWriter testNewFileFileWriter = null; BufferedReader postReader = null; try { testSrcFile1FileWriter = new FileWriter(testSrcFile1); testSrcFile1FileWriter.write("testMergeFile14_src1.txtデータ"); testSrcFile1FileWriter.flush(); testSrcFile1FileWriter.close(); testSrcFile3FileWriter = new FileWriter(testSrcFile3); testSrcFile3FileWriter.write("testMergeFile14_src3.txtデータ"); testSrcFile3FileWriter.flush(); testSrcFile3FileWriter.close(); testNewFileFileWriter = new FileWriter(testNewFile); testNewFileFileWriter.write("testMergeFile14_new.txtデータ"); testNewFileFileWriter.flush(); testNewFileFileWriter.close(); PowerMockito.mockStatic(FileUtility.class, Mockito.CALLS_REAL_METHODS); FileUtility.mergeFile(fileList, newFile); fail("FileExceptionが発生しませんでした。失敗です。"); } catch (FileException e) { assertTrue(FileException.class.isAssignableFrom(e.getClass())); assertEquals("File path is not set.", e.getMessage()); assertNull(e.getFileName()); PowerMockito.verifyPrivate(FileUtility.class, Mockito.times(3)).invoke("checkAbsolutePath", Mockito.anyString()); PowerMockito.verifyPrivate(FileUtility.class).invoke("checkAbsolutePath", newFile); PowerMockito.verifyPrivate(FileUtility.class).invoke("checkAbsolutePath", srcFile1); File mergeFile = new File(newFile); assertTrue(mergeFile.exists()); postReader = new BufferedReader(new InputStreamReader( new FileInputStream(mergeFile))); assertTrue(postReader.ready()); String expectationResultData = "testMergeFile14_src1.txtデータ"; String data = ""; for (int i = 0; i < expectationResultData.length(); i++) { assertTrue(i + "回目の判定で失敗しました。", postReader.ready()); data += (char) postReader.read(); } assertEquals(expectationResultData, data); assertFalse(postReader.ready()); } finally { if (testSrcFile1FileWriter != null) { testSrcFile1FileWriter.close(); } if (testSrcFile3FileWriter != null) { testSrcFile3FileWriter.close(); } if (postReader != null) { postReader.close(); } File file = new File(srcFile1); file.delete(); file = new File(srcFile3); file.delete(); file = new File(newFile); file.delete(); } }
@Test public void testMergeFile15() throws Exception { String classFileName = this.getClass().getSimpleName() + ".class"; URL url = this.getClass().getResource(classFileName); String directoryPath = url.getPath().substring(0, url.getPath().length() - classFileName.length()); List<String> fileList = new ArrayList<String>(); String srcFile1 = directoryPath + "testMergeFile14_src1.txt"; fileList.add(srcFile1); String srcFile2 = directoryPath + "testMergeFile14_src2.txt"; fileList.add(srcFile2); String srcFile3 = "testMergeFile14_src3.txt"; fileList.add(srcFile3); String newFile = directoryPath + "testMergeFile14_new.txt"; Field field = FileUtility.class.getDeclaredField("checkFileExist"); field.setAccessible(true); field.set(FileUtility.class, true); File testSrcFile1 = new File(srcFile1); testSrcFile1.delete(); testSrcFile1.createNewFile(); File testSrcFile2 = new File(srcFile2); testSrcFile2.delete(); testSrcFile2.createNewFile(); File testSrcFile3 = new File(directoryPath + srcFile3); testSrcFile3.delete(); testSrcFile3.createNewFile(); File testNewFile = new File(newFile); testNewFile.delete(); testNewFile.createNewFile(); FileWriter testSrcFile1FileWriter = null; FileWriter testSrcFile2FileWriter = null; FileWriter testSrcFile3FileWriter = null; FileWriter testNewFileFileWriter = null; BufferedReader postReader = null; try { testSrcFile1FileWriter = new FileWriter(testSrcFile1); testSrcFile1FileWriter.write("testMergeFile15_src1.txtデータ"); testSrcFile1FileWriter.flush(); testSrcFile1FileWriter.close(); testSrcFile2FileWriter = new FileWriter(testSrcFile2); testSrcFile2FileWriter.write("testMergeFile15_src2.txtデータ"); testSrcFile2FileWriter.flush(); testSrcFile2FileWriter.close(); testSrcFile3FileWriter = new FileWriter(testSrcFile3); testSrcFile3FileWriter.write("testMergeFile15_src3.txtデータ"); testSrcFile3FileWriter.flush(); testSrcFile3FileWriter.close(); testNewFileFileWriter = new FileWriter(testNewFile); testNewFileFileWriter.write("testMergeFile15_new.txtデータ"); testNewFileFileWriter.flush(); testNewFileFileWriter.close(); PowerMockito.mockStatic(FileUtility.class, Mockito.CALLS_REAL_METHODS); FileUtility.mergeFile(fileList, newFile); fail("FileExceptionが発生しませんでした。失敗です。"); } catch (FileException e) { assertTrue(FileException.class.isAssignableFrom(e.getClass())); assertEquals("File path is not absolute.", e.getMessage()); assertEquals(srcFile3, e.getFileName()); PowerMockito.verifyPrivate(FileUtility.class, Mockito.times(4)).invoke("checkAbsolutePath", Mockito.anyString()); PowerMockito.verifyPrivate(FileUtility.class).invoke("checkAbsolutePath", newFile); PowerMockito.verifyPrivate(FileUtility.class).invoke("checkAbsolutePath", srcFile1); PowerMockito.verifyPrivate(FileUtility.class).invoke("checkAbsolutePath", srcFile2); PowerMockito.verifyPrivate(FileUtility.class).invoke("checkAbsolutePath", srcFile3); File mergeFile = new File(newFile); assertTrue(mergeFile.exists()); postReader = new BufferedReader(new InputStreamReader( new FileInputStream(mergeFile))); assertTrue(postReader.ready()); String expectationResultData = "testMergeFile15_src1.txtデータ" + "testMergeFile15_src2.txtデータ"; String data = ""; for (int i = 0; i < expectationResultData.length(); i++) { assertTrue(i + "回目の判定で失敗しました。", postReader.ready()); data += (char) postReader.read(); } assertEquals(expectationResultData, data); assertFalse(postReader.ready()); } finally { if (testSrcFile1FileWriter != null) { testSrcFile1FileWriter.close(); } if (testSrcFile2FileWriter != null) { testSrcFile2FileWriter.close(); } if (testSrcFile3FileWriter != null) { testSrcFile3FileWriter.close(); } if (postReader != null) { postReader.close(); } File file = new File(srcFile1); file.delete(); file = new File(srcFile2); file.delete(); file = new File(directoryPath + srcFile3); file.delete(); file = new File(newFile); file.delete(); } }
@Ignore @Test public void _ignore_testMergeFile16() throws Exception { List<String> fileList = new ArrayList<String>(); String classFileName = this.getClass().getSimpleName() + ".class"; URL url = this.getClass().getResource(classFileName); String directoryPath = url.getPath().substring(0, url.getPath().length() - classFileName.length()); String newFile = directoryPath + "testMergeFile16_new.txt"; ReflectionTestUtils.setField(FileUtility.class, "checkFileExist", true); File testNewFile = new File(newFile); testNewFile.delete(); testNewFile.createNewFile(); FileWriter testNewFileFileWriter = null; FileInputStream fis = null; FileLock lock = null; BufferedReader postReader = null; try { testNewFileFileWriter = new FileWriter(testNewFile); testNewFileFileWriter.write("testMergeFile16_new.txtデータ"); testNewFileFileWriter.flush(); testNewFileFileWriter.close(); fis = new FileInputStream(testNewFile); lock = fis.getChannel().lock(0L, Long.MAX_VALUE, true); PowerMockito.mockStatic(FileUtility.class, Mockito.CALLS_REAL_METHODS); FileUtility.mergeFile(fileList, newFile); fail("FileExceptionが発生しませんでした。"); } catch (FileException e) { assertTrue(FileException.class.isAssignableFrom(e.getClass())); assertEquals("File control operation was failed.", e.getMessage()); assertEquals(newFile, e.getFileName()); PowerMockito.verifyPrivate(FileUtility.class).invoke("checkAbsolutePath", newFile); lock.release(); File mergeFile = new File(newFile); assertTrue(mergeFile.exists()); postReader = new BufferedReader(new InputStreamReader( new FileInputStream(mergeFile))); assertTrue(postReader.ready()); String expectationResultData = "testMergeFile16_new.txtデータ"; String data = ""; for (int i = 0; i < expectationResultData.length(); i++) { assertTrue(i + "回目の判定で失敗しました。", postReader.ready()); data += (char) postReader.read(); } assertEquals(expectationResultData, data); assertFalse(postReader.ready()); postReader.close(); } finally { if (lock != null) { lock.release(); } if (fis != null) { fis.close(); } if (testNewFileFileWriter != null) { testNewFileFileWriter.close(); } if (postReader != null) { postReader.close(); } File file = new File(newFile); file.delete(); } }