FilterSets implements ProgressCheckFactory { @Override public ProgressCheck newInstance(final JsonObject config) { final Severity importModeSeverity = Severity .valueOf(config.getString(keys().importModeSeverity(), DEFAULT_IMPORT_MODE_SEVERITY.name()) .toUpperCase()); final boolean allowEmptyFilter = hasNonNull(config, keys().allowEmptyFilter()) && config.getBoolean(keys().allowEmptyFilter()); final boolean allowRootFilter = hasNonNull(config, keys().allowRootFilter()) && config.getBoolean(keys().allowRootFilter()); return new Check(importModeSeverity, allowEmptyFilter, allowRootFilter); }  @NotNull static JsonKeys keys(); @Override ProgressCheck newInstance(final JsonObject config); @Deprecated
    static final String CONFIG_IMPORT_MODE_SEVERITY; @Deprecated
    static final String CONFIG_ALLOW_EMPTY_FILTER; @Deprecated
    static final String CONFIG_ALLOW_ROOT_FILTER; static final Severity DEFAULT_IMPORT_MODE_SEVERITY; }
@Test public void testRootImport() throws Exception { TestUtil.testBlock(() -> { ProgressCheck handler = new FilterSets().newInstance(obj().get()); CheckReport report = scanWithCheck(handler, "testrootimport.zip"); Assert.assertEquals("one violation", 1, report.getViolations().size()); assertTrue("all violations have packageIds", report.getViolations().stream() .allMatch(viol -> !viol.getPackages().isEmpty())); }); TestUtil.testBlock(() -> { ProgressCheck handler = new FilterSets().newInstance(key("allowRootFilter", true).get()); CheckReport report = scanWithCheck(handler, "testrootimport.zip"); Assert.assertEquals("no violations", 0, report.getViolations().size()); assertTrue("all violations have packageIds", report.getViolations().stream() .allMatch(viol -> !viol.getPackages().isEmpty())); }); }
@Test public void testModeMerge() throws Exception { TestUtil.testBlock(() -> { ProgressCheck handler = new FilterSets().newInstance(obj().get()); CheckReport report = scanWithCheck(handler, "tmp_mode_merge.zip"); Assert.assertEquals("one violation", 1, report.getViolations().size()); Assert.assertEquals("is severity", Severity.MINOR, report.getViolations().iterator().next().getSeverity()); assertTrue("all violations have packageIds", report.getViolations().stream() .allMatch(viol -> !viol.getPackages().isEmpty())); }); TestUtil.testBlock(() -> { ProgressCheck handler = new FilterSets().newInstance(key("importModeSeverity", "severe").get()); CheckReport report = scanWithCheck(handler, "tmp_mode_merge.zip"); Assert.assertEquals("one violation", 1, report.getViolations().size()); Assert.assertEquals("is severity", Severity.SEVERE, report.getViolations().iterator().next().getSeverity()); assertTrue("all violations have packageIds", report.getViolations().stream() .allMatch(viol -> !viol.getPackages().isEmpty())); }); }
@Test public void testEmptyFilter() throws Exception { TestUtil.testBlock(() -> { ProgressCheck handler = new FilterSets().newInstance(obj().get()); CheckReport report = scanWithCheck(handler, "tmp_foo_bar_test_nofilter.zip"); Assert.assertEquals("one violation", 1, report.getViolations().size()); Assert.assertEquals("is severity", Severity.MAJOR, report.getViolations().iterator().next().getSeverity()); assertTrue("all violations have packageIds", report.getViolations().stream() .allMatch(viol -> !viol.getPackages().isEmpty())); }); TestUtil.testBlock(() -> { ProgressCheck handler = new FilterSets().newInstance(key("allowEmptyFilter", true).get()); CheckReport report = scanWithCheck(handler, "tmp_foo_bar_test_nofilter.zip"); Assert.assertEquals("no violations", 0, report.getViolations().size()); assertTrue("all violations have packageIds", report.getViolations().stream() .allMatch(viol -> !viol.getPackages().isEmpty())); }); }