From 987c328ad889b034ed13851fa57cdca869d4905c Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Sat, 8 Jan 2022 01:07:45 +0100 Subject: [PATCH] Add MicAlgTest --- .../src/test/java/sop/util/MicAlgTest.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 sop-java/src/test/java/sop/util/MicAlgTest.java diff --git a/sop-java/src/test/java/sop/util/MicAlgTest.java b/sop-java/src/test/java/sop/util/MicAlgTest.java new file mode 100644 index 00000000..f720c85b --- /dev/null +++ b/sop-java/src/test/java/sop/util/MicAlgTest.java @@ -0,0 +1,53 @@ +// SPDX-FileCopyrightText: 2022 Paul Schaub +// +// 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 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()); + } + } +}