summaryrefslogtreecommitdiff
path: root/src/test/java/design/model/GolferTest.java
blob: 98dad208ead8de96e3516299b993b20260784059 (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package design.model;

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

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

import design.model.Club.ClubType;
import design.model.undo.Memento;

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

/** Unit Tests for the Club class.
 * @author Willem Dalton
 **/
@Tag("Model-tier")
public class GolferTest {
    
    @Test
    void testConstructor()
    {
        Golfer testGolfer = new Golfer("John Doe", "jdoesgolf2", "weback4321");
        assertEquals("John Doe", testGolfer.getFullName());
        assertEquals("jdoesgolf2", testGolfer.getUsername());
        assertTrue(testGolfer.checkPassword("weback4321"));
    }

    @Test
    void testPrivateConstructor() throws Exception
    {
        Constructor<Golfer> constructor = Golfer.class.getDeclaredConstructor(String.class, int.class, String.class, List.class, List.class, List.class);
        assertTrue(Modifier.isPrivate(constructor.getModifiers()));
        constructor.setAccessible(true);
        Golfer testGolfer = constructor.newInstance("testUser", 12345, "Test Golfer", new ArrayList<>(), new ArrayList<>(), new ArrayList<>());
        assertNotNull(testGolfer);
    }

    @Test
    void testSetUserName()
    {
        Golfer testGolfer = new Golfer("John Doe", "jdoesgolf2", "weback4321");
        testGolfer.setUsername("jquitgolf2");
        assertEquals("jquitgolf2", testGolfer.getUsername());
    }

    @Test
    void testSetFullName()
    {
        Golfer testGolfer = new Golfer("John Doe", "jdoesgolf2", "weback4321");
        testGolfer.setFullName("John Joe");
        assertEquals("John Joe", testGolfer.getFullName());
    }

    @Test
    void testSetPassword()
    {
        Golfer testGolfer = new Golfer("John Doe", "jdoesgolf2", "weback4321");
        testGolfer.setPassword("lifeisroblox1234");
        assertTrue(testGolfer.checkPassword("lifeisroblox1234"));
    }

    @Test
    void testWrongPassword()
    {
        Golfer testGolfer = new Golfer("John Doe", "jdoesgolf2", "weback4321");
        assertFalse(testGolfer.checkPassword("lifeisroblox1234"));
    }

    @Test
    void testAddCourse()
    {
        Golfer testGolfer = new Golfer("John Doe", "jdoesgolf2", "weback4321");
        Course exampleCourse = new Course(0, "Rolling Hills", 68, "Rochester, NY", 9, 30, new ArrayList<Hole>());
        testGolfer.addCourse(exampleCourse);
        assertEquals(exampleCourse, testGolfer.getCourses()[0]);
        assertTrue(testGolfer.hasCourses());
    }

    @Test
    void testRemoveCourse()
    {
        Golfer testGolfer = new Golfer("John Doe", "jdoesgolf2", "weback4321");
        Course exampleCourse = new Course(0, "Rolling Hills", 68, "Rochester, NY", 9, 30, new ArrayList<Hole>());
        testGolfer.addCourse(exampleCourse);
        testGolfer.removeCourse(exampleCourse);
        assertFalse(testGolfer.hasCourses());
    }
    
    @Test
    void testRounds()
    {
        Golfer testGolfer = new Golfer("John Doe", "jdoesgolf2", "weback4321");
        Course exampleCourse = new Course(0, "Rolling Hills", 68, "Rochester, NY", 9, 30, new ArrayList<Hole>());
        Round exampleRound = new Round(exampleCourse, LocalDateTime.MAX, new Hole(0, 3));
        testGolfer.addRound(exampleRound);
        assertEquals(exampleRound, testGolfer.getRounds()[0]);
    }

    @Test
    void testAddClub()
    {
        Golfer testGolfer = new Golfer("John Doe", "jdoesgolf2", "weback4321");

        Club c = new Club("John Doe", "The Slammer", ClubType.DRIVER);
        testGolfer.addClub(c);
        Club addedClub = testGolfer.getClubs()[0];
        assertTrue(testGolfer.hasClub(addedClub));
        assertTrue(testGolfer.hasClubs());
    }

    @Test
    void testRemoveClub()
    {
        Golfer testGolfer = new Golfer("John Doe", "jdoesgolf2", "weback4321");

        Club c = new Club("John Doe", "The Slammer", ClubType.DRIVER);
        testGolfer.addClub(c);
        Club addedClub = testGolfer.getClubs()[0];
        testGolfer.removeClub(addedClub);
        assertFalse(testGolfer.hasClub(addedClub));
        assertFalse(testGolfer.hasClubs());

    }

    @Test
    void testToString()
    {
        Golfer testGolfer = new Golfer("John Doe", "jdoesgolf2", "weback4321");
        String expectedString = "John Doe (@jdoesgolf2)";
        assertEquals(expectedString, testGolfer.toString());
    }

    @Test
    void testMemento()
    {
        Golfer testGolfer = new Golfer("John Doe", "jdoesgolf2", "weback4321");
        Memento memento = testGolfer.createMemento();
        testGolfer.setFullName("Joe Doe");
        assertEquals("Joe Doe", testGolfer.getFullName());
        testGolfer.restore(memento);
        assertEquals("John Doe", testGolfer.getFullName());
    }


}