package ee.shy.storage;

import org.junit.Test;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import static org.junit.Assert.assertEquals;

public class HashTest {
    @Test(expected = IllegalArgumentException.class)
    public void testConstructorIllegalSize() {
        new Hash("1234");
    }

    @Test(expected = IllegalArgumentException.class)
    public void testConstructorIllegalParity() {
        new Hash("123");
    }

    @Test(expected = IllegalArgumentException.class)
    public void testConstructorIllegalHexChar() {
        new Hash("foo");
    }

    @Test
    public void testZero() {
        assertEquals("0000000000000000000000000000000000000000", Hash.ZERO.toString());
    }

    @Test
    public void testString() {
        assertEquals("0000000000000000000000000000000000000000", new Hash("0000000000000000000000000000000000000000").toString());
        assertEquals("2fd4e1c67a2d28fced849ee1bb76e7391b93eb12", new Hash("2fd4e1c67a2d28fced849ee1bb76e7391b93eb12").toString());
    }

    @Test
    public void testMessageDigest() throws NoSuchAlgorithmException {
        MessageDigest md = MessageDigest.getInstance("SHA-1");
        md.update("The quick brown fox jumps over the lazy dog".getBytes());

        assertEquals("2fd4e1c67a2d28fced849ee1bb76e7391b93eb12", new Hash(md.digest()).toString());
    }

    @Test
    public void testEqualsHashcode() {
        assertEquals(new Hash("2fd4e1c67a2d28fced849ee1bb76e7391b93eb12"), new Hash("2fd4e1c67a2d28fced849ee1bb76e7391b93eb12"));
        assertEquals(new Hash("2fd4e1c67a2d28fced849ee1bb76e7391b93eb12").hashCode(), new Hash("2fd4e1c67a2d28fced849ee1bb76e7391b93eb12").hashCode());
    }
}

@@ -170,16 +170,64 @@
 tEquals;
+%0Aimport static org.junit.Assert.assertNotEquals;
 %0A%0Apublic
@@ -698,32 +698,41 @@
    assertEquals(
+new Hash(
 %22000000000000000
@@ -757,16 +757,17 @@
 0000000%22
+)
 , Hash.Z
@@ -769,27 +769,16 @@
 ash.ZERO
-.toString()
 );%0A    %7D
@@ -809,16 +809,18 @@
 oid test
+To
 String()
@@ -891,60 +891,17 @@
 0%22, 
-new Hash(%220000000000000000000000000000000000000000%22)
+Hash.ZERO
 .toS
@@ -1078,29 +1078,21 @@
 oid test
-MessageDig
+Byt
 es
-t
 () throw
@@ -1274,32 +1274,41 @@
    assertEquals(
+new Hash(
 %222fd4e1c67a2d28f
@@ -1325,32 +1325,33 @@
 b76e7391b93eb12%22
+)
 , new Hash(md.di
@@ -1357,27 +1357,16 @@
 igest())
-.toString()
 );%0A    %7D
@@ -1420,37 +1420,36 @@
 ) %7B%0A        
+H
 as
-sertEquals(
+h hash = 
 new Hash(%222f
@@ -1480,32 +1480,94 @@
 76e7391b93eb12%22)
+;%0A%0A        assertEquals(hash, hash);%0A        assertEquals(hash
 , new Hash(%222fd4
@@ -1625,67 +1625,107 @@
 sert
+Not
 Equals(
-new Hash(%222fd4e1c67a2d28fced849ee1bb76e7391b93eb12%22)
+hash, Hash.ZERO);%0A        assertNotEquals(hash, new Object());%0A%0A        assertEquals(hash
 .has

Increase Hash#equals test coverage