diff options
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/design/model/ClubTest.java | 25 | ||||
| -rw-r--r-- | src/test/java/design/model/HoleTest.java | 55 | ||||
| -rw-r--r-- | src/test/java/design/model/RoundTest.java | 50 | ||||
| -rw-r--r-- | src/test/java/design/model/StrokeLeagueTest.java | 66 |
4 files changed, 196 insertions, 0 deletions
diff --git a/src/test/java/design/model/ClubTest.java b/src/test/java/design/model/ClubTest.java index f73f322..f47405f 100644 --- a/src/test/java/design/model/ClubTest.java +++ b/src/test/java/design/model/ClubTest.java @@ -1,6 +1,13 @@ 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; @@ -24,6 +31,16 @@ public class ClubTest { } @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); @@ -52,6 +69,14 @@ public class ClubTest { } @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); diff --git a/src/test/java/design/model/HoleTest.java b/src/test/java/design/model/HoleTest.java new file mode 100644 index 0000000..58aff49 --- /dev/null +++ b/src/test/java/design/model/HoleTest.java @@ -0,0 +1,55 @@ +package design.model; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +/** Tests for the hole model class. + * @author Willem Dalton + */ +@Tag("Model-tier") +public class HoleTest { + + @Test + void testValidEquals() + { + Hole hole1 = new Hole(0, 10); + Hole hole2 = new Hole(0, 10); + assertTrue(hole1.equals(hole2)); + } + + @Test + void testNotAHole() + { + Hole hole1 = new Hole(0, 10); + String notAHole = "ImNotAHole!"; + assertFalse(hole1.equals(notAHole)); + } + + @Test + void testNotEquals() + { + Hole hole1 = new Hole(0, 10); + Hole hole2 = new Hole(10, 999); + assertFalse(hole1.equals(hole2)); + } + + @Test + void testNotEqualPar() + { + Hole hole1 = new Hole(0, 10); + Hole hole2 = new Hole(0, 999); + assertFalse(hole1.equals(hole2)); + } + + @Test + void testNotEqualNumber() + { + Hole hole1 = new Hole(0, 10); + Hole hole2 = new Hole(10, 10); + assertFalse(hole1.equals(hole2)); + } +} + diff --git a/src/test/java/design/model/RoundTest.java b/src/test/java/design/model/RoundTest.java index d472f5b..76d8f47 100644 --- a/src/test/java/design/model/RoundTest.java +++ b/src/test/java/design/model/RoundTest.java @@ -1,12 +1,19 @@ 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 @@ -27,6 +34,18 @@ public class RoundTest { } @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>()); @@ -36,7 +55,38 @@ public class RoundTest { 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()); } } diff --git a/src/test/java/design/model/StrokeLeagueTest.java b/src/test/java/design/model/StrokeLeagueTest.java new file mode 100644 index 0000000..cc37887 --- /dev/null +++ b/src/test/java/design/model/StrokeLeagueTest.java @@ -0,0 +1,66 @@ +package design.model; + +import static org.junit.jupiter.api.Assertions.assertFalse; +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 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); + } +} |
