@Test
public void testPatterns() throws Exception {

    TestUtil.testBlock(() -> {
        ProgressCheck check = new Subpackages().newInstance(key("rules", arr()).get());
        CheckReport report = scanWithCheck(check, "subtest_with_content.zip");
        logViolations("testPatterns:[]", report);
        Assert.assertEquals("no violations", 0, report.getViolations().size());
        assertTrue("all violations have packageIds", report.getViolations().stream()
                .allMatch(viol -> !viol.getPackages().isEmpty()));
    });
    TestUtil.testBlock(() -> {
        ProgressCheck check = new Subpackages().newInstance(
                key("rules", arr(key("type", "deny").key("pattern", "my_packages:sub_.*"))).get());
        CheckReport report = scanWithCheck(check, "subtest_with_content.zip");
        logViolations("testPatterns:sub_.*", report);
        Assert.assertEquals("two violations", 2, report.getViolations().size());
        assertTrue("all violations have packageIds", report.getViolations().stream()
                .allMatch(viol -> !viol.getPackages().isEmpty()));
    });
    TestUtil.testBlock(() -> {
        ProgressCheck check = new Subpackages().newInstance(
                key("rules", arr()
                        .val(key("type", "deny").key("pattern", "my_packages:sub_.*"))
                        .val(key("type", "allow").key("pattern", "my_packages:sub_a"))
                ).get());
        CheckReport report = scanWithCheck(check, "subtest_with_content.zip");
        logViolations("testPatterns:sub_.* - sub_a", report);
        Assert.assertEquals("one violation", 1, report.getViolations().size());
        assertTrue("all violations have packageIds", report.getViolations().stream()
                .allMatch(viol -> !viol.getPackages().isEmpty()));
    });
    TestUtil.testBlock(() -> {
        ProgressCheck check = new Subpackages().newInstance(
                key("rules", arr(key("type", "deny").key("pattern", "my_packages:sub_a"))).get());
        CheckReport report = scanWithCheck(check, "subtest_with_content.zip");
        logViolations("testPatterns:sub_a", report);
        Assert.assertEquals("one violation", 1, report.getViolations().size());
        assertTrue("all violations have packageIds", report.getViolations().stream()
                .allMatch(viol -> !viol.getPackages().isEmpty()));
    });
    TestUtil.testBlock(() -> {
        ProgressCheck check = new Subpackages().newInstance(
                key("rules", arr(key("type", "deny").key("pattern", "my_packages:sub_b"))).get());
        CheckReport report = scanWithCheck(check, "subtest_with_content.zip");
        logViolations("testPatterns:sub_b", report);
        Assert.assertEquals("one violation", 1, report.getViolations().size());
        assertTrue("all violations have packageIds", report.getViolations().stream()
                .allMatch(viol -> !viol.getPackages().isEmpty()));
    });
    TestUtil.testBlock(() -> {
        ProgressCheck check = new Subpackages().newInstance(
                key("rules", arr(key("type", "deny").key("pattern", "my_packages:sub_c"))).get());
        CheckReport report = scanWithCheck(check, "subtest_with_content.zip");
        logViolations("testPatterns:sub_c", report);
        Assert.assertEquals("one violation", 0, report.getViolations().size());
        assertTrue("all violations have packageIds", report.getViolations().stream()
                .allMatch(viol -> !viol.getPackages().isEmpty()));
    });
}