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 **/ @Tag("Model-tier") public class RoundTest { @Test void testConstructor() { Course testCourse = new Course(0, "Rolling Waves", 62, "Rochester, NY", 9, 20, new ArrayList()); LocalDateTime testTime = LocalDateTime.now(); Hole testHole = new Hole(0,3); Round testRound = new Round(testCourse, testTime, testHole); assertEquals(testCourse, testRound.getCourse()); assertEquals(testTime, testRound.getDateTime()); 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() { Course testCourse = new Course(0, "Rolling Waves", 62, "Rochester, NY", 9, 20, new ArrayList()); LocalDateTime testTime = LocalDateTime.now(); Hole testHole = new Hole(0,3); Round testRound = new Round(testCourse, testTime, testHole); 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()); } }