mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-11-30 00:02: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;
|
this.email = email;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder withName(String name) {
|
public Builder withName(@Nonnull String name) {
|
||||||
checkNotNull("name", name);
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder withComment(String comment) {
|
public Builder withComment(@Nonnull String comment) {
|
||||||
checkNotNull("comment", comment);
|
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder withEmail(String email) {
|
public Builder withEmail(@Nonnull String email) {
|
||||||
checkNotNull("email", email);
|
|
||||||
this.email = email;
|
this.email = email;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -72,13 +69,10 @@ public final class UserId implements CharSequence {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UserId onlyEmail(@Nonnull String email) {
|
public static UserId onlyEmail(@Nonnull String email) {
|
||||||
checkNotNull("email", email);
|
|
||||||
return new UserId(null, null, email);
|
return new UserId(null, null, email);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UserId nameAndEmail(@Nonnull String name, @Nonnull String email) {
|
public static UserId nameAndEmail(@Nonnull String name, @Nonnull String email) {
|
||||||
checkNotNull("name", name);
|
|
||||||
checkNotNull("email", email);
|
|
||||||
return new UserId(name, null, email);
|
return new UserId(name, null, email);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,10 +174,4 @@ public final class UserId implements CharSequence {
|
||||||
|| (!valueIsNull && !otherValueIsNull
|
|| (!valueIsNull && !otherValueIsNull
|
||||||
&& (ignoreCase ? value.equalsIgnoreCase(otherValue) : value.equals(otherValue)));
|
&& (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.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
||||||
|
|
||||||
public class UserIdTest {
|
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
|
@Test
|
||||||
public void testFormatOnlyName() {
|
public void testFormatOnlyName() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
|
@ -66,11 +50,6 @@ public class UserIdTest {
|
||||||
.toString());
|
.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void throwIfOnlyEmailEmailNull() {
|
|
||||||
assertThrows(IllegalArgumentException.class, () -> UserId.onlyEmail(null));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNameAndEmail() {
|
public void testNameAndEmail() {
|
||||||
UserId userId = UserId.nameAndEmail("Maurice Moss", "moss.m@reynholm.co.uk");
|
UserId userId = UserId.nameAndEmail("Maurice Moss", "moss.m@reynholm.co.uk");
|
||||||
|
|
Loading…
Reference in a new issue