1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-12-22 19:08:00 +01:00

Add MicAlgTest

This commit is contained in:
Paul Schaub 2022-01-08 01:07:45 +01:00
parent 1cb49f4b12
commit 987c328ad8

View file

@ -0,0 +1,53 @@
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package sop.util;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Test;
import sop.MicAlg;
public class MicAlgTest {
@Test
public void constructorNullArgThrows() {
assertThrows(IllegalArgumentException.class, () -> new MicAlg(null));
}
@Test
public void emptyMicAlgIsEmptyString() {
MicAlg empty = MicAlg.empty();
assertNotNull(empty.getMicAlg());
assertTrue(empty.getMicAlg().isEmpty());
}
@Test
public void fromInvalidAlgorithmIdThrows() {
assertThrows(IllegalArgumentException.class, () -> MicAlg.fromHashAlgorithmId(-1));
}
@Test
public void fromHashAlgorithmIdsKnownAlgsMatch() {
Map<Integer, String> knownAlgorithmMicalgs = new HashMap<>();
knownAlgorithmMicalgs.put(1, "pgp-md5");
knownAlgorithmMicalgs.put(2, "pgp-sha1");
knownAlgorithmMicalgs.put(3, "pgp-ripemd160");
knownAlgorithmMicalgs.put(8, "pgp-sha256");
knownAlgorithmMicalgs.put(9, "pgp-sha384");
knownAlgorithmMicalgs.put(10, "pgp-sha512");
knownAlgorithmMicalgs.put(11, "pgp-sha224");
for (Integer id : knownAlgorithmMicalgs.keySet()) {
MicAlg micAlg = MicAlg.fromHashAlgorithmId(id);
assertEquals(knownAlgorithmMicalgs.get(id), micAlg.getMicAlg());
}
}
}