FileControlImpl implements FileControl { @Override public void mergeFile(List<String> fileList, String newFile) { List<String> srcFileList = new ArrayList<String>(); for (String fileName : fileList) { srcFileList.add(getAbsolutePath(fileName)); } FileUtility.mergeFile(srcFileList, getAbsolutePath(newFile)); }  @Override void copyFile(String srcFile, String newFile); @Override void deleteFile(String srcFile); @Override void mergeFile(List<String> fileList, String newFile); @Override void renameFile(String srcFile, String newFile); String getBasePath(); void setBasePath(String basePath); void setCheckFileExist(boolean checkFileExist);  }
@SuppressWarnings("unchecked") @Test public void testMergeFile01() throws Exception { FileControlImpl fileControl = PowerMockito.spy(new FileControlImpl()); 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 newFile = directoryPath + "testMergeFile01_new.txt"; File file = new File(newFile); file.delete(); file.createNewFile(); String basePath = ""; ReflectionTestUtils.setField(fileControl, "basePath", basePath); PowerMockito.mockStatic(FileUtility.class); ArgumentCaptor<String> fileUtilityStringArgumentCaptor = ArgumentCaptor .forClass(String.class); @SuppressWarnings("rawtypes") ArgumentCaptor<List> fileUtilityListArgumentCaptor = ArgumentCaptor .forClass(List.class); PowerMockito.doNothing().when(FileUtility.class, "mergeFile", fileUtilityListArgumentCaptor.capture(), fileUtilityStringArgumentCaptor.capture()); Method getAbsolutePathMethod = PowerMockito.method( FileControlImpl.class, "getAbsolutePath", String.class); ArgumentCaptor<String> fileControlStringArgumentCaptor = ArgumentCaptor .forClass(String.class); PowerMockito.doCallRealMethod().when(fileControl, getAbsolutePathMethod) .withArguments(fileControlStringArgumentCaptor.capture()); try { fileControl.mergeFile(fileList, newFile); PowerMockito.verifyPrivate(fileControl).invoke( getAbsolutePathMethod).withArguments(Mockito.anyString()); String argGetAbsolutePath = fileControlStringArgumentCaptor .getValue(); assertEquals(newFile, argGetAbsolutePath); PowerMockito.verifyStatic(); FileUtility.mergeFile(Mockito.anyList(), Mockito.anyString()); @SuppressWarnings("rawtypes") List argListMergeFile = fileUtilityListArgumentCaptor.getValue(); assertEquals(fileList, argListMergeFile); String argStringMergeFile = fileUtilityStringArgumentCaptor .getValue(); assertEquals(newFile, argStringMergeFile); } finally { file = new File(newFile); file.delete(); } }
@SuppressWarnings("unchecked") @Test public void testMergeFile02() throws Exception { FileControlImpl fileControl = PowerMockito.spy(new FileControlImpl()); 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 + "testMergeFile02-01_src.txt"; fileList.add(srcFile1); String newFile = directoryPath + "testMergeFile02_new.txt"; File file = new File(srcFile1); file.delete(); file.createNewFile(); file = new File(newFile); file.delete(); file.createNewFile(); String basePath = ""; ReflectionTestUtils.setField(fileControl, "basePath", basePath); PowerMockito.mockStatic(FileUtility.class); ArgumentCaptor<String> fileUtilityStringArgumentCaptor = ArgumentCaptor .forClass(String.class); @SuppressWarnings("rawtypes") ArgumentCaptor<List> fileUtilityListArgumentCaptor = ArgumentCaptor .forClass(List.class); PowerMockito.doNothing().when(FileUtility.class, "mergeFile", fileUtilityListArgumentCaptor.capture(), fileUtilityStringArgumentCaptor.capture()); Method getAbsolutePathMethod = PowerMockito.method( FileControlImpl.class, "getAbsolutePath", String.class); ArgumentCaptor<String> fileControlStringArgumentCaptor = ArgumentCaptor .forClass(String.class); PowerMockito.doCallRealMethod().when(fileControl, getAbsolutePathMethod) .withArguments(fileControlStringArgumentCaptor.capture()); try { fileControl.mergeFile(fileList, newFile); PowerMockito.verifyPrivate(fileControl, Mockito.times(2)).invoke( getAbsolutePathMethod).withArguments(Mockito.anyString()); List<String> argGetAbsolutePathList = fileControlStringArgumentCaptor .getAllValues(); assertEquals(srcFile1, argGetAbsolutePathList.get(0)); assertEquals(newFile, argGetAbsolutePathList.get(1)); PowerMockito.verifyStatic(); FileUtility.mergeFile(Mockito.anyList(), Mockito.anyString()); @SuppressWarnings("rawtypes") List argListMergeFile = fileUtilityListArgumentCaptor.getValue(); assertEquals(fileList, argListMergeFile); String argStringMergeFile = fileUtilityStringArgumentCaptor .getValue(); assertEquals(newFile, argStringMergeFile); } finally { file = new File(srcFile1); file.delete(); file = new File(newFile); file.delete(); } }
@SuppressWarnings("unchecked") @Test public void testMergeFile03() throws Exception { FileControlImpl fileControl = PowerMockito.spy(new FileControlImpl()); 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 = "testMergeFile03-01_src.txt"; fileList.add(srcFile1); String srcFile2 = "testMergeFile03-02_src.txt"; fileList.add(srcFile2); String srcFile3 = "testMergeFile03-03_src.txt"; fileList.add(srcFile3); String newFile = "testMergeFile03_new.txt"; File file = new File(directoryPath + srcFile1); file.delete(); file.createNewFile(); file = new File(directoryPath + srcFile2); file.delete(); file.createNewFile(); file = new File(directoryPath + srcFile3); file.delete(); file.createNewFile(); file = new File(newFile); file.delete(); file.createNewFile(); String basePath = directoryPath; ReflectionTestUtils.setField(fileControl, "basePath", basePath); PowerMockito.mockStatic(FileUtility.class); ArgumentCaptor<String> fileUtilityStringArgumentCaptor = ArgumentCaptor .forClass(String.class); @SuppressWarnings("rawtypes") ArgumentCaptor<List> fileUtilityListArgumentCaptor = ArgumentCaptor .forClass(List.class); PowerMockito.doNothing().when(FileUtility.class, "mergeFile", fileUtilityListArgumentCaptor.capture(), fileUtilityStringArgumentCaptor.capture()); Method getAbsolutePathMethod = PowerMockito.method( FileControlImpl.class, "getAbsolutePath", String.class); ArgumentCaptor<String> fileControlStringArgumentCaptor = ArgumentCaptor .forClass(String.class); PowerMockito.doCallRealMethod().when(fileControl, getAbsolutePathMethod) .withArguments(fileControlStringArgumentCaptor.capture()); try { fileControl.mergeFile(fileList, newFile); PowerMockito.verifyPrivate(fileControl, Mockito.times(4)).invoke( getAbsolutePathMethod).withArguments(Mockito.anyString()); List<String> argGetAbsolutePathList = fileControlStringArgumentCaptor .getAllValues(); assertEquals(srcFile1, argGetAbsolutePathList.get(0)); assertEquals(srcFile2, argGetAbsolutePathList.get(1)); assertEquals(srcFile3, argGetAbsolutePathList.get(2)); assertEquals(newFile, argGetAbsolutePathList.get(3)); PowerMockito.verifyStatic(); FileUtility.mergeFile(Mockito.anyList(), Mockito.anyString()); @SuppressWarnings("rawtypes") List argListMergeFile = fileUtilityListArgumentCaptor.getValue(); assertEquals(basePath + srcFile1, argListMergeFile.get(0)); assertEquals(basePath + srcFile2, argListMergeFile.get(1)); assertEquals(basePath + srcFile3, argListMergeFile.get(2)); String argStringMergeFile = fileUtilityStringArgumentCaptor .getValue(); assertEquals(basePath + newFile, argStringMergeFile); } finally { file = new File(directoryPath + srcFile1); file.delete(); file = new File(directoryPath + srcFile2); file.delete(); file = new File(directoryPath + srcFile3); file.delete(); file = new File(newFile); file.delete(); } }
@SuppressWarnings("unchecked") @Test public void testMergeFile04() throws Exception { FileControlImpl fileControl = PowerMockito.spy(new FileControlImpl()); 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-01_src.txt"; fileList.add(srcFile1); String srcFile2 = directoryPath + "testMergeFile04-02_src.txt"; fileList.add(srcFile2); String srcFile3 = directoryPath + "testMergeFile04-03_src.txt"; fileList.add(srcFile3); String newFile = directoryPath + "testMergeFile04_new.txt"; File file = new File(srcFile1); file.delete(); file.createNewFile(); file = new File(srcFile2); file.delete(); file.createNewFile(); file = new File(srcFile3); file.delete(); file.createNewFile(); file = new File(newFile); file.delete(); file.createNewFile(); String basePath = directoryPath; ReflectionTestUtils.setField(fileControl, "basePath", basePath); PowerMockito.mockStatic(FileUtility.class); @SuppressWarnings("rawtypes") ArgumentCaptor<List> fileUtilityListArgumentCaptor = ArgumentCaptor .forClass(List.class); ArgumentCaptor<String> fileUtlityStringArgumentCaptor = ArgumentCaptor .forClass(String.class); PowerMockito.doNothing().when(FileUtility.class, "mergeFile", fileUtilityListArgumentCaptor.capture(), fileUtlityStringArgumentCaptor.capture()); Method getAbsolutePathMethod = PowerMockito.method( FileControlImpl.class, "getAbsolutePath", String.class); ArgumentCaptor<String> fileControlStringArgumentCaptor = ArgumentCaptor .forClass(String.class); PowerMockito.doCallRealMethod().when(fileControl, getAbsolutePathMethod) .withArguments(fileControlStringArgumentCaptor.capture()); try { fileControl.mergeFile(fileList, newFile); PowerMockito.verifyPrivate(fileControl, Mockito.times(4)).invoke( getAbsolutePathMethod).withArguments( fileControlStringArgumentCaptor.capture()); List<String> argGetAbsolutePathList = fileControlStringArgumentCaptor .getAllValues(); assertEquals(fileList.get(0), argGetAbsolutePathList.get(0)); assertEquals(fileList.get(1), argGetAbsolutePathList.get(1)); assertEquals(fileList.get(2), argGetAbsolutePathList.get(2)); assertEquals(newFile, argGetAbsolutePathList.get(3)); PowerMockito.verifyStatic(); FileUtility.mergeFile(Mockito.anyList(), Mockito.anyString()); @SuppressWarnings("rawtypes") List argListMergeFile = fileUtilityListArgumentCaptor.getValue(); assertEquals(fileList.get(0), argListMergeFile.get(0)); assertEquals(fileList.get(1), argListMergeFile.get(1)); assertEquals(fileList.get(2), argListMergeFile.get(2)); String argStringMergeFile = fileUtlityStringArgumentCaptor .getValue(); assertEquals(newFile, argStringMergeFile); } finally { file = new File(srcFile1); file.delete(); file = new File(srcFile2); file.delete(); file = new File(srcFile3); file.delete(); file = new File(newFile); file.delete(); } }
@SuppressWarnings("unchecked") @Test public void testMergeFile05() throws Exception { FileControlImpl fileControl = PowerMockito.spy(new FileControlImpl()); 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 = "testMergeFile05-01_src.txt"; fileList.add(srcFile1); String srcFile2 = "testMergeFile05-02_src.txt"; fileList.add(srcFile2); String srcFile3 = "testMergeFile05-03_src.txt"; fileList.add(srcFile3); String newFile = "testMergeFile05_new.txt"; File file = new File(directoryPath + srcFile1); file.delete(); file.createNewFile(); file = new File(directoryPath + srcFile2); file.delete(); file.createNewFile(); file = new File(directoryPath + srcFile3); file.delete(); file.createNewFile(); file = new File(directoryPath + newFile); file.delete(); file.createNewFile(); String basePath = ""; ReflectionTestUtils.setField(fileControl, "basePath", basePath); PowerMockito.mockStatic(FileUtility.class); ArgumentCaptor<String> fileUtilityStringArgumentCaptor = ArgumentCaptor .forClass(String.class); @SuppressWarnings("rawtypes") ArgumentCaptor<List> fileUtilityListArgumentCaptor = ArgumentCaptor .forClass(List.class); PowerMockito.doNothing().when(FileUtility.class, "mergeFile", fileUtilityListArgumentCaptor.capture(), fileUtilityStringArgumentCaptor.capture()); Method getAbsolutePathMethod = PowerMockito.method( FileControlImpl.class, "getAbsolutePath", String.class); ArgumentCaptor<String> fileControlStringArgumentCaptor = ArgumentCaptor .forClass(String.class); PowerMockito.doCallRealMethod().when(fileControl, getAbsolutePathMethod) .withArguments(fileControlStringArgumentCaptor.capture()); try { fileControl.mergeFile(fileList, newFile); PowerMockito.verifyPrivate(fileControl, Mockito.times(4)).invoke( getAbsolutePathMethod).withArguments(Mockito.anyString()); List<String> argGetAbsolutePathList = fileControlStringArgumentCaptor .getAllValues(); assertEquals(fileList.get(0), argGetAbsolutePathList.get(0)); assertEquals(fileList.get(1), argGetAbsolutePathList.get(1)); assertEquals(fileList.get(2), argGetAbsolutePathList.get(2)); assertEquals(newFile, argGetAbsolutePathList.get(3)); PowerMockito.verifyStatic(); FileUtility.mergeFile(Mockito.anyList(), Mockito.anyString()); @SuppressWarnings("rawtypes") List argListMergeFile = fileUtilityListArgumentCaptor.getValue(); assertEquals(srcFile1, argListMergeFile.get(0)); assertEquals(srcFile2, argListMergeFile.get(1)); assertEquals(srcFile3, argListMergeFile.get(2)); String argStringMergeFile = fileUtilityStringArgumentCaptor .getValue(); assertEquals(newFile, argStringMergeFile); } finally { file = new File(directoryPath + srcFile1); file.delete(); file = new File(directoryPath + srcFile2); file.delete(); file = new File(directoryPath + srcFile3); file.delete(); file = new File(directoryPath + newFile); file.delete(); } }
@Test public void testMergeFile06() throws Exception { FileControlImpl fileControl = PowerMockito.spy(new FileControlImpl()); 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 = null; String newFile = directoryPath + "testMergeFile06_new.txt"; File file = new File(newFile); file.delete(); file.createNewFile(); String basePath = ""; ReflectionTestUtils.setField(fileControl, "basePath", basePath); try { fileControl.mergeFile(fileList, newFile); fail("NullPointerExceptionが発生しませんでした。失敗です。"); } catch (Exception e) { assertEquals(NullPointerException.class, e.getClass()); } finally { file = new File(newFile); file.delete(); } }
@Test public void testMergeFile07() throws Exception { FileControlImpl fileControl = PowerMockito.spy(new FileControlImpl()); 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-01_src.txt"; fileList.add(srcFile1); String newFile = null; File file = new File(srcFile1); file.delete(); file.createNewFile(); String basePath = ""; ReflectionTestUtils.setField(fileControl, "basePath", basePath); Method getAbsolutePathMethod = PowerMockito.method( FileControlImpl.class, "getAbsolutePath", String.class); ArgumentCaptor<String> fileControlStringArgumentCaptor = ArgumentCaptor .forClass(String.class); PowerMockito.doCallRealMethod().when(fileControl, getAbsolutePathMethod) .withArguments(fileControlStringArgumentCaptor.capture()); try { fileControl.mergeFile(fileList, newFile); fail("FileExceptionが発生しませんでした。失敗です。"); } catch (FileException e) { PowerMockito.verifyPrivate(fileControl, Mockito.times(2)).invoke( getAbsolutePathMethod).withArguments(Mockito.anyString()); List<String> argGetAbsolutePathList = fileControlStringArgumentCaptor .getAllValues(); assertEquals(srcFile1, argGetAbsolutePathList.get(0)); assertEquals(newFile, argGetAbsolutePathList.get(1)); assertEquals(FileException.class, e.getClass()); assertEquals("File name is not set.", e.getMessage()); assertNull(e.getFileName()); } finally { file = new File(srcFile1); file.delete(); } }
@Test public void testMergeFile08() throws Exception { FileControlImpl fileControl = PowerMockito.spy(new FileControlImpl()); 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-01_src.txt"; fileList.add(srcFile1); String srcFile2 = null; fileList.add(srcFile2); String srcFile3 = directoryPath + "testMergeFile08-03_src.txt"; fileList.add(srcFile3); String newFile = directoryPath + "testMergeFile08_new.txt"; File file = new File(srcFile1); file.delete(); file.createNewFile(); file = new File(srcFile3); file.delete(); file.createNewFile(); file = new File(newFile); file.delete(); file.createNewFile(); String basePath = ""; ReflectionTestUtils.setField(fileControl, "basePath", basePath); Method getAbsolutePathMethod = PowerMockito.method( FileControlImpl.class, "getAbsolutePath", String.class); ArgumentCaptor<String> fileControlStringArgumentCaptor = ArgumentCaptor .forClass(String.class); PowerMockito.doCallRealMethod().when(fileControl, getAbsolutePathMethod) .withArguments(fileControlStringArgumentCaptor.capture()); try { fileControl.mergeFile(fileList, newFile); fail("FileExceptionが発生しませんでした。失敗です。"); } catch (FileException e) { PowerMockito.verifyPrivate(fileControl, Mockito.times(2)).invoke( getAbsolutePathMethod).withArguments(Mockito.anyString()); List<String> argGetAbsolutePathList = fileControlStringArgumentCaptor .getAllValues(); assertEquals(srcFile1, argGetAbsolutePathList.get(0)); assertEquals(srcFile2, argGetAbsolutePathList.get(1)); assertEquals(FileException.class, e.getClass()); assertEquals("File name is not set.", e.getMessage()); assertNull(e.getFileName()); } finally { file = new File(srcFile1); file.delete(); file = new File(srcFile3); file.delete(); file = new File(newFile); file.delete(); } }
@SuppressWarnings("unchecked") @Test public void testMergeFile09() throws Exception { FileControlImpl fileControl = PowerMockito.spy(new FileControlImpl()); 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 = "testMergeFile09-01_src.txt"; fileList.add(srcFile1); String srcFile2 = "testMergeFile09-02_src.txt"; fileList.add(srcFile2); String srcFile3 = "testMergeFile09-03_src.txt"; fileList.add(srcFile3); String newFile = directoryPath + "testMergeFile09_new.txt"; File file = new File(directoryPath + srcFile1); file.delete(); file.createNewFile(); file = new File(directoryPath + srcFile2); file.delete(); file.createNewFile(); file = new File(directoryPath + srcFile3); file.delete(); file.createNewFile(); file = new File(newFile); file.delete(); file.createNewFile(); String basePath = directoryPath; ReflectionTestUtils.setField(fileControl, "basePath", basePath); PowerMockito.mockStatic(FileUtility.class); ArgumentCaptor<String> fileUtilityStringArgumentCaptor = ArgumentCaptor .forClass(String.class); @SuppressWarnings("rawtypes") ArgumentCaptor<List> fileUtilityListArgumentCaptor = ArgumentCaptor .forClass(List.class); PowerMockito.doNothing().when(FileUtility.class, "mergeFile", fileUtilityListArgumentCaptor.capture(), fileUtilityStringArgumentCaptor.capture()); Method getAbsolutePathMethod = PowerMockito.method( FileControlImpl.class, "getAbsolutePath", String.class); ArgumentCaptor<String> fileControlStringArgumentCaptor = ArgumentCaptor .forClass(String.class); PowerMockito.doCallRealMethod().when(fileControl, getAbsolutePathMethod) .withArguments(fileControlStringArgumentCaptor.capture()); try { fileControl.mergeFile(fileList, newFile); PowerMockito.verifyPrivate(fileControl, Mockito.times(4)).invoke( getAbsolutePathMethod).withArguments(Mockito.anyString()); List<String> argGetAbsolutePathList = fileControlStringArgumentCaptor .getAllValues(); assertEquals(fileList.get(0), argGetAbsolutePathList.get(0)); assertEquals(fileList.get(1), argGetAbsolutePathList.get(1)); assertEquals(fileList.get(2), argGetAbsolutePathList.get(2)); assertEquals(newFile, argGetAbsolutePathList.get(3)); PowerMockito.verifyStatic(); FileUtility.mergeFile(Mockito.anyList(), Mockito.anyString()); @SuppressWarnings("rawtypes") List argListMergeFile = fileUtilityListArgumentCaptor.getValue(); assertEquals(basePath + srcFile1, argListMergeFile.get(0)); assertEquals(basePath + srcFile2, argListMergeFile.get(1)); assertEquals(basePath + srcFile3, argListMergeFile.get(2)); String argStringMergeFile = fileUtilityStringArgumentCaptor .getValue(); assertEquals(newFile, argStringMergeFile); } finally { file = new File(directoryPath + srcFile1); file.delete(); file = new File(directoryPath + srcFile2); file.delete(); file = new File(directoryPath + srcFile3); file.delete(); file = new File(newFile); file.delete(); } }
@SuppressWarnings("unchecked") @Test public void testMergeFile10() throws Exception { FileControlImpl fileControl = PowerMockito.spy(new FileControlImpl()); 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-01_src.txt"; fileList.add(srcFile1); String srcFile2 = "testMergeFile10-02_src.txt"; fileList.add(srcFile2); String srcFile3 = directoryPath + "testMergeFile10-03_src.txt"; fileList.add(srcFile3); String newFile = directoryPath + "testMergeFile10_new.txt"; File file = new File(srcFile1); file.delete(); file.createNewFile(); file = new File(directoryPath + srcFile2); file.delete(); file.createNewFile(); file = new File(srcFile3); file.delete(); file.createNewFile(); file = new File(newFile); file.delete(); file.createNewFile(); String basePath = directoryPath; ReflectionTestUtils.setField(fileControl, "basePath", basePath); PowerMockito.mockStatic(FileUtility.class); ArgumentCaptor<String> fileUtilityStringArgumentCaptor = ArgumentCaptor .forClass(String.class); @SuppressWarnings("rawtypes") ArgumentCaptor<List> fileUtilityListArgumentCaptor = ArgumentCaptor .forClass(List.class); PowerMockito.doNothing().when(FileUtility.class, "mergeFile", fileUtilityListArgumentCaptor.capture(), fileUtilityStringArgumentCaptor.capture()); Method getAbsolutePathMethod = PowerMockito.method( FileControlImpl.class, "getAbsolutePath", String.class); ArgumentCaptor<String> fileControlStringArgumentCaptor = ArgumentCaptor .forClass(String.class); PowerMockito.doCallRealMethod().when(fileControl, getAbsolutePathMethod) .withArguments(fileControlStringArgumentCaptor.capture()); try { fileControl.mergeFile(fileList, newFile); PowerMockito.verifyPrivate(fileControl, Mockito.times(4)).invoke( getAbsolutePathMethod).withArguments(Mockito.anyString()); List<String> argGetAbsolutePathList = fileControlStringArgumentCaptor .getAllValues(); assertEquals(fileList.get(0), argGetAbsolutePathList.get(0)); assertEquals(fileList.get(1), argGetAbsolutePathList.get(1)); assertEquals(fileList.get(2), argGetAbsolutePathList.get(2)); assertEquals(newFile, argGetAbsolutePathList.get(3)); PowerMockito.verifyStatic(); FileUtility.mergeFile(Mockito.anyList(), Mockito.anyString()); @SuppressWarnings("rawtypes") List argListMergeFile = fileUtilityListArgumentCaptor.getValue(); assertEquals(srcFile1, argListMergeFile.get(0)); assertEquals(basePath + srcFile2, argListMergeFile.get(1)); assertEquals(srcFile3, argListMergeFile.get(2)); String argStringMergeFile = fileUtilityStringArgumentCaptor .getValue(); assertEquals(newFile, argStringMergeFile); } finally { file = new File(srcFile1); file.delete(); file = new File(directoryPath + srcFile2); file.delete(); file = new File(srcFile3); file.delete(); file = new File(newFile); file.delete(); } }
@SuppressWarnings("unchecked") @Test public void testMergeFile11() throws Exception { FileControlImpl fileControl = PowerMockito.spy(new FileControlImpl()); 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 + "testMergeFile11-01_src.txt"; fileList.add(srcFile1); String srcFile2 = directoryPath + "testMergeFile11-02_src.txt"; fileList.add(srcFile2); String srcFile3 = directoryPath + "testMergeFile11-03_src.txt"; fileList.add(srcFile3); String newFile = "testMergeFile11_new.txt"; File file = new File(srcFile1); file.delete(); file.createNewFile(); file = new File(srcFile2); file.delete(); file.createNewFile(); file = new File(srcFile3); file.delete(); file.createNewFile(); file = new File(directoryPath + newFile); file.delete(); file.createNewFile(); String basePath = directoryPath; ReflectionTestUtils.setField(fileControl, "basePath", basePath); PowerMockito.mockStatic(FileUtility.class); ArgumentCaptor<String> fileUtilityStringArgumentCaptor = ArgumentCaptor .forClass(String.class); @SuppressWarnings("rawtypes") ArgumentCaptor<List> fileUtilityListArgumentCaptor = ArgumentCaptor .forClass(List.class); PowerMockito.doNothing().when(FileUtility.class, "mergeFile", fileUtilityListArgumentCaptor.capture(), fileUtilityStringArgumentCaptor.capture()); Method getAbsolutePathMethod = PowerMockito.method( FileControlImpl.class, "getAbsolutePath", String.class); ArgumentCaptor<String> fileControlStringArgumentCaptor = ArgumentCaptor .forClass(String.class); PowerMockito.doCallRealMethod().when(fileControl, getAbsolutePathMethod) .withArguments(fileControlStringArgumentCaptor.capture()); try { fileControl.mergeFile(fileList, newFile); PowerMockito.verifyPrivate(fileControl, Mockito.times(4)).invoke( getAbsolutePathMethod).withArguments(Mockito.anyString()); List<String> argGetAbsolutePathList = fileControlStringArgumentCaptor .getAllValues(); assertEquals(fileList.get(0), argGetAbsolutePathList.get(0)); assertEquals(fileList.get(1), argGetAbsolutePathList.get(1)); assertEquals(fileList.get(2), argGetAbsolutePathList.get(2)); assertEquals(newFile, argGetAbsolutePathList.get(3)); PowerMockito.verifyStatic(); FileUtility.mergeFile(Mockito.anyList(), Mockito.anyString()); @SuppressWarnings("rawtypes") List argListMergeFile = fileUtilityListArgumentCaptor.getValue(); assertEquals(srcFile1, argListMergeFile.get(0)); assertEquals(srcFile2, argListMergeFile.get(1)); assertEquals(srcFile3, argListMergeFile.get(2)); String argStringMergeFile = fileUtilityStringArgumentCaptor .getValue(); assertEquals(basePath + newFile, argStringMergeFile); } finally { 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(); } }