@Test public void getActiveSeverities_should_throw_IllegalArgumentException_on_unknown_severity() { Execution execution = new Execution() .withCycleDefinition(new CycleDefinition().withProjectId(PROJECT_ID)) .withRuns(new HashSet<>(Collections.singletonList( run() .withIncludeInThresholds(Boolean.TRUE) .withSeverityTags("any")))); when(severityRepository.findAllByProjectIdOrderByPosition(PROJECT_ID)).thenReturn(Collections.emptyList()); Assertions.assertThrows(IllegalArgumentException.class, () -> cut.getActiveSeverities(execution)); }
SortedSet<Severity> getActiveSeverities(Execution execution) { final List<Severity> allSeverities = severityRepository.findAllByProjectIdOrderByPosition(execution.getCycleDefinition().getProjectId()); SortedSet<Severity> activeSeverities = new TreeSet<>(new Severity.SeverityPositionComparator()); final Set<Run> runsToIncludeInQuality = getRunsToIncludeInQuality(execution); if (runsToIncludeInQuality.isEmpty()) { activeSeverities.addAll(allSeverities); } for (Run run : runsToIncludeInQuality) { if (StringUtils.isEmpty(run.getSeverityTags()) || "all".equals(run.getSeverityTags())) { activeSeverities.addAll(allSeverities); } else { for (final String severityCode : run.getSeverityTags().split(Run.SEVERITY_TAGS_SEPARATOR)) { activeSeverities.add(allSeverities.stream() .filter(s -> severityCode.equals(s.getCode())) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Cannot find severity \"" + severityCode + "\" in " + allSeverities))); } } } return activeSeverities; }
QualityService { SortedSet<Severity> getActiveSeverities(Execution execution) { final List<Severity> allSeverities = severityRepository.findAllByProjectIdOrderByPosition(execution.getCycleDefinition().getProjectId()); SortedSet<Severity> activeSeverities = new TreeSet<>(new Severity.SeverityPositionComparator()); final Set<Run> runsToIncludeInQuality = getRunsToIncludeInQuality(execution); if (runsToIncludeInQuality.isEmpty()) { activeSeverities.addAll(allSeverities); } for (Run run : runsToIncludeInQuality) { if (StringUtils.isEmpty(run.getSeverityTags()) || "all".equals(run.getSeverityTags())) { activeSeverities.addAll(allSeverities); } else { for (final String severityCode : run.getSeverityTags().split(Run.SEVERITY_TAGS_SEPARATOR)) { activeSeverities.add(allSeverities.stream() .filter(s -> severityCode.equals(s.getCode())) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Cannot find severity \"" + severityCode + "\" in " + allSeverities))); } } } return activeSeverities; } }
QualityService { SortedSet<Severity> getActiveSeverities(Execution execution) { final List<Severity> allSeverities = severityRepository.findAllByProjectIdOrderByPosition(execution.getCycleDefinition().getProjectId()); SortedSet<Severity> activeSeverities = new TreeSet<>(new Severity.SeverityPositionComparator()); final Set<Run> runsToIncludeInQuality = getRunsToIncludeInQuality(execution); if (runsToIncludeInQuality.isEmpty()) { activeSeverities.addAll(allSeverities); } for (Run run : runsToIncludeInQuality) { if (StringUtils.isEmpty(run.getSeverityTags()) || "all".equals(run.getSeverityTags())) { activeSeverities.addAll(allSeverities); } else { for (final String severityCode : run.getSeverityTags().split(Run.SEVERITY_TAGS_SEPARATOR)) { activeSeverities.add(allSeverities.stream() .filter(s -> severityCode.equals(s.getCode())) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Cannot find severity \"" + severityCode + "\" in " + allSeverities))); } } } return activeSeverities; }  }
QualityService { SortedSet<Severity> getActiveSeverities(Execution execution) { final List<Severity> allSeverities = severityRepository.findAllByProjectIdOrderByPosition(execution.getCycleDefinition().getProjectId()); SortedSet<Severity> activeSeverities = new TreeSet<>(new Severity.SeverityPositionComparator()); final Set<Run> runsToIncludeInQuality = getRunsToIncludeInQuality(execution); if (runsToIncludeInQuality.isEmpty()) { activeSeverities.addAll(allSeverities); } for (Run run : runsToIncludeInQuality) { if (StringUtils.isEmpty(run.getSeverityTags()) || "all".equals(run.getSeverityTags())) { activeSeverities.addAll(allSeverities); } else { for (final String severityCode : run.getSeverityTags().split(Run.SEVERITY_TAGS_SEPARATOR)) { activeSeverities.add(allSeverities.stream() .filter(s -> severityCode.equals(s.getCode())) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Cannot find severity \"" + severityCode + "\" in " + allSeverities))); } } } return activeSeverities; }  void computeQuality(Execution execution); }
QualityService { SortedSet<Severity> getActiveSeverities(Execution execution) { final List<Severity> allSeverities = severityRepository.findAllByProjectIdOrderByPosition(execution.getCycleDefinition().getProjectId()); SortedSet<Severity> activeSeverities = new TreeSet<>(new Severity.SeverityPositionComparator()); final Set<Run> runsToIncludeInQuality = getRunsToIncludeInQuality(execution); if (runsToIncludeInQuality.isEmpty()) { activeSeverities.addAll(allSeverities); } for (Run run : runsToIncludeInQuality) { if (StringUtils.isEmpty(run.getSeverityTags()) || "all".equals(run.getSeverityTags())) { activeSeverities.addAll(allSeverities); } else { for (final String severityCode : run.getSeverityTags().split(Run.SEVERITY_TAGS_SEPARATOR)) { activeSeverities.add(allSeverities.stream() .filter(s -> severityCode.equals(s.getCode())) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Cannot find severity \"" + severityCode + "\" in " + allSeverities))); } } } return activeSeverities; }  void computeQuality(Execution execution);  }