Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding unit tests for net.authorize.sample.Sha512.ComputeTransHashS512 #91

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
<artifactId>junit</artifactId>
<version>4.8.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
}
}