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
|
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.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import design.model.Club.ClubType;
/** Unit Tests for the Club class.
* @author Willem Dalton
**/
@Tag("Model-tier")
public class ClubTest {
@Test
void testConstructor()
{
Club testClub = new Club("John Doe", "The Slammer", ClubType.DRIVER);
assertEquals(-1, testClub.getId());
assertEquals("John Doe", testClub.getManufacture());
assertEquals("The Slammer", testClub.getNickname());
assertEquals(ClubType.DRIVER, testClub.getClubType());
}
@Test
void testPrivateConstructor() throws Exception
{
Constructor<Club> constructor = Club.class.getDeclaredConstructor(int.class, String.class, String.class, ClubType.class);
assertTrue(Modifier.isPrivate(constructor.getModifiers()));
constructor.setAccessible(true);
Club testClub = constructor.newInstance(0, "John Doe", "The Slammer", ClubType.DRIVER);
assertNotNull(testClub);
}
@Test
void testGetClubType()
{
Club testClub = new Club("John Doe", "The Slammer", ClubType.DRIVER);
assertEquals(ClubType.DRIVER, testClub.getClubType());
}
@Test
void testGetNickname()
{
Club testClub = new Club("John Doe", "The Slammer", ClubType.DRIVER);
assertEquals("The Slammer", testClub.getNickname());
}
@Test
void testGetManufacture()
{
Club testClub = new Club("John Doe", "The Slammer", ClubType.DRIVER);
assertEquals("John Doe", testClub.getManufacture());
}
@Test
void testGetId()
{
Club testClub = new Club("John Doe", "The Slammer", ClubType.DRIVER);
assertEquals(-1, testClub.getId());
}
@Test
void testSetId()
{
Club testClub = new Club("John Doe", "The Slammer", ClubType.DRIVER);
testClub.setId(10);
assertThrows(AssertionError.class, () -> testClub.setId(5));
}
@Test
void testToString()
{
Club testClub = new Club("John Doe", "The Slammer", ClubType.DRIVER);
String expectedString = "#-1 The Slammer - John Doe (DRIVER)";
assertEquals(expectedString, testClub.toString());
}
}
|