@Test public void correctFilesAreAddedToProject() { when(io.directoryExists()).thenReturn(true); when(io.getPath()).thenReturn("path_1"); List<FileIO> list = new ArrayList<FileIO>(); FileIO childIO = mock(FileIO.class); list.add(childIO); when(io.getChildren()).thenReturn(list); when(childIO.getPath()).thenReturn("path_2"); when(childIO.getChildren()).thenReturn(new ArrayList<FileIO>()); when(childIO.fileExists()).thenReturn(true); when(io.getChildren()).thenReturn(list); Project project = mock(Project.class); doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { List<String> paths = (List<String>) invocation.getArguments()[0]; assertEquals(2, paths.size()); assertTrue(paths.contains("path_1")); assertTrue(paths.contains("path_2")); return null; } }).when(project).setProjectFiles(anyListOf(String.class)); scanner.updateProject(project); verify(project, times(1)).setProjectFiles(anyListOf(String.class)); }
public void updateProject(Project project) { if (project.getStatus() == ProjectStatus.DELETED) { return; } List<String> files = new ArrayList<String>(); traverse(files, io.newFile(project.getRootPath())); project.setProjectFiles(files); if (project.existsOnDisk()) { project.setStatus(ProjectStatus.DOWNLOADED); } else { project.setStatus(ProjectStatus.NOT_DOWNLOADED); } }
ProjectScanner { public void updateProject(Project project) { if (project.getStatus() == ProjectStatus.DELETED) { return; } List<String> files = new ArrayList<String>(); traverse(files, io.newFile(project.getRootPath())); project.setProjectFiles(files); if (project.existsOnDisk()) { project.setStatus(ProjectStatus.DOWNLOADED); } else { project.setStatus(ProjectStatus.NOT_DOWNLOADED); } } }
ProjectScanner { public void updateProject(Project project) { if (project.getStatus() == ProjectStatus.DELETED) { return; } List<String> files = new ArrayList<String>(); traverse(files, io.newFile(project.getRootPath())); project.setProjectFiles(files); if (project.existsOnDisk()) { project.setStatus(ProjectStatus.DOWNLOADED); } else { project.setStatus(ProjectStatus.NOT_DOWNLOADED); } } ProjectScanner(ProjectDAO projectDAO, IOFactory io); }
ProjectScanner { public void updateProject(Project project) { if (project.getStatus() == ProjectStatus.DELETED) { return; } List<String> files = new ArrayList<String>(); traverse(files, io.newFile(project.getRootPath())); project.setProjectFiles(files); if (project.existsOnDisk()) { project.setStatus(ProjectStatus.DOWNLOADED); } else { project.setStatus(ProjectStatus.NOT_DOWNLOADED); } } ProjectScanner(ProjectDAO projectDAO, IOFactory io); void updateProject(Project project); void updateProjects(); }
ProjectScanner { public void updateProject(Project project) { if (project.getStatus() == ProjectStatus.DELETED) { return; } List<String> files = new ArrayList<String>(); traverse(files, io.newFile(project.getRootPath())); project.setProjectFiles(files); if (project.existsOnDisk()) { project.setStatus(ProjectStatus.DOWNLOADED); } else { project.setStatus(ProjectStatus.NOT_DOWNLOADED); } } ProjectScanner(ProjectDAO projectDAO, IOFactory io); void updateProject(Project project); void updateProjects();  }