Merge "GroupReference: Disallow null for name"
diff --git a/java/com/google/gerrit/common/data/GroupReference.java b/java/com/google/gerrit/common/data/GroupReference.java
index 8060659..cfaad17 100644
--- a/java/com/google/gerrit/common/data/GroupReference.java
+++ b/java/com/google/gerrit/common/data/GroupReference.java
@@ -61,6 +61,9 @@
}
public void setName(String newName) {
+ if (newName == null) {
+ throw new NullPointerException();
+ }
this.name = newName;
}
diff --git a/javatests/com/google/gerrit/common/data/GroupReferenceTest.java b/javatests/com/google/gerrit/common/data/GroupReferenceTest.java
index 4181423..717e122 100644
--- a/javatests/com/google/gerrit/common/data/GroupReferenceTest.java
+++ b/javatests/com/google/gerrit/common/data/GroupReferenceTest.java
@@ -18,9 +18,13 @@
import com.google.gerrit.reviewdb.client.AccountGroup;
import com.google.gerrit.reviewdb.client.AccountGroup.UUID;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
public class GroupReferenceTest {
+ @Rule public ExpectedException exception = ExpectedException.none();
+
@Test
public void forGroupDescription() {
String name = "foo";
@@ -54,6 +58,31 @@
}
@Test
+ public void create() {
+ AccountGroup.UUID uuid = new AccountGroup.UUID("uuid");
+ String name = "foo";
+ GroupReference groupReference = new GroupReference(uuid, name);
+ assertThat(groupReference.getUUID()).isEqualTo(uuid);
+ assertThat(groupReference.getName()).isEqualTo(name);
+ }
+
+ @Test
+ public void createWithoutUuid() {
+ // GroupReferences where the UUID is null are used to represent groups from project.config that
+ // cannot be resolved.
+ String name = "foo";
+ GroupReference groupReference = new GroupReference(null, name);
+ assertThat(groupReference.getUUID()).isNull();
+ assertThat(groupReference.getName()).isEqualTo(name);
+ }
+
+ @Test
+ public void cannotCreateWithoutName() {
+ exception.expect(NullPointerException.class);
+ new GroupReference(new AccountGroup.UUID("uuid"), null);
+ }
+
+ @Test
public void isGroupReference() {
assertThat(GroupReference.isGroupReference("foo")).isFalse();
assertThat(GroupReference.isGroupReference("groupfoo")).isFalse();
@@ -82,6 +111,8 @@
groupReference.setUUID(uuid2);
assertThat(groupReference.getUUID()).isEqualTo(uuid2);
+ // GroupReferences where the UUID is null are used to represent groups from project.config that
+ // cannot be resolved.
groupReference.setUUID(null);
assertThat(groupReference.getUUID()).isNull();
}
@@ -97,8 +128,8 @@
groupReference.setName(name2);
assertThat(groupReference.getName()).isEqualTo(name2);
+ exception.expect(NullPointerException.class);
groupReference.setName(null);
- assertThat(groupReference.getName()).isNull();
}
@Test