Merge "GroupReference: Disallow null for name"
This commit is contained in:
commit
26fb902345
@ -61,6 +61,9 @@ public class GroupReference implements Comparable<GroupReference> {
|
||||
}
|
||||
|
||||
public void setName(String newName) {
|
||||
if (newName == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
this.name = newName;
|
||||
}
|
||||
|
||||
|
@ -18,9 +18,13 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
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";
|
||||
@ -53,6 +57,31 @@ public class GroupReferenceTest {
|
||||
assertThat(groupReference.getUUID()).isEqualTo(uuid);
|
||||
}
|
||||
|
||||
@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();
|
||||
@ -82,6 +111,8 @@ public class GroupReferenceTest {
|
||||
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 @@ public class GroupReferenceTest {
|
||||
groupReference.setName(name2);
|
||||
assertThat(groupReference.getName()).isEqualTo(name2);
|
||||
|
||||
exception.expect(NullPointerException.class);
|
||||
groupReference.setName(null);
|
||||
assertThat(groupReference.getName()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user