diff options
Diffstat (limited to 'src/test/java/design/model/StrokeLeagueTest.java')
| -rw-r--r-- | src/test/java/design/model/StrokeLeagueTest.java | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/test/java/design/model/StrokeLeagueTest.java b/src/test/java/design/model/StrokeLeagueTest.java new file mode 100644 index 0000000..8af7561 --- /dev/null +++ b/src/test/java/design/model/StrokeLeagueTest.java @@ -0,0 +1,65 @@ +package design.model; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +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 stroke league model class. + * @author Willem Dalton + */ +@Tag("Model-tier") +public class StrokeLeagueTest { + + @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"); + StrokeLeague testLeague = new StrokeLeague("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<StrokeLeague> constructor = StrokeLeague.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); + StrokeLeague testLeague = constructor.newInstance(1, "Bobby's Band", new Date(), new Date(), new Date(), testOwner, new ArrayList<Golfer>(), 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"); + StrokeLeague testLeague = new StrokeLeague("Bobby's Band", testRegistration, testStart, testEnd, testOwner); + + // add and remove participant + testLeague.addParticipants(testOwner); + assertEquals(testOwner, testLeague.getParticipants()[0]); + assertEquals(1, testLeague.getParticipants().length); + testLeague.removeParticipants(testOwner); + assertEquals(0, testLeague.getParticipants().length); + } +} |
