Ensure that verbs occur only once in the collection

This is necessary for equals to work correctly
This commit is contained in:
René Pfeuffer
2019-02-04 16:33:03 +01:00
parent 42456af6d5
commit 7369f1cfce
2 changed files with 14 additions and 4 deletions

View File

@@ -46,9 +46,10 @@ import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Set;
import static java.util.Collections.emptyList;
import static java.util.Collections.unmodifiableCollection;
import static java.util.Collections.unmodifiableSet;
//~--- JDK imports ------------------------------------------------------------
@@ -67,7 +68,7 @@ public class RepositoryPermission implements PermissionObject, Serializable
private boolean groupPermission = false;
private String name;
@XmlElement(name = "verb")
private Collection<String> verbs;
private Set<String> verbs;
/**
* Constructs a new {@link RepositoryPermission}.
@@ -78,7 +79,7 @@ public class RepositoryPermission implements PermissionObject, Serializable
public RepositoryPermission(String name, Collection<String> verbs, boolean groupPermission)
{
this.name = name;
this.verbs = unmodifiableCollection(new LinkedHashSet<>(verbs));
this.verbs = unmodifiableSet(new LinkedHashSet<>(verbs));
this.groupPermission = groupPermission;
}
@@ -209,6 +210,6 @@ public class RepositoryPermission implements PermissionObject, Serializable
*/
public void setVerbs(Collection<String> verbs)
{
this.verbs = verbs;
this.verbs = unmodifiableSet(new LinkedHashSet<>(verbs));
}
}

View File

@@ -46,4 +46,13 @@ class RepositoryPermissionTest {
assertThat(permission1).isNotEqualTo(permission2);
}
@Test
void shouldBeEqualWithRedundantVerbs() {
RepositoryPermission permission1 = new RepositoryPermission("name1", asList("one", "two"), false);
RepositoryPermission permission2 = new RepositoryPermission("name1", asList("one", "two"), false);
permission2.setVerbs(asList("one", "two", "two"));
assertThat(permission1).isEqualTo(permission2);
}
}