package com.wizzardo.tools.security;

import org.junit.Assert;
import org.junit.Test;

/**
 * Created by wizzardo on 15.03.15.
 */
public class HashTest {

    @Test
    public void md5_test() {
        String data = "foo bar\n";
        Assert.assertEquals("5ceaa7ed396ccb8e959c02753cb4bd18", MD5.create().update(data).asString());
    }

    @Test
    public void sha1_test() {
        String data = "foo bar\n";
        Assert.assertEquals("d53a205a336e07cf9eac45471b3870f9489288ec", SHA1.create().update(data).asString());
    }
}

@@ -80,16 +80,157 @@
 .Test;%0A%0A
+import java.io.ByteArrayInputStream;%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.security.NoSuchAlgorithmException;%0A%0A
 /**%0A * C
@@ -666,11 +666,1504 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void hash_test() throws IOException %7B%0A        String data = %22foo bar%5Cn%22;%0A        Assert.assertTrue(MD5.create().check(data, %225ceaa7ed396ccb8e959c02753cb4bd18%22));%0A%0A        byte%5B%5D hash = new byte%5B%5D%7B92, -22, -89, -19, 57, 108, -53, -114, -107, -100, 2, 117, 60, -76, -67, 24%7D;%0A        Assert.assertTrue(MD5.create().check(data.getBytes(%22utf-8%22), hash));%0A%0A%0A        MD5 md5 = MD5.create();%0A        md5.update(data);%0A        md5.update(data);%0A        Assert.assertNotEquals(%225ceaa7ed396ccb8e959c02753cb4bd18%22, md5.toString());%0A        md5.reset();%0A        md5.update(data);%0A        Assert.assertEquals(%225ceaa7ed396ccb8e959c02753cb4bd18%22, md5.toString());%0A%0A        InputStream in = new ByteArrayInputStream(data.getBytes(%22utf-8%22));%0A        Assert.assertEquals(%225ceaa7ed396ccb8e959c02753cb4bd18%22, MD5.create().update(in).asString());%0A%0A        byte%5B%5D bytes = data.getBytes(%22utf-8%22);%0A        md5 = MD5.create();%0A        for (byte b : bytes) %7B%0A            md5.update(b);%0A        %7D%0A        Assert.assertEquals(%225ceaa7ed396ccb8e959c02753cb4bd18%22, md5.toString());%0A%0A        boolean exception = false;%0A        try %7B%0A            new Hash(%22some hash%22) %7B%0A                @Override%0A                protected int hexStringLength() %7B%0A                    return 0;%0A                %7D%0A            %7D;%0A        %7D catch (Exception e) %7B%0A            exception = true;%0A            Assert.assertEquals(NoSuchAlgorithmException.class, e.getClass());%0A        %7D%0A        Assert.assertTrue(exception);%0A    %7D
 %0A%7D%0A

improve test