summaryrefslogtreecommitdiff
path: root/src/test/java/design/model/RoundTest.java
blob: 76d8f479d01e204d132e0a3ed6a5164fe0f306ca (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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 design.model.Club.ClubType;

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

/** Unit Tests for the Round class.
 * @author Willem Dalton
 **/
@Tag("Model-tier")
public class RoundTest {
    
    @Test
    void testConstructor()
    {
        Course testCourse = new Course(0, "Rolling Waves", 62, "Rochester, NY", 9, 20, new ArrayList<Hole>());
        LocalDateTime testTime = LocalDateTime.now();
        Hole testHole = new Hole(0,3);
        Round testRound = new Round(testCourse, testTime, testHole);
        assertEquals(testCourse, testRound.getCourse());
        assertEquals(testTime, testRound.getDateTime());
        assertEquals(testHole, testRound.getStartingHole());
    }

    @Test
    void testPrivateConstructor() throws Exception
    {
        Course testCourse = new Course(0, "Rolling Waves", 62, "Rochester, NY", 9, 20, new ArrayList<Hole>());
        Constructor<Round> constructor = Round.class.getDeclaredConstructor(Course.class, LocalDateTime.class, Hole.class, List.class);
        assertTrue(Modifier.isPrivate(constructor.getModifiers()));
        constructor.setAccessible(true);
        Round testRound = constructor.newInstance(testCourse, LocalDateTime.now(), new Hole(0, 0), new ArrayList<Play>());
        assertNotNull(testRound);
    }


    @Test
    void testHolePlay()
    {
        Course testCourse = new Course(0, "Rolling Waves", 62, "Rochester, NY", 9, 20, new ArrayList<Hole>());
        LocalDateTime testTime = LocalDateTime.now();
        Hole testHole = new Hole(0,3);
        Round testRound = new Round(testCourse, testTime, testHole);
        Play testPlay = new Play(0);

        testRound.addPlay(testPlay);

        assertEquals(1, testRound.getPlays().length);
        assertEquals(testPlay, testRound.getPlays()[0]);
        assertEquals(0, testRound.getTotalSwings());

        Club newClub = new Club("John Doe Inc", "The Slammer", ClubType.DRIVER);
        Swing newSwing = new Swing(200, newClub);
        
        // try swinging, expect to see another swing added.
        testPlay.addSwing(newSwing);

        assertEquals(1, testRound.getTotalSwings());
        assertEquals(200, testRound.getTotalDistance());
    } 

    @Test
    void testProgressHole()
    {
        Hole testHole = new Hole(0,3);
        Hole nextHole = new Hole(1, 5);

        ArrayList<Hole> testHoles = new ArrayList<Hole>();
        testHoles.add(testHole);
        testHoles.add(nextHole);

        Course testCourse = new Course(0, "Rolling Waves", 62, "Rochester, NY", 9, 20, testHoles);
        LocalDateTime testTime = LocalDateTime.now();
        Round testRound = new Round(testCourse, testTime, testHole);
        
        // progress a Hole and check value.
        assertEquals(testHole, testRound.getCurrentHole());
        testRound.nextHole();
        assertEquals(nextHole, testRound.getCurrentHole());
    }
}