CulpritFinder { List<BuildProblemData> getRelevantBuildProblems() { SettingNames settingNames = new SettingNames(); if (triggerOnBuildProblem.equals(settingNames.getNoTrigger())) { Loggers.SERVER.debug("[SinCity] build problems do not trigger"); return new ArrayList<BuildProblemData>(); } final List<BuildProblemData> thisBuildProblems = newBuild.getFailureReasons(); Loggers.SERVER.debug("[SinCity] this build's problems: " + thisBuildProblems); if (triggerOnBuildProblem.equals(settingNames.getTriggerOnAll())) { Loggers.SERVER.debug("[SinCity] reporting all build problems"); return thisBuildProblems; } final List<BuildProblemData> previousBuildProblems = oldBuild == null ? new ArrayList<BuildProblemData>() : oldBuild.getFailureReasons(); Loggers.SERVER.debug("[SinCity] previous build's problems: " + previousBuildProblems); final List<BuildProblemDataWithCustomComparator> newProblemsWithCustomComparator = new ArrayList<BuildProblemDataWithCustomComparator>(); for (BuildProblemData thisBuildProblem : thisBuildProblems) newProblemsWithCustomComparator.add(new BuildProblemDataWithCustomComparator(thisBuildProblem)); for (BuildProblemData previousBuildProblem : previousBuildProblems) newProblemsWithCustomComparator.remove(new BuildProblemDataWithCustomComparator(previousBuildProblem)); final List<BuildProblemData> newProblems = new ArrayList<BuildProblemData>(); for (BuildProblemDataWithCustomComparator newProblemWithCustomSeparator : newProblemsWithCustomComparator) newProblems.add(newProblemWithCustomSeparator.getBuildProblemData()); Loggers.SERVER.debug("[SinCity] new build problems: " + newProblems); Loggers.SERVER.debug("[SinCity] reporting new build problems"); return newProblems; } CulpritFinder(@NotNull SBuild newBuild,
                         @Nullable SFinishedBuild oldBuild,
                         @NotNull String triggerOnBuildProblem,
                         @NotNull String triggerOnTestFailure,
                         @NotNull BuildCustomizerFactory buildCustomizerFactory,
                         @NotNull BuildQueue buildQueue,
                         boolean putBuildsToQueueTop,
                         @NotNull String triggeredBy); void triggerCulpritFindingIfNeeded();  }
@Test public void testGetRelevantBuildProblems() { mockery.checking(new Expectations() {{ oneOf(thisBuild).getFailureReasons(); will(returnValue(Arrays.asList( BuildProblemData.createBuildProblem("909103612", ErrorData.ARTIFACT_DEPENDENCY_ERROR_TYPE, "Failed to resolve artifacts from <Sam :: SinCity Build, build #61 [id 21768]>"), BuildProblemData.createBuildProblem("simpleRunner1", BuildProblemTypes.TC_EXIT_CODE_TYPE, "Process exited with code 1"), BuildProblemData.createBuildProblem("bt251", ErrorData.SNAPSHOT_DEPENDENCY_ERROR_BUILD_PROCEEDS_TYPE, "Snapshot dependency \"... Dependency\" failed") ))); oneOf(previousBuild).getFailureReasons(); will(returnValue(Arrays.asList( BuildProblemData.createBuildProblem("simpleRunner1", BuildProblemTypes.TC_EXIT_CODE_TYPE, "Process exited with code 1"), BuildProblemData.createBuildProblem("-639166500", ErrorData.ARTIFACT_DEPENDENCY_ERROR_TYPE, "Failed to resolve artifacts from <Sam :: SinCity Build, build #58 [id 21760]>"), BuildProblemData.createBuildProblem("TC_EXECUTION_TIMEOUT", BuildProblemTypes.TC_EXECUTION_TIMEOUT_TYPE, "Execution timeout") ))); }}); SettingNames settingNames = new SettingNames(); CulpritFinder culpritFinder = new CulpritFinder(thisBuild, previousBuild, settingNames.getTriggerOnNew(), settingNames.getNoTrigger(), buildCustomizerFactory, buildQueue, false, ""); List<BuildProblemData> relevantBuildProblems = culpritFinder.getRelevantBuildProblems(); assertThat(relevantBuildProblems.size(), is(1)); assertThat(relevantBuildProblems.get(0).getIdentity(), is("bt251")); assertThat(relevantBuildProblems.get(0).getType(), is(ErrorData.SNAPSHOT_DEPENDENCY_ERROR_BUILD_PROCEEDS_TYPE)); assertThat(relevantBuildProblems.get(0).getDescription(), is("Snapshot dependency \"... Dependency\" failed")); }