Paths implements ProgressCheckFactory { @Override public ProgressCheck newInstance(final JsonObject config) { List<Rule> rules = Rules.fromJsonArray(arrayOrEmpty(config, keys().rules())); final boolean denyAllDeletes = hasNonNull(config, keys().denyAllDeletes()) && config.getBoolean(keys().denyAllDeletes()); final Severity severity = Severity.valueOf( config.getString(keys().severity(), DEFAULT_SEVERITY.name()).toUpperCase()); return new Check(rules, denyAllDeletes, severity); }  @NotNull static JsonKeys keys(); @Override ProgressCheck newInstance(final JsonObject config); @Deprecated
    static final String CONFIG_RULES; @Deprecated
    static final String CONFIG_DENY_ALL_DELETES; @Deprecated
    static final String CONFIG_SEVERITY; static final Severity DEFAULT_SEVERITY; }
@Test public void testDefaultSeverity() throws Exception { TestUtil.testBlock(() -> { ProgressCheck check = new Paths().newInstance(key("rules", arr(denyEtc)).get()); CheckReport report = scanWithCheck(check, "test-package-with-etc.zip"); logViolations("level_set:no_unsafe", report); Assert.assertEquals("violations", 6, report.getViolations().size()); assertTrue("all violations are MAJOR", report.getViolations().stream() .allMatch(viol -> viol.getSeverity().equals(Severity.MAJOR))); }); }
@Test public void testCustomSeverity() throws Exception { TestUtil.testBlock(() -> { ProgressCheck check = new Paths().newInstance(key("severity", "SEVERE").key("rules", arr(denyEtc)).get()); CheckReport report = scanWithCheck(check, "test-package-with-etc.zip"); logViolations("level_set:no_unsafe", report); Assert.assertEquals("violations", 6, report.getViolations().size()); assertTrue("all violations are SEVERE", report.getViolations().stream() .allMatch(viol -> viol.getSeverity().equals(Severity.SEVERE))); }); }
@Test public void testCustomSeverityMixedCase() throws Exception { TestUtil.testBlock(() -> { ProgressCheck check = new Paths().newInstance(key("severity", "minor").key("rules", arr(denyEtc)).get()); CheckReport report = scanWithCheck(check, "test-package-with-etc.zip"); logViolations("level_set:no_unsafe", report); Assert.assertEquals("violations", 6, report.getViolations().size()); assertTrue("all violations are MINOR", report.getViolations().stream() .allMatch(viol -> viol.getSeverity().equals(Severity.MINOR))); }); }
@Test public void testBadSeverity() throws Exception { TestUtil.testBlock(() -> { boolean threw = false; try { ProgressCheck check = new Paths().newInstance(key("severity", "whoops").key("rules", arr(denyEtc)).get()); } catch (IllegalArgumentException e) { threw = true; } assertTrue("bad severity should cause exception on construction.", threw); }); }