1.1 --- a/samples/messagedigest/test/api/NewAPIToOldAPITest.java Sat Jun 14 10:32:31 2008 +0200
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,64 +0,0 @@
1.4 -/*
1.5 - * To change this template, choose Tools | Templates
1.6 - * and open the template in the editor.
1.7 - */
1.8 -
1.9 -package api;
1.10 -
1.11 -import java.nio.ByteBuffer;
1.12 -import java.security.MessageDigest;
1.13 -import java.util.Arrays;
1.14 -import java.util.Random;
1.15 -import org.junit.After;
1.16 -import org.junit.BeforeClass;
1.17 -import org.junit.Test;
1.18 -import static org.junit.Assert.*;
1.19 -
1.20 -/** Compares that the MessageDigest and Digest yield the same results for
1.21 - * default provider.
1.22 - *
1.23 - * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
1.24 - */
1.25 -public class NewAPIToOldAPITest {
1.26 - private static byte[] arr;
1.27 - private static long time;
1.28 - private static byte[] resOld;
1.29 - private static byte[] resNew;
1.30 -
1.31 - public NewAPIToOldAPITest() {
1.32 - }
1.33 -
1.34 - @BeforeClass
1.35 - public static void setUp() {
1.36 - time = System.currentTimeMillis();
1.37 - Random r = new Random(time);
1.38 - arr = new byte[r.nextInt(1024)];
1.39 - r.nextBytes(arr);
1.40 - }
1.41 -
1.42 - @After
1.43 - public void tearDown() {
1.44 - }
1.45 -
1.46 - @Test
1.47 - public void generateHashUsingMessageDigest() throws Exception {
1.48 - MessageDigest md = MessageDigest.getInstance("MD5");
1.49 - byte[] res = md.digest(arr);
1.50 - resOld = res;
1.51 - }
1.52 -
1.53 - @Test
1.54 - public void generateHashUsingNewDigest() throws Exception {
1.55 - Digest d = Digest.getInstance("MD5");
1.56 - ByteBuffer bb = ByteBuffer.wrap(arr);
1.57 - byte[] res = d.digest(bb);
1.58 - resNew = res;
1.59 - }
1.60 -
1.61 - @Test
1.62 - public void compareTheHashes() throws Exception {
1.63 - if (!Arrays.equals(resOld, resNew)) {
1.64 - fail("Arrays are different:\n" + Arrays.toString(resOld) + "\n" + Arrays.toString(resNew));
1.65 - }
1.66 - }
1.67 -}
1.68 \ No newline at end of file