pgpainless/pgpainless-core/src/test/java/org/pgpainless/key/UserIdTest.java

79 lines
2.5 KiB
Java
Raw Normal View History

2020-11-13 15:59:28 +01:00
/*
* Copyright 2020 Paul Schaub.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.pgpainless.key;
2020-11-13 16:31:59 +01:00
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
2020-11-13 15:59:28 +01:00
2020-11-13 16:31:59 +01:00
import org.junit.jupiter.api.Test;
2020-11-13 15:59:28 +01:00
import org.pgpainless.key.util.UserId;
public class UserIdTest {
2020-11-13 16:31:59 +01:00
@Test
2020-11-13 15:59:28 +01:00
public void throwForNullName() {
2020-11-13 16:31:59 +01:00
assertThrows(IllegalArgumentException.class, () -> UserId.withName(null));
2020-11-13 15:59:28 +01:00
}
2020-11-13 16:31:59 +01:00
@Test
2020-11-13 15:59:28 +01:00
public void throwForNullComment() {
2020-11-13 16:31:59 +01:00
assertThrows(IllegalArgumentException.class, () -> UserId.withName("foo")
.withComment(null));
2020-11-13 15:59:28 +01:00
}
2020-11-13 16:31:59 +01:00
@Test
2020-11-13 15:59:28 +01:00
public void throwForNullEmail() {
2020-11-13 16:31:59 +01:00
assertThrows(IllegalArgumentException.class, () -> UserId.withName("foo")
2020-11-13 15:59:28 +01:00
.withComment("bar")
2020-11-13 16:31:59 +01:00
.withEmail(null));
2020-11-13 15:59:28 +01:00
}
@Test
public void testFormatOnlyName() {
assertEquals(
"Juliet Capulet",
UserId.withName("Juliet Capulet")
.build().toString());
}
@Test
public void testFormatNameAndComment() {
assertEquals(
"Juliet Capulet (from the play)",
UserId.withName("Juliet Capulet")
.withComment("from the play")
.noEmail().toString());
}
@Test
public void testFormatNameCommentAndMail() {
assertEquals("Juliet Capulet (from the play) <juliet@capulet.lit>",
UserId.withName("Juliet Capulet")
.withComment("from the play")
.withEmail("juliet@capulet.lit")
.toString());
}
@Test
public void testFormatNameAndEmail() {
assertEquals("Juliet Capulet <juliet@capulet.lit>",
UserId.withName("Juliet Capulet")
.noComment()
.withEmail("juliet@capulet.lit")
.toString());
}
}