@Test
void filter() {

    StoredPasswordFilter filter = new StoredPasswordFilter();
    Bundle filteredBundle = new Bundle();
    filteredBundle.addEntity(TestUtils.createPolicy("my-policy", "1", "", "", null, ""));
    Bundle bundle = FilterTestUtils.getBundle();
    bundle.setDependencyMap(
            ImmutableMap.of(
                    new Dependency("1", Policy.class, "my-policy", EntityTypes.POLICY_TYPE), Arrays.asList(new Dependency("2", StoredPassword.class, "password2", EntityTypes.STORED_PASSWORD_TYPE), new Dependency("3", StoredPassword.class, "password3", EntityTypes.STORED_PASSWORD_TYPE)),
                    new Dependency("2", Policy.class, "my-policy2", EntityTypes.POLICY_TYPE), Collections.singletonList(new Dependency("4", StoredPassword.class, "password4", EntityTypes.STORED_PASSWORD_TYPE))));
    bundle.addEntity(new StoredPassword.Builder().name("password1").id("1").properties(ImmutableMap.of("type", StoredPassword.Type.PASSWORD.getName())).build());
    bundle.addEntity(new StoredPassword.Builder().name("password2").id("2").properties(ImmutableMap.of("type", StoredPassword.Type.PASSWORD.getName())).build());
    bundle.addEntity(new StoredPassword.Builder().name("password3").id("3").properties(ImmutableMap.of("type", StoredPassword.Type.PEM_PRIVATE_KEY.getName())).build());
    bundle.addEntity(new StoredPassword.Builder().name("password4").id("4").properties(ImmutableMap.of("type", StoredPassword.Type.PASSWORD.getName())).build());
    FilterConfiguration filterConfiguration = new FilterConfiguration();
    List<StoredPassword> filteredEntities = filter.filter("/my/folder/path", filterConfiguration, bundle, filteredBundle);
    assertEquals(1, filteredEntities.size());
    assertTrue(filteredEntities.stream().anyMatch(c -> "password2".equals(c.getName())));
    filterConfiguration.getEntityFilters().put(filter.getFilterableEntityName(), new HashSet<>());
    filterConfiguration.getEntityFilters().get(filter.getFilterableEntityName()).add("password4");
    filteredEntities = filter.filter("/my/folder/path", filterConfiguration, bundle, filteredBundle);
    assertEquals(2, filteredEntities.size());
    assertTrue(filteredEntities.stream().anyMatch(c -> "password2".equals(c.getName())));
    assertTrue(filteredEntities.stream().anyMatch(c -> "password4".equals(c.getName())));
    filterConfiguration.getEntityFilters().get(filter.getFilterableEntityName()).add("non-existing-entity");
    EntityFilterException entityFilterException = assertThrows(EntityFilterException.class, () -> filter.filter("/my/folder/path", filterConfiguration, bundle, filteredBundle));
    assertTrue(entityFilterException.getMessage().contains("non-existing-entity"));
}