-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMicAlgTest.java
More file actions
66 lines (54 loc) · 2.06 KB
/
MicAlgTest.java
File metadata and controls
66 lines (54 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package sop;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayOutputStream;
import java.util.HashMap;
import java.util.Map;
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;
public class MicAlgTest {
@Test
public void constructorNullArgThrows() {
assertThrows(NullPointerException.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());
}
}
@Test
public void testWriteTo() {
MicAlg m = MicAlg.fromHashAlgorithmId(10);
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
m.writeTo(bOut);
assertEquals("pgp-sha512", bOut.toString());
m = MicAlg.empty();
bOut = new ByteArrayOutputStream();
m.writeTo(bOut);
assertEquals("", bOut.toString());
}
}