package nl.jft.logic.match;

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

import java.time.LocalDateTime;

import static org.junit.Assert.*;

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

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

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

        Participant participant = LogicTestUtil.makeDefaultUser();
        Goal goal = LogicTestUtil.makeGoal(participant, null);
    }

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

        Participant participant = LogicTestUtil.makeDefaultUser();
        Goal goal = LogicTestUtil.makeGoal(LogicConstants.INTERNAL_ID, participant, null);
    }

    @Test
    public void equals_sameObjects_returnsTrue() {
        Goal goal1 = LogicTestUtil.makeGoalWithUser();
        Goal goal2 = LogicTestUtil.makeGoalWithUser();

        boolean result = goal1.equals(goal2);
        assertTrue(result);
    }

    @Test
    public void equals_otherGoal_returnsFalse() throws Exception {
        Goal goal1 = LogicTestUtil.makeGoalWithUser();
        Goal goal2 = LogicTestUtil.makeGoalWithTeam();

        boolean result = goal1.equals(goal2);
        assertFalse(result);
    }

    @Test
    public void equals_otherObject_returnsFalse() {
        Goal goal1 = LogicTestUtil.makeGoalWithUser();
        String goal2 = "goal2";

        boolean result = goal1.equals(goal2);
        assertFalse(result);
    }

    @Test
    public void equals_nullObject_returnsFalse() {
        Goal goal1 = LogicTestUtil.makeGoalWithUser();
        Goal goal2 = null;

        boolean result = goal1.equals(goal2);
        assertFalse(result);
    }

    @Test
    public void hashCode_whenCalled_returnsHashCode() {
        Goal goal1 = LogicTestUtil.makeGoalWithTeam();
        Goal goal2 = LogicTestUtil.makeGoalWithTeam();

        boolean result = goal1.hashCode() == goal2.hashCode();
        assertTrue(result);
    }

    @Test
    public void getId_whenCalled_returnsId() {
        Goal goal = LogicTestUtil.makeGoalWithUser(); // Default id = 0.

        int expected = LogicConstants.INTERNAL_ID;
        int actual = goal.getId();

        assertEquals(expected, actual);
    }

    @Test
    public void getParticipant_nullParticipant_returnsNull() {
        Goal goal = LogicTestUtil.makeGoalNoParticipant();

        Participant expected = null;
        Participant actual = goal.getParticipant();

        assertEquals(expected, actual);
    }

    @Test
    public void getParticipant_userParticipant_returnsUser() {
        Goal goal = LogicTestUtil.makeGoalWithUser();

        Participant expected = LogicTestUtil.makeDefaultUser();
        Participant actual = goal.getParticipant();

        assertEquals(expected, actual);
    }

    @Test
    public void getParticipant_teamParticipant_returnsTeam() {
        Goal goal = LogicTestUtil.makeGoalWithTeam();

        Participant expected = LogicTestUtil.makeDefaultTeam();
        Participant actual = goal.getParticipant();

        assertEquals(expected, actual);
    }

    @Test
    public void getTime_whenCalled_returnsTime() {
        Goal goal = LogicTestUtil.makeGoalNoParticipant();

        LocalDateTime expected = LogicTestUtil.makeDefaultLocalDateTime();
        LocalDateTime actual = goal.getTime();

        assertEquals(expected, actual);
    }

}
@@ -1105,36 +1105,36 @@
 til.makeGoalWith
-User
+Team
 ();%0A        Goal
@@ -1160,36 +1160,36 @@
 til.makeGoalWith
-User
+Team
 ();%0A%0A        boo
@@ -1296,20 +1296,24 @@
 ls_other
-Goal
+Instance
 _returns
@@ -1324,24 +1324,243 @@
 e() 
-throws Exception
+%7B%0A        Goal goal1 = LogicTestUtil.makeGoalWithTeam();%0A        Goal goal2 = null;%0A%0A        boolean result = goal1.equals(goal2);%0A        assertFalse(result);%0A    %7D%0A%0A    @Test%0A    public void equals_nullFirstParticipant_returnsFalse()
  %7B%0A 
@@ -1597,34 +1597,72 @@
 til.makeGoal
-WithUser
+(null, LogicTestUtil.makeDefaultLocalDateTime
 ()
+)
 ;%0A        Go
@@ -1690,36 +1690,36 @@
 til.makeGoalWith
-Team
+User
 ();%0A%0A        boo
@@ -1826,18 +1826,28 @@
 als_
-otherObjec
+nullSecondParticipan
 t_re
@@ -1928,256 +1928,1221 @@
     
-String goal2 = %22goal2%22;%0A%0A        boolean result = goal1.equals(goal2);%0A        assertFalse(result);%0A    %7D%0A%0A    @Test%0A    public void equals_nullObject_returnsFalse() %7B%0A        Goal goal1 = LogicTestUtil.makeGoalWithUser();%0A        Goal goal2 = null
+Goal goal2 = LogicTestUtil.makeGoal(null, LogicTestUtil.makeDefaultLocalDateTime());%0A%0A        boolean result = goal1.equals(goal2);%0A        assertFalse(result);%0A    %7D%0A%0A    @Test%0A    public void equals_differentIds_returnsFalse() %7B%0A        Goal goal1 = LogicTestUtil.makeGoal(1, LogicTestUtil.makeDefaultUser(), LogicTestUtil.makeDefaultLocalDateTime());%0A        Goal goal2 = LogicTestUtil.makeGoal(2, LogicTestUtil.makeDefaultUser(), LogicTestUtil.makeDefaultLocalDateTime());%0A%0A        boolean result = goal1.equals(goal2);%0A        assertFalse(result);%0A    %7D%0A%0A    @Test%0A    public void equals_differentParticipants_returnsFalse() %7B%0A        Goal goal1 = LogicTestUtil.makeGoal(LogicTestUtil.makeDefaultUser(), LogicTestUtil.makeDefaultLocalDateTime());%0A        Goal goal2 = LogicTestUtil.makeGoal(LogicTestUtil.makeDefaultUser2(), LogicTestUtil.makeDefaultLocalDateTime());%0A%0A        boolean result = goal1.equals(goal2);%0A        assertFalse(result);%0A    %7D%0A%0A    @Test%0A    public void equals_differentTimes_returnsFalse() %7B%0A        Goal goal1 = LogicTestUtil.makeGoal(LogicTestUtil.makeDefaultUser(), LocalDateTime.MIN);%0A        Goal goal2 = LogicTestUtil.makeGoal(LogicTestUtil.makeDefaultUser(), LocalDateTime.MAX)
 ;%0A%0A 

Add all paths in equals in Goal.