From aad48ef586cead54a570e14c741c3e1a9b22618e Mon Sep 17 00:00:00 2001 From: Scott Buchanan <46462768+EdgarScott@users.noreply.github.com> Date: Fri, 30 Aug 2019 16:53:18 +0100 Subject: [PATCH] Adding unit tests for net.authorize.sample.Sha512.ComputeTransHashSHA2.java These tests were written using Diffblue Cover --- pom.xml | 6 ++ .../Sha512/ComputeTransHashSHA2Test.java | 57 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 src/test/java/net/authorize/sample/Sha512/ComputeTransHashSHA2Test.java diff --git a/pom.xml b/pom.xml index b5631847..9396c5bd 100644 --- a/pom.xml +++ b/pom.xml @@ -21,6 +21,12 @@ junit 4.8.1 + + junit + junit + 4.12 + test + diff --git a/src/test/java/net/authorize/sample/Sha512/ComputeTransHashSHA2Test.java b/src/test/java/net/authorize/sample/Sha512/ComputeTransHashSHA2Test.java new file mode 100644 index 00000000..01d5f590 --- /dev/null +++ b/src/test/java/net/authorize/sample/Sha512/ComputeTransHashSHA2Test.java @@ -0,0 +1,57 @@ +package net.authorize.sample.Sha512; + +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +public class ComputeTransHashSHA2Test { + + @Rule public final ExpectedException thrown = ExpectedException.none(); + + @Test + public void getHMACSHA512InputNotNullNotNullOutputIllegalArgumentException() throws Exception { + thrown.expect(IllegalArgumentException.class); + ComputeTransHashSHA2.getHMACSHA512("/", "/"); + } + + @Test + public void getHMACSHA512InputNotNullNotNullOutputIllegalArgumentException2() throws Exception { + thrown.expect(IllegalArgumentException.class); + ComputeTransHashSHA2.getHMACSHA512( + "\u0003\u0001\u0001 \u0010\u0000 0 ", + "\u0000\u0000\u0000?????????????????????????????????????"); + } + + @Test + public void getHMACSHA512InputNotNullNullOutputIllegalArgumentException() throws Exception { + thrown.expect(IllegalArgumentException.class); + ComputeTransHashSHA2.getHMACSHA512( + "\u8003\u0001\u0000\u0000>\u0000\ubffe\ubffe\ubffe\u0003", + null); + } + + @Test + public void getHMACSHA512InputNullNotNullOutputIllegalArgumentException() throws Exception { + thrown.expect(IllegalArgumentException.class); + ComputeTransHashSHA2.getHMACSHA512( + null, "\u0000\u0000\u0000??????????????????????"); + } + + @Test + public void hexStringToByteArrayInputNotNullOutput0() { + Assert.assertArrayEquals(new byte[] {}, ComputeTransHashSHA2.hexStringToByteArray("")); + } + + @Test + public void hexStringToByteArrayInputNotNullOutputStringIndexOutOfBoundsException() { + thrown.expect(StringIndexOutOfBoundsException.class); + ComputeTransHashSHA2.hexStringToByteArray("/"); + } + + @Test + public void hexStringToByteArrayInputNotNullOutputStringIndexOutOfBoundsException2() { + thrown.expect(StringIndexOutOfBoundsException.class); + ComputeTransHashSHA2.hexStringToByteArray("#\uff77\u0002"); + } +}