summaryrefslogtreecommitdiff
path: root/src/test/java/design/model/MatchTest.java
blob: 90582180c41ee26b723dbc86cc6b227dcab1aa89 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package design.model;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.util.Date;
import java.time.LocalDateTime;

/** Unit Tests for the Match class.
 * @author Willem Dalton
 **/
@Tag("Model-tier")
public class MatchTest {
    
    @Test
    void testConstructor()
    {
        Course testCourse = new Course(0, "Rolling Waves", 67, "Rochester. NY", 9, 30, new ArrayList<Hole>());
        Date testDate = new Date(1234567);
        LocalDateTime now = LocalDateTime.now();
        Match testMatch = new Match(testCourse, testDate, now, 9);
        assertEquals(testCourse, testMatch.getCourse());
        assertEquals(testDate, testMatch.getDateScheduled());
        assertEquals(now, testMatch.getStart());
        assertEquals(9, testMatch.getHoleCount());
    }

    @Test
    void testPrivateConstructor() throws Exception
    {
        Course testCourse = new Course(0, "Rolling Waves", 67, "Rochester. NY", 9, 30, new ArrayList<Hole>());
        Constructor<Match> constructor = Match.class.getDeclaredConstructor(Course.class, Date.class, LocalDateTime.class, int.class, List.class);
        assertTrue(Modifier.isPrivate(constructor.getModifiers()));
        constructor.setAccessible(true);
        Match testMatch = constructor.newInstance(testCourse, new Date(1234), LocalDateTime.now(), 0, new ArrayList<>());
        assertNotNull(testMatch);
    }

    @Test
    void testAddRound()
    {
        Course testCourse = new Course(0, "Rolling Waves", 67, "Rochester. NY", 9, 30, new ArrayList<Hole>());
        Date testDate = new Date(1234567);
        LocalDateTime now = LocalDateTime.now();
        Match testMatch = new Match(testCourse, testDate, now, 9);
        Round testRound = new Round(testCourse, now, new Hole(0, 5));
        testMatch.addRound(testRound);
        assertEquals(testRound, testMatch.getRounds()[0]);
        assertEquals(1, testMatch.getRounds().length);
    }
}