package com.maxmind.minfraud.request;

import com.maxmind.minfraud.request.Email.Builder;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class EmailTest {

    @Test
    public void testAddress() throws Exception {
        Email email = new Builder().address("test@test.org").build();
        assertEquals("raw email", "test@test.org", email.getAddress());
        assertEquals("domain set from email", "test.org", email.getDomain());
        assertEquals("MD5 getter works", "476869598e748d958e819c180af31982", email.getAddressMd5());
    }

    @Test
    public void testAddressMd5() throws Exception {
        Email email = new Builder().address("test@test.org").hashAddress().build();
        assertEquals("MD5 generated from email", "476869598e748d958e819c180af31982", email.getAddress());
        assertEquals("domain set from email", "test.org", email.getDomain());
        assertEquals("MD5 getter works", "476869598e748d958e819c180af31982", email.getAddressMd5());
    }

    @Test
    public void testAddressMd5MultipleTimes() throws Exception {
        Email email = new Builder().address("test@test.org").hashAddress().hashAddress().build();
        assertEquals("MD5 generated from email", "476869598e748d958e819c180af31982", email.getAddress());
        assertEquals("domain set from email", "test.org", email.getDomain());
        assertEquals("MD5 getter works", "476869598e748d958e819c180af31982", email.getAddressMd5());
    }

    @Test
    public void testHashAddressWithoutAddress() throws Exception {
        Email email = new Builder().domain("test.org").hashAddress().build();
        assertEquals("domain is set", "test.org", email.getDomain());
    }

    @Test
    public void testMd5GetsLowercased() throws Exception {
        Email email = new Builder().address("TEST@TEST.org").hashAddress().build();
        assertEquals("MD5 generated from lowercased email", "476869598e748d958e819c180af31982", email.getAddress());
        assertEquals("MD5 generated from lowercased email", "476869598e748d958e819c180af31982", email.getAddressMd5());
    }

    @Test
    public void testGetAddressWithoutSettingIt() throws Exception {
        Email email = new Builder().domain("test.org").hashAddress().build();
        assertEquals("null address if none set", null, email.getAddress());
        assertEquals("null addressMd5 if none set", null, email.getAddressMd5());

        Email email2 = new Builder().domain("test.org").hashAddress().build();
        assertEquals("null address if none set", null, email2.getAddress());
        assertEquals("null addressMd5 if none set", null, email2.getAddressMd5());
    }

    @Test(expected = IllegalArgumentException.class)
    public void testInvalidAddress() throws Exception {
        new Builder().address("a@test@test.org").build();
    }

    @Test
    public void testDomain() throws Exception {
        String domain = "domain.com";
        Email email = new Builder().domain(domain).build();
        assertEquals(domain, email.getDomain());
    }

    @Test(expected = IllegalArgumentException.class)
    public void testInvalidDomain() throws Exception {
        new Builder().domain(" domain.com").build();
    }
}

@@ -151,16 +151,59 @@
 tEquals;
+%0Aimport static org.junit.Assert.assertNull;
 %0A%0Apublic
@@ -2303,38 +2303,36 @@
 ;%0A        assert
-Equals
+Null
 (%22null address i
@@ -2335,38 +2335,32 @@
 ss if none set%22,
- null,
  email.getAddres
@@ -2371,38 +2371,36 @@
 ;%0A        assert
-Equals
+Null
 (%22null addressMd
@@ -2410,30 +2410,24 @@
 f none set%22,
- null,
  email.getAd
@@ -2525,38 +2525,36 @@
 ;%0A        assert
-Equals
+Null
 (%22null address i
@@ -2557,38 +2557,32 @@
 ss if none set%22,
- null,
  email2.getAddre
@@ -2602,22 +2602,20 @@
   assert
-Equals
+Null
 (%22null a
@@ -2641,14 +2641,8 @@
 et%22,
- null,
  ema

Use assertNull when appropriate