mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-26 06:12:06 +01:00
Simplify UserIdTests
This commit is contained in:
parent
4c1d359971
commit
837fbd3635
2 changed files with 3 additions and 36 deletions
|
@ -22,20 +22,17 @@ public final class UserId implements CharSequence {
|
|||
this.email = email;
|
||||
}
|
||||
|
||||
public Builder withName(String name) {
|
||||
checkNotNull("name", name);
|
||||
public Builder withName(@Nonnull String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withComment(String comment) {
|
||||
checkNotNull("comment", comment);
|
||||
public Builder withComment(@Nonnull String comment) {
|
||||
this.comment = comment;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder withEmail(String email) {
|
||||
checkNotNull("email", email);
|
||||
public Builder withEmail(@Nonnull String email) {
|
||||
this.email = email;
|
||||
return this;
|
||||
}
|
||||
|
@ -72,13 +69,10 @@ public final class UserId implements CharSequence {
|
|||
}
|
||||
|
||||
public static UserId onlyEmail(@Nonnull String email) {
|
||||
checkNotNull("email", email);
|
||||
return new UserId(null, null, email);
|
||||
}
|
||||
|
||||
public static UserId nameAndEmail(@Nonnull String name, @Nonnull String email) {
|
||||
checkNotNull("name", name);
|
||||
checkNotNull("email", email);
|
||||
return new UserId(name, null, email);
|
||||
}
|
||||
|
||||
|
@ -180,10 +174,4 @@ public final class UserId implements CharSequence {
|
|||
|| (!valueIsNull && !otherValueIsNull
|
||||
&& (ignoreCase ? value.equalsIgnoreCase(otherValue) : value.equals(otherValue)));
|
||||
}
|
||||
|
||||
private static void checkNotNull(String paramName, String value) {
|
||||
if (value == null) {
|
||||
throw new IllegalArgumentException(paramName + " must be not null");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,25 +10,9 @@ import org.pgpainless.key.util.UserId;
|
|||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
public class UserIdTest {
|
||||
|
||||
@Test
|
||||
public void throwForNullName() {
|
||||
assertThrows(IllegalArgumentException.class, () -> UserId.newBuilder().withName(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void throwForNullComment() {
|
||||
assertThrows(IllegalArgumentException.class, () -> UserId.newBuilder().withComment(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void throwForNullEmail() {
|
||||
assertThrows(IllegalArgumentException.class, () -> UserId.newBuilder().withEmail(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatOnlyName() {
|
||||
assertEquals(
|
||||
|
@ -66,11 +50,6 @@ public class UserIdTest {
|
|||
.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void throwIfOnlyEmailEmailNull() {
|
||||
assertThrows(IllegalArgumentException.class, () -> UserId.onlyEmail(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNameAndEmail() {
|
||||
UserId userId = UserId.nameAndEmail("Maurice Moss", "moss.m@reynholm.co.uk");
|
||||
|
|
Loading…
Reference in a new issue