package nl.jft.logic.participant.impl;

import nl.jft.logic.util.LogicTestUtil;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import static org.junit.Assert.*;

/**
 * @author Lesley
 */
public class UserTest {

    @Rule
    public final ExpectedException expectedException = ExpectedException.none();

    @Test
    public void construct_nullUsername_throwsException() {
        expectedException.expect(NullPointerException.class);

        User user = LogicTestUtil.makeUser(-1, null);
    }

    @Test
    public void construct_emptyUsername_throwsException() {
        expectedException.expect(IllegalArgumentException.class);

        User user = LogicTestUtil.makeUser(-1, "");
    }

    @Test
    public void equals_sameObjects_returnsTrue() {
        User user1 = LogicTestUtil.makeDefaultUser();
        User user2 = LogicTestUtil.makeDefaultUser();

        assertTrue(user1.equals(user2));
    }

    @Test
    public void equals_otherUser_returnsFalse() throws Exception {
        User user1 = LogicTestUtil.makeDefaultUser();
        User user2 = LogicTestUtil.makeUser(-1, "Henk");

        assertFalse(user1.equals(user2));
    }

    @Test
    public void equals_otherObject_returnsFalse() {
        User user1 = LogicTestUtil.makeDefaultUser();
        String user2 = "user2";

        assertFalse(user1.equals(user2));
    }

    @Test
    public void equals_nullObject_returnsFalse() {
        User user1 = LogicTestUtil.makeDefaultUser();
        User user2 = null;

        assertFalse(user1.equals(user2));
    }

    @Test
    public void hashCode_whenCalled_returnsHashCode() {
        User user1 = LogicTestUtil.makeDefaultUser();
        User user2 = LogicTestUtil.makeDefaultUser();

        boolean result = user1.hashCode() == user2.hashCode();
        assertTrue(result);
    }

    @Test
    public void getUsername_whenCalled_returnsUsername() {
        User user = LogicTestUtil.makeDefaultUser(); // Default username = "username".

        String expected = "username";
        String actual = user.getName();

        assertEquals(expected, actual);
    }

    @Test
    public void getId_whenCalled_returnsId() throws Exception {
        User user = LogicTestUtil.makeDefaultUser(); //Default id = -1.

        int expected = -1;
        int actual = user.getId();

        assertEquals(expected, actual);
    }
}

@@ -907,27 +907,33 @@
         
-assertTrue(
+boolean result = 
 user1.eq
@@ -935,32 +935,59 @@
 r1.equals(user2)
+;%0A        assertTrue(result
 );%0A    %7D%0A%0A    @T
@@ -1173,36 +1173,41 @@
 );%0A%0A        
-assertFalse(
+boolean result = 
 user1.equals
@@ -1205,32 +1205,60 @@
 r1.equals(user2)
+;%0A        assertFalse(result
 );%0A    %7D%0A%0A    @T
@@ -1404,36 +1404,41 @@
 %22;%0A%0A        
-assertFalse(
+boolean result = 
 user1.equals
@@ -1436,32 +1436,60 @@
 r1.equals(user2)
+;%0A        assertFalse(result
 );%0A    %7D%0A%0A    @T
@@ -1633,28 +1633,33 @@
         
-assertFalse(
+boolean result = 
 user1.eq
@@ -1669,16 +1669,44 @@
 s(user2)
+;%0A        assertFalse(result
 );%0A    %7D
@@ -2519,10 +2519,11 @@
 ;%0A    %7D%0A
+%0A
 %7D%0A

Refactor tests in UserTest.