AffectedFilesResolver { public void copyAffectedFilesToBuildFolder(final Report report, final FilePath buildFolder, final FilePath affectedFilesFolder) throws InterruptedException { copyAffectedFilesToBuildFolder(report, new RemoteFacade(buildFolder, affectedFilesFolder)); }  static boolean hasAffectedFile(final Run<?, ?> run, final Issue issue); static Path getFile(final Run<?, ?> run, final String fileName); void copyAffectedFilesToBuildFolder(final Report report, final FilePath buildFolder,
            final FilePath affectedFilesFolder); static final String AFFECTED_FILES_FOLDER_NAME; }
@Test void shouldDoNothingForEmptyReport() throws InterruptedException { AffectedFilesResolver resolver = new AffectedFilesResolver(); Report report = new Report(); resolver.copyAffectedFilesToBuildFolder(report, mock(RemoteFacade.class)); assertThat(report.getErrorMessages()).isEmpty(); assertThat(report.getInfoMessages()).hasSize(1); String message = report.getInfoMessages().get(0); assertThat(message).contains("0 copied"); assertThat(message).contains("0 not in workspace"); assertThat(message).contains("0 not-found"); assertThat(message).contains("0 with I/O error"); }
@Test void shouldCopyFile() throws InterruptedException { AffectedFilesResolver resolver = new AffectedFilesResolver(); Report report = new Report(); Issue issue = new IssueBuilder().setFileName(FILE_NAME).build(); report.add(issue); RemoteFacade remoteFacade = mock(RemoteFacade.class); when(remoteFacade.exists(FILE_NAME)).thenReturn(true); when(remoteFacade.isInWorkspace(FILE_NAME)).thenReturn(true); resolver.copyAffectedFilesToBuildFolder(report, remoteFacade); assertThat(report.getErrorMessages()).isEmpty(); assertThat(report.getInfoMessages()).hasSize(1); String message = report.getInfoMessages().get(0); assertThat(message).contains("1 copied"); assertThat(message).contains("0 not in workspace"); assertThat(message).contains("0 not-found"); assertThat(message).contains("0 with I/O error"); }
@Test void shouldReportCopyExceptions() throws InterruptedException, IOException { AffectedFilesResolver resolver = new AffectedFilesResolver(); Report report = new Report(); Issue issue = new IssueBuilder().setFileName(FILE_NAME).build(); report.add(issue); RemoteFacade remoteFacade = mock(RemoteFacade.class); when(remoteFacade.exists(FILE_NAME)).thenReturn(true); when(remoteFacade.isInWorkspace(FILE_NAME)).thenReturn(true); doThrow(IOException.class).when(remoteFacade).copy(FILE_NAME, FILE_NAME); resolver.copyAffectedFilesToBuildFolder(report, remoteFacade); assertThat(report.getErrorMessages()) .hasSize(2) .contains("Can't copy some affected workspace files to Jenkins build folder:", "- 'file.txt', IO exception has been thrown: java.io.IOException"); assertThat(report.getInfoMessages()).hasSize(1); String message = report.getInfoMessages().get(0); assertThat(message).contains("0 copied"); assertThat(message).contains("0 not in workspace"); assertThat(message).contains("0 not-found"); assertThat(message).contains("1 with I/O error"); }
@Test void shouldSkipNonWorkspaceFile() throws InterruptedException { AffectedFilesResolver resolver = new AffectedFilesResolver(); Report report = new Report(); Issue issue = new IssueBuilder().setFileName(FILE_NAME).build(); report.add(issue); RemoteFacade remoteFacade = mock(RemoteFacade.class); when(remoteFacade.exists(FILE_NAME)).thenReturn(true); when(remoteFacade.isInWorkspace(FILE_NAME)).thenReturn(false); resolver.copyAffectedFilesToBuildFolder(report, remoteFacade); assertThat(report.getErrorMessages()).isEmpty(); assertThat(report.getInfoMessages()).hasSize(1); String message = report.getInfoMessages().get(0); assertThat(message).contains("0 copied"); assertThat(message).contains("1 not in workspace"); assertThat(message).contains("0 not-found"); assertThat(message).contains("0 with I/O error"); }