1 /*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2013-2026 The Coveralls Maven Plugin Project Contributors:
5 * https://github.com/hazendaz/coveralls-maven-plugin/graphs/contributors
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 */
25 package org.eluder.coveralls.maven.plugin.util;
26
27 import java.io.ByteArrayInputStream;
28 import java.io.IOException;
29 import java.security.NoSuchAlgorithmException;
30
31 import org.junit.jupiter.api.Assertions;
32 import org.junit.jupiter.api.Test;
33
34 /**
35 * The Class Sha521DigestInputStreamTest.
36 */
37 class Sha521DigestInputStreamTest {
38
39 /**
40 * Test read.
41 *
42 * @throws NoSuchAlgorithmException
43 * the no such algorithm exception
44 * @throws IOException
45 * Signals that an I/O exception has occurred.
46 */
47 @Test
48 void read() throws NoSuchAlgorithmException, IOException {
49 final byte[] data = { (byte) 0xAA, (byte) 0xBB, (byte) 0xCC, (byte) 0xDD };
50 try (var is = new Sha512DigestInputStream(new ByteArrayInputStream(data))) {
51 Assertions.assertEquals(0xAA, is.read());
52 Assertions.assertEquals(0xBB, is.read());
53 Assertions.assertEquals(0xCC, is.read());
54 Assertions.assertEquals(0xDD, is.read());
55 Assertions.assertEquals(-1, is.read());
56 Assertions.assertEquals(
57 "48E218B30D4EA16305096FE35E84002A0D262EB3853131309423492228980C60238F9EED238285036F22E37C4662E40C80A461000A7AA9A03FB3CB6E4223E83B",
58 is.getDigestHex());
59 }
60 }
61
62 /**
63 * Read array.
64 *
65 * @throws NoSuchAlgorithmException
66 * the no such algorithm exception
67 * @throws IOException
68 * Signals that an I/O exception has occurred.
69 */
70 @Test
71 void readArray() throws NoSuchAlgorithmException, IOException {
72 final byte[] data = { (byte) 0xAA, (byte) 0xBB, (byte) 0xCC, (byte) 0xDD };
73 try (var is = new Sha512DigestInputStream(new ByteArrayInputStream(data))) {
74 final var buff = new byte[5];
75 Assertions.assertEquals(4, is.read(buff));
76 Assertions.assertEquals(-1, is.read());
77 for (var i = 0; i < data.length; i++) {
78 Assertions.assertEquals(data[i], buff[i]);
79 }
80 Assertions.assertEquals(
81 "48E218B30D4EA16305096FE35E84002A0D262EB3853131309423492228980C60238F9EED238285036F22E37C4662E40C80A461000A7AA9A03FB3CB6E4223E83B",
82 is.getDigestHex());
83 }
84 }
85
86 }