mirror of
https://github.com/pgpainless/pgpainless.git
synced 2025-12-08 13:21:09 +01:00
Add tests for LongExtension methods
This commit is contained in:
parent
88d9fae2fc
commit
06d0b90ff6
3 changed files with 40 additions and 5 deletions
38
pgpainless-core/src/test/java/openpgp/LongExtensionTest.java
Normal file
38
pgpainless-core/src/test/java/openpgp/LongExtensionTest.java
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
// SPDX-FileCopyrightText: 2025 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package openpgp;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.pgpainless.key.util.KeyIdUtil;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
public class LongExtensionTest {
|
||||
|
||||
private final Random random = new Random();
|
||||
|
||||
@Test
|
||||
public void testFromOpenPGPKeyId() {
|
||||
long id = random.nextLong();
|
||||
String hexId = LongExtensionsKt.openPgpKeyId(id);
|
||||
assertEquals(16, hexId.length());
|
||||
// Calling companion object extension methods from java is tricky.
|
||||
// KeyIdUtil delegates to Long.Companion extension method though.
|
||||
long parsed = KeyIdUtil.fromLongKeyId(hexId);
|
||||
assertEquals(id, parsed, "Long MUST still match after converting to hex and back.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParsingMalformedHexIdFails() {
|
||||
assertThrows(IllegalArgumentException.class, () ->
|
||||
KeyIdUtil.fromLongKeyId("00"),
|
||||
"Hex encoding is too short, expect 16 chars.");assertThrows(IllegalArgumentException.class, () ->
|
||||
KeyIdUtil.fromLongKeyId("00010203040506XX"),
|
||||
"Hex encoding contains non-hex chars.");
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue