From 229a469f61f842260618ee52294b5dae0f3c1bb4 Mon Sep 17 00:00:00 2001 From: WillemDalton Date: Thu, 13 Nov 2025 17:35:47 -0500 Subject: completed coverage for stroke league --- src/test/java/design/model/RoundTest.java | 50 +++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'src/test/java/design/model/RoundTest.java') 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 @@ -26,6 +33,18 @@ public class RoundTest { assertEquals(testHole, testRound.getStartingHole()); } + @Test + void testPrivateConstructor() throws Exception + { + Course testCourse = new Course(0, "Rolling Waves", 62, "Rochester, NY", 9, 20, new ArrayList()); + Constructor 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()); + assertNotNull(testRound); + } + + @Test void testHolePlay() { @@ -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 testHoles = new ArrayList(); + 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()); } } -- cgit v1.2.3