Updating to NBMs from NetBeans 8.0.1 as some of them are required to run on JDK8
3 import java.nio.ByteBuffer;
4 import java.security.MessageDigest;
5 import java.util.Arrays;
6 import java.util.Random;
7 import org.apidesign.api.security.Digest;
8 import org.junit.After;
9 import org.junit.BeforeClass;
10 import org.junit.Test;
11 import static org.junit.Assert.*;
13 /** Compares that the MessageDigest and Digest yield the same results for
16 * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
18 public class NewAPIToOldAPITest {
19 private static byte[] arr;
20 private static long time;
21 private static byte[] resOld;
22 private static byte[] resNew;
24 public NewAPIToOldAPITest() {
28 public static void setUp() {
29 time = System.currentTimeMillis();
30 Random r = new Random(time);
31 arr = new byte[r.nextInt(1024)];
36 public void tearDown() {
40 public void generateHashUsingMessageDigest() throws Exception {
41 MessageDigest md = MessageDigest.getInstance("MD5");
42 byte[] res = md.digest(arr);
47 public void generateHashUsingNewDigest() throws Exception {
48 if (Boolean.getBoolean("no.failures") && Boolean.getBoolean("no.md5")) return;
49 Digest d = Digest.getInstance("MD5");
50 ByteBuffer bb = ByteBuffer.wrap(arr);
51 byte[] res = d.digest(bb);
56 public void compareTheHashes() throws Exception {
57 if (Boolean.getBoolean("no.failures") && Boolean.getBoolean("no.md5")) return;
58 if (!Arrays.equals(resOld, resNew)) {
59 fail("Arrays are different:\n" + Arrays.toString(resOld) + "\n" + Arrays.toString(resNew));