mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-09-09 18:29:39 +02:00
UserId: Remove deprecated method usage
This commit is contained in:
parent
b181efee00
commit
429186c5e1
3 changed files with 26 additions and 36 deletions
|
@ -6,15 +6,9 @@ package org.pgpainless.key.util
|
||||||
|
|
||||||
class UserId internal constructor(name: String?, comment: String?, email: String?) : CharSequence {
|
class UserId internal constructor(name: String?, comment: String?, email: String?) : CharSequence {
|
||||||
|
|
||||||
private val _name: String?
|
private val _name: String? = name?.trim()
|
||||||
val comment: String?
|
val comment: String? = comment?.trim()
|
||||||
val email: String?
|
val email: String? = email?.trim()
|
||||||
|
|
||||||
init {
|
|
||||||
this._name = name?.trim()
|
|
||||||
this.comment = comment?.trim()
|
|
||||||
this.email = email?.trim()
|
|
||||||
}
|
|
||||||
|
|
||||||
val full: String = buildString {
|
val full: String = buildString {
|
||||||
if (name?.isNotBlank() == true) {
|
if (name?.isNotBlank() == true) {
|
||||||
|
@ -170,10 +164,6 @@ class UserId internal constructor(name: String?, comment: String?, email: String
|
||||||
fun compare(u1: UserId?, u2: UserId?, comparator: Comparator<UserId?>) =
|
fun compare(u1: UserId?, u2: UserId?, comparator: Comparator<UserId?>) =
|
||||||
comparator.compare(u1, u2)
|
comparator.compare(u1, u2)
|
||||||
|
|
||||||
@JvmStatic
|
|
||||||
@Deprecated("Deprecated in favor of builde() method.", ReplaceWith("builder()"))
|
|
||||||
fun newBuilder() = builder()
|
|
||||||
|
|
||||||
@JvmStatic fun builder() = Builder()
|
@JvmStatic fun builder() = Builder()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ public class UserIdTest {
|
||||||
public void testFormatOnlyName() {
|
public void testFormatOnlyName() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"Juliet Capulet",
|
"Juliet Capulet",
|
||||||
UserId.newBuilder().withName("Juliet Capulet")
|
UserId.builder().withName("Juliet Capulet")
|
||||||
.build().toString());
|
.build().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ public class UserIdTest {
|
||||||
public void testFormatNameAndComment() {
|
public void testFormatNameAndComment() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"Juliet Capulet (from the play)",
|
"Juliet Capulet (from the play)",
|
||||||
UserId.newBuilder().withName("Juliet Capulet")
|
UserId.builder().withName("Juliet Capulet")
|
||||||
.withComment("from the play")
|
.withComment("from the play")
|
||||||
.noEmail().build().toString());
|
.noEmail().build().toString());
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ public class UserIdTest {
|
||||||
@Test
|
@Test
|
||||||
public void testFormatNameCommentAndMail() {
|
public void testFormatNameCommentAndMail() {
|
||||||
assertEquals("Juliet Capulet (from the play) <juliet@capulet.lit>",
|
assertEquals("Juliet Capulet (from the play) <juliet@capulet.lit>",
|
||||||
UserId.newBuilder().withName("Juliet Capulet")
|
UserId.builder().withName("Juliet Capulet")
|
||||||
.withComment("from the play")
|
.withComment("from the play")
|
||||||
.withEmail("juliet@capulet.lit")
|
.withEmail("juliet@capulet.lit")
|
||||||
.build()
|
.build()
|
||||||
|
@ -45,7 +45,7 @@ public class UserIdTest {
|
||||||
@Test
|
@Test
|
||||||
public void testFormatNameAndEmail() {
|
public void testFormatNameAndEmail() {
|
||||||
assertEquals("Juliet Capulet <juliet@capulet.lit>",
|
assertEquals("Juliet Capulet <juliet@capulet.lit>",
|
||||||
UserId.newBuilder().withName("Juliet Capulet")
|
UserId.builder().withName("Juliet Capulet")
|
||||||
.noComment()
|
.noComment()
|
||||||
.withEmail("juliet@capulet.lit")
|
.withEmail("juliet@capulet.lit")
|
||||||
.build()
|
.build()
|
||||||
|
@ -60,7 +60,7 @@ public class UserIdTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testBuilderWithName() {
|
void testBuilderWithName() {
|
||||||
final UserId userId = UserId.newBuilder().withName("John Smith").build();
|
final UserId userId = UserId.builder().withName("John Smith").build();
|
||||||
assertEquals("John Smith", userId.getName());
|
assertEquals("John Smith", userId.getName());
|
||||||
assertNull(userId.getComment());
|
assertNull(userId.getComment());
|
||||||
assertNull(userId.getEmail());
|
assertNull(userId.getEmail());
|
||||||
|
@ -68,7 +68,7 @@ public class UserIdTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testBuilderWithComment() {
|
void testBuilderWithComment() {
|
||||||
final UserId userId = UserId.newBuilder().withComment("Sales Dept.").build();
|
final UserId userId = UserId.builder().withComment("Sales Dept.").build();
|
||||||
assertNull(userId.getName());
|
assertNull(userId.getName());
|
||||||
assertEquals("Sales Dept.", userId.getComment());
|
assertEquals("Sales Dept.", userId.getComment());
|
||||||
assertNull(userId.getEmail());
|
assertNull(userId.getEmail());
|
||||||
|
@ -76,7 +76,7 @@ public class UserIdTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testBuilderWithEmail() {
|
void testBuilderWithEmail() {
|
||||||
final UserId userId = UserId.newBuilder().withEmail("john.smith@example.com").build();
|
final UserId userId = UserId.builder().withEmail("john.smith@example.com").build();
|
||||||
assertNull(userId.getName());
|
assertNull(userId.getName());
|
||||||
assertNull(userId.getComment());
|
assertNull(userId.getComment());
|
||||||
assertEquals("john.smith@example.com", userId.getEmail());
|
assertEquals("john.smith@example.com", userId.getEmail());
|
||||||
|
@ -84,7 +84,7 @@ public class UserIdTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testBuilderWithAll() {
|
void testBuilderWithAll() {
|
||||||
final UserId userId = UserId.newBuilder().withEmail("john.smith@example.com")
|
final UserId userId = UserId.builder().withEmail("john.smith@example.com")
|
||||||
.withName("John Smith")
|
.withName("John Smith")
|
||||||
.withEmail("john.smith@example.com")
|
.withEmail("john.smith@example.com")
|
||||||
.withComment("Sales Dept.").build();
|
.withComment("Sales Dept.").build();
|
||||||
|
@ -95,7 +95,7 @@ public class UserIdTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testBuilderNoName() {
|
void testBuilderNoName() {
|
||||||
final UserId.Builder builder = UserId.newBuilder()
|
final UserId.Builder builder = UserId.builder()
|
||||||
.withEmail("john.smith@example.com")
|
.withEmail("john.smith@example.com")
|
||||||
.withName("John Smith")
|
.withName("John Smith")
|
||||||
.withComment("Sales Dept.").build().toBuilder();
|
.withComment("Sales Dept.").build().toBuilder();
|
||||||
|
@ -107,7 +107,7 @@ public class UserIdTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testBuilderNoComment() {
|
void testBuilderNoComment() {
|
||||||
final UserId.Builder builder = UserId.newBuilder()
|
final UserId.Builder builder = UserId.builder()
|
||||||
.withEmail("john.smith@example.com")
|
.withEmail("john.smith@example.com")
|
||||||
.withName("John Smith")
|
.withName("John Smith")
|
||||||
.withComment("Sales Dept.").build().toBuilder();
|
.withComment("Sales Dept.").build().toBuilder();
|
||||||
|
@ -119,7 +119,7 @@ public class UserIdTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testBuilderNoEmail() {
|
void testBuilderNoEmail() {
|
||||||
final UserId.Builder builder = UserId.newBuilder()
|
final UserId.Builder builder = UserId.builder()
|
||||||
.withEmail("john.smith@example.com")
|
.withEmail("john.smith@example.com")
|
||||||
.withName("John Smith")
|
.withName("John Smith")
|
||||||
.withComment("Sales Dept.").build().toBuilder();
|
.withComment("Sales Dept.").build().toBuilder();
|
||||||
|
@ -143,7 +143,7 @@ public class UserIdTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testEmptyNameAndEmptyCommentAndValidEmailFormatting() {
|
void testEmptyNameAndEmptyCommentAndValidEmailFormatting() {
|
||||||
final UserId userId = UserId.newBuilder()
|
final UserId userId = UserId.builder()
|
||||||
.withComment("")
|
.withComment("")
|
||||||
.withName("")
|
.withName("")
|
||||||
.withEmail("john.smith@example.com")
|
.withEmail("john.smith@example.com")
|
||||||
|
@ -157,8 +157,8 @@ public class UserIdTest {
|
||||||
final String comment = "Sales Dept.";
|
final String comment = "Sales Dept.";
|
||||||
final String email = "john.smith@example.com";
|
final String email = "john.smith@example.com";
|
||||||
final String upperEmail = email.toUpperCase();
|
final String upperEmail = email.toUpperCase();
|
||||||
final UserId userId1 = UserId.newBuilder().withComment(comment).withName(name).withEmail(email).build();
|
final UserId userId1 = UserId.builder().withComment(comment).withName(name).withEmail(email).build();
|
||||||
final UserId userId2 = UserId.newBuilder().withComment(comment).withName(name).withEmail(upperEmail).build();
|
final UserId userId2 = UserId.builder().withComment(comment).withName(name).withEmail(upperEmail).build();
|
||||||
assertEquals(userId1, userId2);
|
assertEquals(userId1, userId2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,8 +168,8 @@ public class UserIdTest {
|
||||||
final String name2 = "Don Duck";
|
final String name2 = "Don Duck";
|
||||||
final String comment = "Sales Dept.";
|
final String comment = "Sales Dept.";
|
||||||
final String email = "john.smith@example.com";
|
final String email = "john.smith@example.com";
|
||||||
final UserId userId1 = UserId.newBuilder().withComment(comment).withName(name1).withEmail(email).build();
|
final UserId userId1 = UserId.builder().withComment(comment).withName(name1).withEmail(email).build();
|
||||||
final UserId userId2 = UserId.newBuilder().withComment(comment).withName(name2).withEmail(email).build();
|
final UserId userId2 = UserId.builder().withComment(comment).withName(name2).withEmail(email).build();
|
||||||
assertNotEquals(userId1, userId2);
|
assertNotEquals(userId1, userId2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,8 +179,8 @@ public class UserIdTest {
|
||||||
final String comment1 = "Sales Dept.";
|
final String comment1 = "Sales Dept.";
|
||||||
final String comment2 = "Legal Dept.";
|
final String comment2 = "Legal Dept.";
|
||||||
final String email = "john.smith@example.com";
|
final String email = "john.smith@example.com";
|
||||||
final UserId userId1 = UserId.newBuilder().withComment(comment1).withName(name).withEmail(email).build();
|
final UserId userId1 = UserId.builder().withComment(comment1).withName(name).withEmail(email).build();
|
||||||
final UserId userId2 = UserId.newBuilder().withComment(comment2).withName(name).withEmail(email).build();
|
final UserId userId2 = UserId.builder().withComment(comment2).withName(name).withEmail(email).build();
|
||||||
assertNotEquals(userId1, userId2);
|
assertNotEquals(userId1, userId2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,8 +220,8 @@ public class UserIdTest {
|
||||||
UserId id2 = UserId.onlyEmail("alice@gnupg.org");
|
UserId id2 = UserId.onlyEmail("alice@gnupg.org");
|
||||||
UserId id3 = UserId.nameAndEmail("Alice", "alice@pgpainless.org");
|
UserId id3 = UserId.nameAndEmail("Alice", "alice@pgpainless.org");
|
||||||
UserId id3_ = UserId.nameAndEmail("Alice", "alice@pgpainless.org");
|
UserId id3_ = UserId.nameAndEmail("Alice", "alice@pgpainless.org");
|
||||||
UserId id4 = UserId.newBuilder().withName("Alice").build();
|
UserId id4 = UserId.builder().withName("Alice").build();
|
||||||
UserId id5 = UserId.newBuilder().withName("Alice").withComment("Work Mail").withEmail("alice@pgpainless.org").build();
|
UserId id5 = UserId.builder().withName("Alice").withComment("Work Mail").withEmail("alice@pgpainless.org").build();
|
||||||
|
|
||||||
assertEquals(id3.hashCode(), id3_.hashCode());
|
assertEquals(id3.hashCode(), id3_.hashCode());
|
||||||
assertNotEquals(id2.hashCode(), id3.hashCode());
|
assertNotEquals(id2.hashCode(), id3.hashCode());
|
||||||
|
@ -250,8 +250,8 @@ public class UserIdTest {
|
||||||
UserId id1 = UserId.nameAndEmail("Alice", "alice@pgpainless.org");
|
UserId id1 = UserId.nameAndEmail("Alice", "alice@pgpainless.org");
|
||||||
UserId id2 = UserId.nameAndEmail("alice", "alice@pgpainless.org");
|
UserId id2 = UserId.nameAndEmail("alice", "alice@pgpainless.org");
|
||||||
UserId id3 = UserId.nameAndEmail("Alice", "Alice@Pgpainless.Org");
|
UserId id3 = UserId.nameAndEmail("Alice", "Alice@Pgpainless.Org");
|
||||||
UserId id4 = UserId.newBuilder().withName("Alice").withComment("Work Email").withEmail("Alice@Pgpainless.Org").build();
|
UserId id4 = UserId.builder().withName("Alice").withComment("Work Email").withEmail("Alice@Pgpainless.Org").build();
|
||||||
UserId id5 = UserId.newBuilder().withName("alice").withComment("work email").withEmail("alice@pgpainless.org").build();
|
UserId id5 = UserId.builder().withName("alice").withComment("work email").withEmail("alice@pgpainless.org").build();
|
||||||
UserId id6 = UserId.nameAndEmail("Bob", "bob@pgpainless.org");
|
UserId id6 = UserId.nameAndEmail("Bob", "bob@pgpainless.org");
|
||||||
|
|
||||||
Comparator<UserId> c = new UserId.DefaultIgnoreCaseComparator();
|
Comparator<UserId> c = new UserId.DefaultIgnoreCaseComparator();
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class SelectUserIdTest {
|
||||||
.getPGPSecretKeyRing();
|
.getPGPSecretKeyRing();
|
||||||
secretKeys = PGPainless.modifyKeyRing(secretKeys)
|
secretKeys = PGPainless.modifyKeyRing(secretKeys)
|
||||||
.addUserId(
|
.addUserId(
|
||||||
UserId.newBuilder().withName("Alice Liddell").noComment()
|
UserId.builder().withName("Alice Liddell").noComment()
|
||||||
.withEmail("crazy@the-rabbit.hole").build(),
|
.withEmail("crazy@the-rabbit.hole").build(),
|
||||||
SecretKeyRingProtector.unprotectedKeys())
|
SecretKeyRingProtector.unprotectedKeys())
|
||||||
.done();
|
.done();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue