@Test
public void when_many_app_env_permission_are_revoked_the_resource_is_saved_only_one_time() throws Exception {

    // Given
    resourceSecured = new AbstractSecurityEnabledResource() {
        @Override
        public String getId() {
            return "id";
        }
    };
    HashSet<Permission> permissions = new HashSet<>();
    permissions.add(Permission.ADMIN);
    resourceSecured.addPermissions(Subject.APPLICATION, "subject1", new HashSet<>(permissions));
    resourceSecured.addPermissions(Subject.ENVIRONMENT, "subject1_1", new HashSet<>(permissions));
    resourceSecured.addPermissions(Subject.ENVIRONMENT, "subject1_2", new HashSet<>(permissions));
    resourceSecured.addPermissions(Subject.ENVIRONMENT_TYPE, "subject_env_1_1", new HashSet<>(permissions));
    ApplicationEnvironment ae1 = new ApplicationEnvironment();
    ae1.setId("subject1_1");
    ApplicationEnvironment ae2 = new ApplicationEnvironment();
    ae2.setId("subject1_2");
    Mockito.when(applicationEnvironmentService.getByApplicationId("subject1")).thenReturn(new ApplicationEnvironment[] { ae1, ae2 });
    // When
    service.revokeAuthorizedEnvironmentsAndEnvironmentTypesPerApplication((AbstractSecurityEnabledResource) resourceSecured, new String[] { "subject1" }, new String[] {
            "subject1_1", "subject1_2" }, new String[] {"subject_env_1_1" });
    // Then
    verify(alienDAO).save(resourceSecuredCaptor.capture());
}