@Test public void testGetHighestReportSeverity() { ReportCollector collector1 = new ReportCollector(); collector1.reportViolation(new SimpleViolation(Severity.MINOR, "")); collector1.reportViolation(new SimpleViolation(Severity.MAJOR, "")); CheckReport hasMajor = new SimpleReport("hasMajor", collector1.getReportedViolations()); ReportCollector collector2 = new ReportCollector(); collector2.reportViolation(new SimpleViolation(Severity.MINOR, "")); collector2.reportViolation(new SimpleViolation(Severity.SEVERE, "")); CheckReport hasSevere = new SimpleReport("hasSevere", collector2.getReportedViolations()); ReportCollector collector3 = new ReportCollector(); collector3.reportViolation(new SimpleViolation(Severity.MINOR, "")); CheckReport hasMinor = new SimpleReport("hasMinor", collector3.getReportedViolations()); final Console console = getMockConsole(); Options optsFailDefault = new Options.Builder() .build(console).getOrDefault(null); Options optsFailMinor = new Options.Builder() .setFailOnSeverity(Severity.MINOR) .build(console).getOrDefault(null); Options optsFailMajor = new Options.Builder() .setFailOnSeverity(Severity.MAJOR) .build(console).getOrDefault(null); Options optsFailSevere = new Options.Builder() .setFailOnSeverity(Severity.SEVERE) .build(console).getOrDefault(null); final Command command = new Command(); assertFalse("no exit minor default fail", command.getHighestReportSeverity(optsFailDefault, Collections.singletonList(hasMinor)).isPresent()); assertEquals("major exit default fail", Command.EXIT_MAJOR_VIOLATION, command.getHighestReportSeverity(optsFailDefault, Collections.singletonList(hasMajor)).get()); assertEquals("severe exit default fail", Command.EXIT_SEVERE_VIOLATION, command.getHighestReportSeverity(optsFailDefault, Collections.singletonList(hasSevere)).get()); assertEquals("minor exit minor fail", Command.EXIT_MINOR_VIOLATION, command.getHighestReportSeverity(optsFailMinor, Collections.singletonList(hasMinor)).get()); assertEquals("major exit minor fail", Command.EXIT_MAJOR_VIOLATION, command.getHighestReportSeverity(optsFailMinor, Collections.singletonList(hasMajor)).get()); assertEquals("severe exit minor fail", Command.EXIT_SEVERE_VIOLATION, command.getHighestReportSeverity(optsFailMinor, Collections.singletonList(hasSevere)).get()); assertFalse("no exit minor major fail", command.getHighestReportSeverity(optsFailMajor, Collections.singletonList(hasMinor)).isPresent()); assertEquals("major exit major fail", Command.EXIT_MAJOR_VIOLATION, command.getHighestReportSeverity(optsFailMajor, Collections.singletonList(hasMajor)).get()); assertEquals("severe exit major fail", Command.EXIT_SEVERE_VIOLATION, command.getHighestReportSeverity(optsFailMajor, Collections.singletonList(hasSevere)).get()); assertFalse("no exit minor severe fail", command.getHighestReportSeverity(optsFailSevere, Collections.singletonList(hasMinor)).isPresent()); assertFalse("no exit major severe fail", command.getHighestReportSeverity(optsFailSevere, Collections.singletonList(hasMajor)).isPresent()); assertEquals("severe exit major fail", Command.EXIT_SEVERE_VIOLATION, command.getHighestReportSeverity(optsFailSevere, Collections.singletonList(hasSevere)).get()); assertFalse("no exit minor default fail", command.getHighestReportSeverity(optsFailDefault, Arrays.asList(hasMinor, hasMinor)).isPresent()); assertEquals("minor exit", Command.EXIT_MAJOR_VIOLATION, command.getHighestReportSeverity(optsFailDefault, Arrays.asList(hasMinor, hasMajor)).get()); assertEquals("major exit", Command.EXIT_MAJOR_VIOLATION, command.getHighestReportSeverity(optsFailDefault, Arrays.asList(hasMajor, hasMinor)).get()); assertEquals("major exit", Command.EXIT_MAJOR_VIOLATION, command.getHighestReportSeverity(optsFailDefault, Arrays.asList(hasMajor, hasMajor)).get()); assertEquals("severe exit", Command.EXIT_SEVERE_VIOLATION, command.getHighestReportSeverity(optsFailDefault, Arrays.asList(hasSevere, hasMajor)).get()); }
Optional<Integer> getHighestReportSeverity(final @NotNull Options opts, final @NotNull List<CheckReport> reports) { return reports.stream() .flatMap(compose1(CheckReport::getViolations, Collection::stream)) .map(Violation::getSeverity) .reduce(Severity::maxSeverity) .filter(opts.getFailOnSeverity().meetsMinimumSeverity()) .map(severity -> { switch (severity) { case SEVERE: return EXIT_SEVERE_VIOLATION; case MAJOR: return EXIT_MAJOR_VIOLATION; case MINOR: default: return EXIT_MINOR_VIOLATION; } }); }
Command { Optional<Integer> getHighestReportSeverity(final @NotNull Options opts, final @NotNull List<CheckReport> reports) { return reports.stream() .flatMap(compose1(CheckReport::getViolations, Collection::stream)) .map(Violation::getSeverity) .reduce(Severity::maxSeverity) .filter(opts.getFailOnSeverity().meetsMinimumSeverity()) .map(severity -> { switch (severity) { case SEVERE: return EXIT_SEVERE_VIOLATION; case MAJOR: return EXIT_MAJOR_VIOLATION; case MINOR: default: return EXIT_MINOR_VIOLATION; } }); } }
Command { Optional<Integer> getHighestReportSeverity(final @NotNull Options opts, final @NotNull List<CheckReport> reports) { return reports.stream() .flatMap(compose1(CheckReport::getViolations, Collection::stream)) .map(Violation::getSeverity) .reduce(Severity::maxSeverity) .filter(opts.getFailOnSeverity().meetsMinimumSeverity()) .map(severity -> { switch (severity) { case SEVERE: return EXIT_SEVERE_VIOLATION; case MAJOR: return EXIT_MAJOR_VIOLATION; case MINOR: default: return EXIT_MINOR_VIOLATION; } }); }  }
Command { Optional<Integer> getHighestReportSeverity(final @NotNull Options opts, final @NotNull List<CheckReport> reports) { return reports.stream() .flatMap(compose1(CheckReport::getViolations, Collection::stream)) .map(Violation::getSeverity) .reduce(Severity::maxSeverity) .filter(opts.getFailOnSeverity().meetsMinimumSeverity()) .map(severity -> { switch (severity) { case SEVERE: return EXIT_SEVERE_VIOLATION; case MAJOR: return EXIT_MAJOR_VIOLATION; case MINOR: default: return EXIT_MINOR_VIOLATION; } }); }   }
Command { Optional<Integer> getHighestReportSeverity(final @NotNull Options opts, final @NotNull List<CheckReport> reports) { return reports.stream() .flatMap(compose1(CheckReport::getViolations, Collection::stream)) .map(Violation::getSeverity) .reduce(Severity::maxSeverity) .filter(opts.getFailOnSeverity().meetsMinimumSeverity()) .map(severity -> { switch (severity) { case SEVERE: return EXIT_SEVERE_VIOLATION; case MAJOR: return EXIT_MAJOR_VIOLATION; case MINOR: default: return EXIT_MINOR_VIOLATION; } }); }    }