mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-06-22 18:19:34 +02:00
Ensure that verbs occur only once in the collection
This is necessary for equals to work correctly
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user