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
|
package design.model;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
/** Tests for the scramble league model class.
* @author Willem Dalton
*/
@Tag("Model-tier")
public class ScrambleLeagueTest {
@Test
void testConstructor()
{
Date testStart = new Date(1234567);
Date testRegistration = new Date(1234568);
Date testEnd = new Date(12345679);
Golfer testOwner = new Golfer("Bobby", "bobby123", "iloveswen262");
ScrambleLeague testLeague = new ScrambleLeague("Bobby's Band", testRegistration, testStart, testEnd, testOwner);
assertEquals(-1, testLeague.getId());
assertEquals("Bobby's Band", testLeague.getName());
assertEquals(testRegistration, testLeague.getRegistrationDate());
assertEquals(testStart, testLeague.getStartDate());
assertEquals(testEnd, testLeague.getEndDate());
assertEquals(testOwner, testLeague.getOwner());
}
@Test
void testPrivateConstructor() throws Exception
{
Golfer testOwner = new Golfer("Bobby", "bobby123", "iloveswen262");
Constructor<ScrambleLeague> constructor = ScrambleLeague.class.getDeclaredConstructor(int.class, String.class, Date.class, Date.class, Date.class, Golfer.class, List.class, List.class);
assertTrue(Modifier.isPrivate(constructor.getModifiers()));
constructor.setAccessible(true);
ScrambleLeague testLeague = constructor.newInstance(1, "Bobby's Band", new Date(), new Date(), new Date(), testOwner, new ArrayList<Team>(), new ArrayList<Match>());
assertNotNull(testLeague);
}
@Test
void testParticipants() throws Exception
{
Date testStart = new Date(1234567);
Date testRegistration = new Date(1234568);
Date testEnd = new Date(12345679);
Golfer testOwner = new Golfer("Bobby", "bobby123", "iloveswen262");
ScrambleLeague testLeague = new ScrambleLeague("Bobby's Band", testRegistration, testStart, testEnd, testOwner);
Team testTeam = new Team("The A Team", testOwner);
// add and remove participant
testLeague.addParticipants(testTeam);
assertEquals(testTeam, testLeague.getParticipants()[0]);
assertEquals(1, testLeague.getParticipants().length);
testLeague.removeParticipants(testTeam);
assertEquals(0, testLeague.getParticipants().length);
}
@Test
void testLocateTeam() throws Exception
{
Date testStart = new Date(1234567);
Date testRegistration = new Date(1234568);
Date testEnd = new Date(12345679);
Golfer testOwner = new Golfer("Bobby", "bobby123", "iloveswen262");
ScrambleLeague testLeague = new ScrambleLeague("Bobby's Band", testRegistration, testStart, testEnd, testOwner);
Team testTeam = new Team("The A Team", testOwner);
Golfer teamMember = new Golfer("Jane Doe", "jane_doe", "weback");
Golfer nonMember = new Golfer("NAN doe", "nan_doe", "wenotback");
// expect a result if member is part of team. expect null if they are not.
testTeam.addMember(teamMember);
testLeague.addParticipants(testTeam);
Team result = testLeague.locateTeam(teamMember);
assertEquals(result, testTeam);
result = testLeague.locateTeam(nonMember);
assertNull(result);
}
}
|