diff options
| author | jrshi <jrs9538@g.rit.edu> | 2025-11-16 16:02:38 -0500 |
|---|---|---|
| committer | jrshi <jrs9538@g.rit.edu> | 2025-11-16 16:02:38 -0500 |
| commit | 0b43e258054b450f5007ef4d4fa34dacba2d8a9c (patch) | |
| tree | af8f64e4bdb6074fe2fb34c993850b6d81ce61de /src/test | |
| parent | 343d0baaaf718bfc9959484d187c4df1e171335e (diff) | |
| parent | af9f559a2ee427905c39363643bac2e7878fb10c (diff) | |
| download | designproject-design-6-0b43e258054b450f5007ef4d4fa34dacba2d8a9c.tar.gz designproject-design-6-0b43e258054b450f5007ef4d4fa34dacba2d8a9c.tar.bz2 designproject-design-6-0b43e258054b450f5007ef4d4fa34dacba2d8a9c.zip | |
Merge branch 'league-play-refactoring' of https://github.com/RIT-SWEN-262/designproject-design-6 into league-play-refactoringleague-play-refactoring
Merging?
Diffstat (limited to 'src/test')
19 files changed, 995 insertions, 102 deletions
diff --git a/src/test/java/design/TestCourseList.java b/src/test/java/design/TestCourseList.java deleted file mode 100644 index f943852..0000000 --- a/src/test/java/design/TestCourseList.java +++ /dev/null @@ -1,86 +0,0 @@ -// package design; - -// import static org.junit.jupiter.api.Assertions.assertEquals; -// import static org.junit.jupiter.api.Assertions.assertTrue; - -// import org.junit.jupiter.api.Test; -// import design.model.course_search.*; -// import design.model.*; - -// import java.util.List; - -// class TestCourseList { - -// // A dummy Course implementation for testing -// private static class DummyCourse implements ICourse { -// private final String name; -// private final float difficulty; - -// public DummyCourse(String name, float difficulty) { -// this.name = name; -// this.difficulty = difficulty; -// } - -// @Override -// public String getName() { return name; } - -// @Override -// public float getDifficultyRating() { return difficulty; } - -// @Override -// public String getLocation() { return ""; } - -// @Override -// public int getTotalPar() { return 0; } - -// @Override -// public int getHoleCount() { return 0; } - -// @Override -// public List<Hole> getHoles() { return null; } -// } - -// // A simple sorter that sorts courses by difficulty -// private static class SortByDifficultyTest implements CourseSorter { -// @Override -// public void sortCourses(List<ICourse> courses) { -// courses.sort((c1, c2) -> Float.compare(c1.getDifficultyRating(), c2.getDifficultyRating())); -// } -// } - -// @Test -// public void testAddAndRemoveCourses() { -// CourseList courseList = new CourseList(); -// ICourse course1 = new DummyCourse("Course A", 2.0f); -// ICourse course2 = new DummyCourse("Course B", 5.0f); - -// courseList.add(course1); -// courseList.add(course2); - -// assertEquals(2, courseList.getCourses().size(), "Should have 2 courses after adding"); -// assertTrue(courseList.getCourses().contains(course1), "Course A should be in the list"); -// assertTrue(courseList.getCourses().contains(course2), "Course B should be in the list"); - -// courseList.remove(course1); -// assertEquals(1, courseList.getCourses().size(), "Should have 1 course after removal"); -// assertTrue(!courseList.getCourses().contains(course1), "Course A should no longer be in the list"); -// } - -// @Test -// public void testSortCourses() { -// CourseList courseList = new CourseList(); -// courseList.add(new DummyCourse("Course A", 3.0f)); -// courseList.add(new DummyCourse("Course B", 1.0f)); -// courseList.add(new DummyCourse("Course C", 2.0f)); - -// // Set sorting strategy -// courseList.setSorter(new SortByDifficultyTest()); - -// courseList.sort(); - -// List<ICourse> sorted = courseList.getCourses(); -// assertEquals("Course B", sorted.get(0).getName(), "First course should have lowest difficulty"); -// assertEquals("Course C", sorted.get(1).getName(), "Second course should have medium difficulty"); -// assertEquals("Course A", sorted.get(2).getName(), "Last course should have highest difficulty"); -// } -// }
\ No newline at end of file diff --git a/src/test/java/design/model/ClubTest.java b/src/test/java/design/model/ClubTest.java index 9ac8130..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; @@ -17,13 +24,23 @@ public class ClubTest { { Club testClub = new Club("John Doe", "The Slammer", ClubType.DRIVER); - assertEquals(0, testClub.getId()); + 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); @@ -52,10 +69,18 @@ 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); - String expectedString = "#0 The Slammer - John Doe (DRIVER)"; + String expectedString = "#-1 The Slammer - John Doe (DRIVER)"; assertEquals(expectedString, testClub.toString()); } } diff --git a/src/test/java/design/model/GolferTest.java b/src/test/java/design/model/GolferTest.java index 65229f3..83ca17b 100644 --- a/src/test/java/design/model/GolferTest.java +++ b/src/test/java/design/model/GolferTest.java @@ -10,6 +10,7 @@ import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import design.model.Club.ClubType; +import design.model.undo.Memento; import java.lang.reflect.Constructor; import java.time.LocalDateTime; @@ -35,10 +36,10 @@ public class GolferTest { @Test void testPrivateConstructor() throws Exception { - Constructor<Golfer> constructor = Golfer.class.getDeclaredConstructor(String.class, int.class, String.class, List.class, List.class, List.class); + Constructor<Golfer> constructor = Golfer.class.getDeclaredConstructor(String.class, int.class, String.class, List.class, List.class, List.class, List.class, Team.class); assertTrue(Modifier.isPrivate(constructor.getModifiers())); constructor.setAccessible(true); - Golfer testGolfer = constructor.newInstance("testUser", 12345, "Test Golfer", new ArrayList<>(), new ArrayList<>(), new ArrayList<>()); + Golfer testGolfer = constructor.newInstance("testUser", 12345, "Test Golfer", new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), new ArrayList<>(), null); assertNotNull(testGolfer); } @@ -137,7 +138,16 @@ public class GolferTest { assertEquals(expectedString, testGolfer.toString()); } + @Test + void testMemento() + { + Golfer testGolfer = new Golfer("John Doe", "jdoesgolf2", "weback4321"); + Memento memento = testGolfer.createMemento(); + testGolfer.setFullName("Joe Doe"); + assertEquals("Joe Doe", testGolfer.getFullName()); + testGolfer.restore(memento); + assertEquals("John Doe", testGolfer.getFullName()); + } -} - +}
\ No newline at end of file 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/InviteTest.java b/src/test/java/design/model/InviteTest.java new file mode 100644 index 0000000..29388a2 --- /dev/null +++ b/src/test/java/design/model/InviteTest.java @@ -0,0 +1,38 @@ +package design.model; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +import java.util.Date; + +/** Unit Tests for the Invite Class. + * @author Willem Dalton + **/ +@Tag("Model-tier") +public class InviteTest { + @Test + void testConstructor() + { + Golfer testOwner = new Golfer("Jane Doe", "j_doe_rocks", "1234"); + Team testTeam = new Team("A Team", testOwner); + Date testDate = new Date(123456); + Invite testInvite = new Invite(testTeam, testDate); + + assertEquals(testTeam, testInvite.getTeam()); + assertEquals(testDate, testInvite.getSendDate()); + } + + @Test + void testAccept() + { + Golfer testOwner = new Golfer("Jane Doe", "j_doe_rocks", "1234"); + Golfer testInvitee = new Golfer("James Doe", "j_doe_is_cool", "54321"); + Team testTeam = new Team("A Team", testOwner); + Date testDate = new Date(123456); + Invite testInvite = new Invite(testTeam, testDate); + testInvite.accept(testInvitee); + assertEquals(testInvitee, testTeam.getMembers()[0]); + } +} diff --git a/src/test/java/design/model/MatchTest.java b/src/test/java/design/model/MatchTest.java new file mode 100644 index 0000000..c775c11 --- /dev/null +++ b/src/test/java/design/model/MatchTest.java @@ -0,0 +1,59 @@ +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 java.util.ArrayList; +import java.util.List; +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; +import java.util.Date; +import java.time.LocalDateTime; + +/** Unit Tests for the Match class. + * @author Willem Dalton + **/ +@Tag("Model-tier") +public class MatchTest { + + @Test + void testConstructor() + { + Course testCourse = new Course(0, "Rolling Waves", 67, "Rochester. NY", 9, 30, new ArrayList<Hole>()); + Date testDate = new Date(1234567); + LocalDateTime now = LocalDateTime.now(); + Match testMatch = new Match(testCourse, testDate, now, now, 9); + assertEquals(testCourse, testMatch.getCourse()); + assertEquals(testDate, testMatch.getDateScheduled()); + assertEquals(now, testMatch.getStart()); + assertEquals(9, testMatch.getHoleCount()); + } + + @Test + void testPrivateConstructor() throws Exception + { + Course testCourse = new Course(0, "Rolling Waves", 67, "Rochester. NY", 9, 30, new ArrayList<Hole>()); + Constructor<Match> constructor = Match.class.getDeclaredConstructor(Course.class, Date.class, LocalDateTime.class, LocalDateTime.class, int.class, List.class); + assertTrue(Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + Match testMatch = constructor.newInstance(testCourse, new Date(1234), LocalDateTime.now(), LocalDateTime.now(), 0, new ArrayList<>()); + assertNotNull(testMatch); + } + + @Test + void testAddRound() + { + Course testCourse = new Course(0, "Rolling Waves", 67, "Rochester. NY", 9, 30, new ArrayList<Hole>()); + Date testDate = new Date(1234567); + LocalDateTime now = LocalDateTime.now(); + Match testMatch = new Match(testCourse, testDate, now, now, 9); + Round testRound = new Round(testCourse, now, new Hole(0, 5)); + testMatch.addRound(testRound); + assertEquals(testRound, testMatch.getRounds()[0]); + assertEquals(1, testMatch.getRounds().length); + } +} diff --git a/src/test/java/design/model/PlayTest.java b/src/test/java/design/model/PlayTest.java new file mode 100644 index 0000000..0a27076 --- /dev/null +++ b/src/test/java/design/model/PlayTest.java @@ -0,0 +1,43 @@ +package design.model; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +import design.model.Club.ClubType; + +import java.util.ArrayList; + +/** Unit Tests for the Play class. + * @author Willem Dalton + **/ +@Tag("Model-tier") +public class PlayTest { + @Test + void testConstructor() + { + Play testPlay = new Play(0); + assertEquals(0, testPlay.getHoleNumber()); + } + + @Test + void testConstructorNull() + { + Play testPlay2 = new Play(0, null); + assertEquals(0, testPlay2.getHoleNumber()); + assertEquals(0, testPlay2.getSwings().length); + } + + @Test + void testConstructorNotNull() + { + Club newClub = new Club("John Doe Inc", "The Slammer", ClubType.DRIVER); + Swing newSwing = new Swing(100, newClub); + ArrayList<Swing> swings = new ArrayList<Swing>(); + swings.add(newSwing); + Play testPlay3 = new Play(0, swings); + assertEquals(0, testPlay3.getHoleNumber()); + assertEquals(swings.get(0), testPlay3.getSwings()[0]); + } +} 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/ScrambleLeagueTest.java b/src/test/java/design/model/ScrambleLeagueTest.java new file mode 100644 index 0000000..e8fe63c --- /dev/null +++ b/src/test/java/design/model/ScrambleLeagueTest.java @@ -0,0 +1,89 @@ +package design.model; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +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 scramble league model class. + * @author Willem Dalton + */ +@Tag("Model-tier") +public class ScrambleLeagueTest { + + @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"); + ScrambleLeague testLeague = new ScrambleLeague("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<ScrambleLeague> constructor = ScrambleLeague.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); + ScrambleLeague testLeague = constructor.newInstance(1, "Bobby's Band", new Date(), new Date(), new Date(), testOwner, new ArrayList<Team>(), 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"); + ScrambleLeague testLeague = new ScrambleLeague("Bobby's Band", testRegistration, testStart, testEnd, testOwner); + Team testTeam = new Team("The A Team", testOwner); + + // add and remove participant + testLeague.addParticipants(testTeam); + assertEquals(testTeam, testLeague.getParticipants()[0]); + assertEquals(1, testLeague.getParticipants().length); + testLeague.removeParticipants(testTeam); + assertEquals(0, testLeague.getParticipants().length); + } + + @Test + void testLocateTeam() throws Exception + { + Date testStart = new Date(1234567); + Date testRegistration = new Date(1234568); + Date testEnd = new Date(12345679); + Golfer testOwner = new Golfer("Bobby", "bobby123", "iloveswen262"); + ScrambleLeague testLeague = new ScrambleLeague("Bobby's Band", testRegistration, testStart, testEnd, testOwner); + + Team testTeam = new Team("The A Team", testOwner); + Golfer teamMember = new Golfer("Jane Doe", "jane_doe", "weback"); + Golfer nonMember = new Golfer("NAN doe", "nan_doe", "wenotback"); + + // expect a result if member is part of team. expect null if they are not. + testTeam.addMember(teamMember); + testLeague.addParticipants(testTeam); + Team result = testLeague.locateTeam(teamMember); + assertEquals(result, testTeam); + result = testLeague.locateTeam(nonMember); + assertNull(result); + } +} 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); + } +} diff --git a/src/test/java/design/model/TeamTest.java b/src/test/java/design/model/TeamTest.java new file mode 100644 index 0000000..c81aa1e --- /dev/null +++ b/src/test/java/design/model/TeamTest.java @@ -0,0 +1,42 @@ +package design.model; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +/** Unit Tests for the Team Class. + * @author Willem Dalton + **/ +@Tag("Model-tier") +public class TeamTest { + @Test + void testConstructor() + { + Golfer testGolfer = new Golfer("John Doe", "j_doe_golfs", "ilovegolf123"); + Team testTeam = new Team("A Team", testGolfer); + assertEquals("A Team", testTeam.getName()); + assertEquals(testGolfer, testTeam.getOwner()); + } + + @Test + void testSetName() + { + Golfer testGolfer = new Golfer("John Doe", "j_doe_golfs", "ilovegolf123"); + Team testTeam = new Team("A Team", testGolfer); + testTeam.setName("B Team"); + assertEquals("B Team", testTeam.getName()); + } + + @Test + void testRemoveMember() + { + Golfer testGolfer = new Golfer("John Doe", "j_doe_golfs", "ilovegolf123"); + Golfer newGolfer = new Golfer("Jane Doe", "j_doe_golfs2", "ilovegolf321"); + Team testTeam = new Team("A Team", testGolfer); + testTeam.addMember(newGolfer); + assertEquals(1, testTeam.getMembers().length); + testTeam.removeMember(newGolfer); + assertEquals(0, testTeam.getMembers().length); + } +} diff --git a/src/test/java/design/model/coursesearch/CourseListTest.java b/src/test/java/design/model/coursesearch/CourseListTest.java index 7538ba5..6bc5529 100644 --- a/src/test/java/design/model/coursesearch/CourseListTest.java +++ b/src/test/java/design/model/coursesearch/CourseListTest.java @@ -1,18 +1,19 @@ package design.model.coursesearch; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import java.util.ArrayList; +import design.model.course_search.ICourse; import design.model.course_search.*; import design.model.Course; -/** Unit Tests for the Club class. +/** Unit Tests for the Course List class. * @author Willem Dalton **/ @Tag("Model-tier") @@ -22,6 +23,61 @@ public class CourseListTest { void testConstructor() { CourseList testList = new CourseList(); + assertNotNull(testList); + } + + @Test + void testSetCourses() + { + CourseList testList = new CourseList(); + Course testCourse1 = new Course(0, "Rolling Waves", 10, "Rochester, NY", 0, 0, null); + Course testCourse2 = new Course(1, "Arcadia Hills", 10, "Rochester, NY", 0, 0, null); + ArrayList<ICourse> courses = new ArrayList<ICourse>(); + courses.add(testCourse1); + courses.add(testCourse2); + testList.setCourses(courses); + assertEquals(courses, testList.getCourses()); + } + @Test + void testSort() + { + CourseList testList = new CourseList(); + Course testCourse1 = new Course(0, "Rolling Waves", 10, "Rochester, NY", 0, 0, null); + Course testCourse2 = new Course(1, "Arcadia Hills", 10, "Rochester, NY", 0, 0, null); + ArrayList<ICourse> courses = new ArrayList<ICourse>(); + courses.add(testCourse1); + courses.add(testCourse2); + testList.setCourses(courses); + SortByName sorter = new SortByName(); + testList.setSorter(sorter); + testList.sort(); + assertEquals(testCourse2, testList.getCourses().get(0)); + assertEquals(testCourse1, testList.getCourses().get(1)); + } + + @Test + void testAddRemove() + { + CourseList testList = new CourseList(); + Course testCourse1 = new Course(0, "Rolling Waves", 10, "Rochester, NY", 0, 0, null); + testList.add(testCourse1); + assertEquals(testCourse1, testList.getCourses().get(0)); + assertEquals(1, testList.getCourses().size()); + testList.remove(testCourse1); + assertEquals(0, testList.getCourses().size()); + } + + @Test + void testOverrides() + { + CourseList testList = new CourseList(); + assertEquals("Course List", testList.getName()); + assertEquals("Course List", testList.toString()); + assertEquals(0, testList.getDifficultyRating()); + assertEquals("", testList.getLocation()); + assertEquals(0, testList.getTotalPar()); + assertEquals(0, testList.getHoleCount()); + assertNull(testList.getHoles()); } } diff --git a/src/test/java/design/model/coursesearch/CurrentSearchQueryTest.java b/src/test/java/design/model/coursesearch/CurrentSearchQueryTest.java new file mode 100644 index 0000000..10f3f87 --- /dev/null +++ b/src/test/java/design/model/coursesearch/CurrentSearchQueryTest.java @@ -0,0 +1,27 @@ +package design.model.coursesearch; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; + +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import java.util.ArrayList; + +import design.model.course_search.*; +import design.model.Course; + +/** Unit Tests for the Current Search Query Class + * @author Willem Dalton + **/ +@Tag("Model-tier") +public class CurrentSearchQueryTest { + + // @Test + // void testReset() + // { + // CurrentSearchQuery query + // } + + +} diff --git a/src/test/java/design/model/coursesearch/sortStrategyTest.java b/src/test/java/design/model/coursesearch/sortStrategyTest.java index aecbeff..35fa335 100644 --- a/src/test/java/design/model/coursesearch/sortStrategyTest.java +++ b/src/test/java/design/model/coursesearch/sortStrategyTest.java @@ -11,10 +11,11 @@ import java.util.ArrayList; import design.model.course_search.*; import design.model.Course; -/** Unit Tests for the Difficulty Sorter class +/** Unit Tests for the Sorter Strategy classes * @author Willem Dalton **/ -public class sortStrategyTest { +@Tag("Model-tier") +public class SortStrategyTest { Course test1 = new Course(0, "Rolling Waves", 67, "Rochester, NY", 9, 30, null); Course test2 = new Course(1, "Balls in the Rough", 60, "Buffalo, NY", 18, 60, null); @@ -25,7 +26,7 @@ public class sortStrategyTest { void testDifficultySort() { SortByDifficulty sorter = new SortByDifficulty(); - ArrayList<ICourse> courses = new ArrayList(); + ArrayList<ICourse> courses = new ArrayList<ICourse>(); courses.add(test1); courses.add(test2); sorter.sortCourses(courses); @@ -38,7 +39,7 @@ public class sortStrategyTest { void testNameSort() { SortByName sorter = new SortByName(); - ArrayList<ICourse> courses = new ArrayList(); + ArrayList<ICourse> courses = new ArrayList<ICourse>(); courses.add(test1); courses.add(test4); sorter.sortCourses(courses); @@ -51,7 +52,7 @@ public class sortStrategyTest { void testLocationSort() { SortByLocation sorter = new SortByLocation(); - ArrayList<ICourse> courses = new ArrayList(); + ArrayList<ICourse> courses = new ArrayList<ICourse>(); courses.add(test1); courses.add(test4); sorter.sortCourses(courses); @@ -64,7 +65,7 @@ public class sortStrategyTest { void testParSort() { SortByPar sorter = new SortByPar(); - ArrayList<ICourse> courses = new ArrayList(); + ArrayList<ICourse> courses = new ArrayList<ICourse>(); courses.add(test1); courses.add(test4); sorter.sortCourses(courses); @@ -77,7 +78,7 @@ public class sortStrategyTest { void testHoleSort() { SortByHoles sorter = new SortByHoles(); - ArrayList<ICourse> courses = new ArrayList(); + ArrayList<ICourse> courses = new ArrayList<ICourse>(); courses.add(test1); courses.add(test4); sorter.sortCourses(courses); diff --git a/src/test/java/design/model/holeplay/HolePlayContextTest.java b/src/test/java/design/model/holeplay/HolePlayContextTest.java index de0f1e9..c2ca619 100644 --- a/src/test/java/design/model/holeplay/HolePlayContextTest.java +++ b/src/test/java/design/model/holeplay/HolePlayContextTest.java @@ -1,5 +1,74 @@ package design.model.holeplay; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +import java.util.Date; +import java.time.LocalDateTime; +import java.util.ArrayList; + +import design.model.Golfer; +import design.model.Round; +import design.model.Club.ClubType; +import design.persistence.PersonalDatabase; +import design.model.Course; +import design.model.Hole; +import design.model.Club; + +/** Unit Tests for the HolePlayContext Class. + * @author Willem Dalton + **/ +@Tag("Model-tier") public class HolePlayContextTest { + @Test + void testConstructor() + { + Golfer testGolfer = new Golfer("John Doe", "j_doe", "weback"); + Course testCourse = new Course(0, "Rolling Waves", 67, "Rochester, NY", 0, 0, new ArrayList<Hole>()); + Round testRound = new Round(testCourse, LocalDateTime.now(), new Hole(0, 10)); + HolePlayContext testContext = new HolePlayContext(testGolfer, testRound, PersonalDatabase.instance()); + assertEquals(testGolfer, testContext.getGolfer()); + assertEquals(testRound, testContext.getRound()); + } + + @Test + void testPlay() + { + Golfer testGolfer = new Golfer("John Doe", "j_doe", "weback"); + Course testCourse = new Course(0, "Rolling Waves", 67, "Rochester, NY", 0, 0, new ArrayList<Hole>()); + Round testRound = new Round(testCourse, LocalDateTime.now(), new Hole(0, 10)); + HolePlayContext testContext = new HolePlayContext(testGolfer, testRound, PersonalDatabase.instance()); + testContext.beginNewPlay(0); + Club testClub = new Club("John Doe Inc", "The Slammer", ClubType.DRIVER); + testContext.addSwing(testClub, 100); + assertEquals(1, testContext.getCurrentPlay().getSwingCount()); + assertEquals(100, testContext.getCurrentPlay().getDistance()); + } + + @Test + void testPlayNull() + { + Golfer testGolfer = new Golfer("John Doe", "j_doe", "weback"); + Course testCourse = new Course(0, "Rolling Waves", 67, "Rochester, NY", 0, 0, new ArrayList<Hole>()); + Round testRound = new Round(testCourse, LocalDateTime.now(), new Hole(0, 10)); + HolePlayContext testContext = new HolePlayContext(testGolfer, testRound, PersonalDatabase.instance()); + testContext.beginNewPlay(0); + Club testClub = new Club("John Doe Inc", "The Slammer", ClubType.DRIVER); + testContext.addSwing(testClub, null); + assertEquals(1, testContext.getCurrentPlay().getSwingCount()); + assertEquals(0, testContext.getCurrentPlay().getDistance()); + } + + // @Test + // void testHolePlay() + // { + // Golfer testGolfer = new Golfer("John Doe", "j_doe", "weback"); + // Course testCourse = new Course(0, "Rolling Waves", 67, "Rochester, NY", 0, 0, new ArrayList<Hole>()); + // Round testRound = new Round(testCourse, LocalDateTime.now(), new Hole(0, 10)); + // HolePlayContext testContext = new HolePlayContext(testGolfer, testRound, PersonalDatabase.instance()); + // testContext.startHole(); + // } }
\ No newline at end of file diff --git a/src/test/java/design/model/statistics/StatisticsTest.java b/src/test/java/design/model/statistics/StatisticsTest.java new file mode 100644 index 0000000..e68796a --- /dev/null +++ b/src/test/java/design/model/statistics/StatisticsTest.java @@ -0,0 +1,180 @@ +package design.model.statistics; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.Arrays; + +import design.model.Course; +import design.model.Golfer; +import design.model.Hole; +import design.model.Round; +import design.model.Club.ClubType; +import design.model.Play; +import design.model.Club; +import design.model.Swing; + +/** Unit Tests for the Statistics Subsystem + * @author Willem Dalton + **/ +@Tag("Model-tier") +public class StatisticsTest { + + /* base stats wrapper for testing purposes */ + private static class StubStatistics implements Statistics { + private final Golfer golfer; + + public StubStatistics(Golfer golfer) { + this.golfer = golfer; + } + + @Override + public Round[] getRounds() { + return golfer.getRounds(); + } + + @Override + public int get_score() { + return Arrays.stream(getRounds()) + .mapToInt(Round::getTotalSwings) + .sum(); + } + + @Override + public double get_distance() { + return Arrays.stream(getRounds()) + .mapToDouble(Round::getTotalDistance) + .sum(); + } + } + + @Test + void testLifeTime() + { + Golfer testGolfer = new Golfer("John Doe", "j_doe", "weback"); + Course testCourse = new Course(0, "Rolling Waves", 67, "Rochester, NY", 0, 0, new ArrayList<Hole>()); + Round testRound = new Round(testCourse, LocalDateTime.now(), new Hole(0, 10)); + Swing testSwing = new Swing(100, new Club("John Doe Inc", "The Slammer", ClubType.DRIVER)); + LifetimeStats stats = new LifetimeStats(testGolfer); + + assertNotNull(stats); + assertEquals(0, stats.get_score()); + assertEquals(0, stats.get_distance()); + + ArrayList<Swing> testSwings = new ArrayList<Swing>(); + testSwings.add(testSwing); + Play testPlay = new Play(0, testSwings); + testRound.addPlay(testPlay); + testGolfer.addRound(testRound); + + assertEquals(1, stats.get_score()); + assertEquals(100, stats.get_distance()); + } + + @Test + void testYearly() + { + Golfer testGolfer = new Golfer("John Doe", "j_doe", "weback"); + Course testCourse = new Course(0, "Rolling Waves", 67, "Rochester, NY", 0, 0, new ArrayList<Hole>()); + Round testRound = new Round(testCourse, LocalDateTime.now(), new Hole(0, 10)); + Swing testSwing = new Swing(100, new Club("John Doe Inc", "The Slammer", ClubType.DRIVER)); + + Statistics wrapper = new StubStatistics(testGolfer); + YearlyStats stats = new YearlyStats(wrapper, 2025); + + assertNotNull(stats); + assertEquals(0, stats.get_score()); + assertEquals(0, stats.get_distance()); + + ArrayList<Swing> testSwings = new ArrayList<Swing>(); + testSwings.add(testSwing); + Play testPlay = new Play(0, testSwings); + testRound.addPlay(testPlay); + testGolfer.addRound(testRound); + + assertEquals(1, stats.get_score()); + assertEquals(100, stats.get_distance()); + } + + @Test + void testCourse() + { + Golfer testGolfer = new Golfer("John Doe", "j_doe", "weback"); + Course testCourse = new Course(0, "Rolling Waves", 67, "Rochester, NY", 0, 0, new ArrayList<Hole>()); + Round testRound = new Round(testCourse, LocalDateTime.now(), new Hole(0, 10)); + Swing testSwing = new Swing(100, new Club("John Doe Inc", "The Slammer", ClubType.DRIVER)); + + Statistics wrapper = new StubStatistics(testGolfer); + CourseStats stats = new CourseStats(wrapper, testCourse); + + assertNotNull(stats); + assertEquals(0, stats.get_score()); + assertEquals(0, stats.get_distance()); + + ArrayList<Swing> testSwings = new ArrayList<Swing>(); + testSwings.add(testSwing); + Play testPlay = new Play(0, testSwings); + testRound.addPlay(testPlay); + testGolfer.addRound(testRound); + + assertEquals(1, stats.get_score()); + assertEquals(100, stats.get_distance()); + } + + @Test + void testRound() + { + Golfer testGolfer = new Golfer("John Doe", "j_doe", "weback"); + Course testCourse = new Course(0, "Rolling Waves", 67, "Rochester, NY", 0, 0, new ArrayList<Hole>()); + Round testRound = new Round(testCourse, LocalDateTime.now(), new Hole(0, 10)); + Swing testSwing = new Swing(100, new Club("John Doe Inc", "The Slammer", ClubType.DRIVER)); + + Statistics wrapper = new StubStatistics(testGolfer); + RoundStats stats = new RoundStats(wrapper, testRound); + + assertNotNull(stats); + assertEquals(0, stats.get_score()); + assertEquals(0, stats.get_distance()); + + ArrayList<Swing> testSwings = new ArrayList<Swing>(); + testSwings.add(testSwing); + Play testPlay = new Play(0, testSwings); + testRound.addPlay(testPlay); + testGolfer.addRound(testRound); + + assertEquals(1, stats.get_score()); + assertEquals(100, stats.get_distance()); + } + + @Test + void testHole() + { + Golfer testGolfer = new Golfer("John Doe", "j_doe", "weback"); + Course testCourse = new Course(0, "Rolling Waves", 67, "Rochester, NY", 0, 0, new ArrayList<Hole>()); + Round testRound = new Round(testCourse, LocalDateTime.now(), new Hole(0, 10)); + Swing testSwing = new Swing(100, new Club("John Doe Inc", "The Slammer", ClubType.DRIVER)); + Hole testHole = new Hole(0, 10); + + Statistics wrapper = new StubStatistics(testGolfer); + HoleStats stats = new HoleStats(wrapper, testHole); + + assertNotNull(stats); + assertEquals(0, stats.get_score()); + assertEquals(0, stats.get_distance()); + + ArrayList<Swing> testSwings = new ArrayList<Swing>(); + testSwings.add(testSwing); + Play testPlay = new Play(0, testSwings); + testRound.addPlay(testPlay); + testGolfer.addRound(testRound); + + assertEquals(1, stats.get_score()); + assertEquals(100, stats.get_distance()); + assertEquals(0, stats.getRounds().length); + } +} diff --git a/src/test/java/design/persistence/CSVMasterDatabaseTest.java b/src/test/java/design/persistence/CSVMasterDatabaseTest.java new file mode 100644 index 0000000..4c78800 --- /dev/null +++ b/src/test/java/design/persistence/CSVMasterDatabaseTest.java @@ -0,0 +1,33 @@ +package design.persistence; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +/** Unit Tests for the CSV Master Database Singleton class. + * @author Willem Dalton + **/ +@Tag("Persistence-tier") +public class CSVMasterDatabaseTest { + + @Test + void testInstance() + { + CSVMasterDatabase instance = CSVMasterDatabase.instance(); + assertNotNull(instance); + CSVMasterDatabase instance2 = CSVMasterDatabase.instance(); + assertNotNull(instance2); + } + + @Test + void testGetCourses() + { + CSVMasterDatabase instance = CSVMasterDatabase.instance(); + String expectedResult = "Mountain View Links (Mobile, AL) | Holes: 18 | Total Par: 70 | Difficulty: 73.0"; + assertEquals(1000, instance.getCourses().length); + assertNotNull(instance.getCourseList()); + assertEquals(expectedResult, instance.getCourse(0).toString()); + } +} diff --git a/src/test/java/design/persistence/JSONLeagueDatabaseTest.java b/src/test/java/design/persistence/JSONLeagueDatabaseTest.java new file mode 100644 index 0000000..f211670 --- /dev/null +++ b/src/test/java/design/persistence/JSONLeagueDatabaseTest.java @@ -0,0 +1,75 @@ +package design.persistence; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.Date; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +import design.model.League; +import design.model.StrokeLeague; +import design.model.Course; +import design.model.Golfer; +import design.model.Hole; +import design.model.Match; + +/** Unit Tests for the JSON Personal Database Singleton + * @author Willem Dalton + **/ +@Tag("Persistence-tier") +public class JSONLeagueDatabaseTest { + Path tempDB; + + @BeforeEach + void clearDB() throws IOException + { + tempDB = Files.createTempFile("testleaguedb", ".json"); + Files.writeString(tempDB, "[]"); + JSONLeagueDatabase.testInstance(tempDB.toString()); + } + + @Test + void testInstance() + { + JSONLeagueDatabase instance = JSONLeagueDatabase.instance(); // makes new instance + assertNotNull(instance); + JSONLeagueDatabase instance2 = JSONLeagueDatabase.instance(); // instance already exists + assertNotNull(instance2); + } + + @Test + void testAddRemove() throws IOException + { + JSONLeagueDatabase instance = JSONLeagueDatabase.testInstance(tempDB.toString()); // makes new instance + Golfer testOwner = new Golfer("Jamie Doe", "joe_cool", "12345"); + League testLeague = new StrokeLeague("The A Team", new Date(1234), new Date(123), new Date(12345), testOwner); + instance.addLeague(testLeague); + assertEquals(1, instance.getLeagues().length); + assertEquals(testLeague, instance.getLeagues()[0]); + instance.removeLeague(testLeague); + assertEquals(0, instance.getLeagues().length); + } + + @Test + void testUpdateGolfer() throws IOException + { + JSONLeagueDatabase instance = JSONLeagueDatabase.testInstance(tempDB.toString()); // makes new instance + Golfer testOwner = new Golfer("Jamie Doe", "joe_cool", "12345"); + League testLeague = new StrokeLeague("The A Team", new Date(1234), new Date(123), new Date(12345), testOwner); + instance.addLeague(testLeague); + Course testCourse = new Course(0, "Rolling Waves", 62, "Rochester, NY", 9, 20, new ArrayList<Hole>()); + Match testMatch = new Match(testCourse, new Date(123), LocalDateTime.now(), LocalDateTime.now(), 3); + testLeague.addMatchToSchedule(testMatch); + instance.updateLeague(testLeague); + assertEquals(testLeague, instance.getLeague(testLeague.getId())); + } +} diff --git a/src/test/java/design/persistence/JSONPersonalDatabaseTest.java b/src/test/java/design/persistence/JSONPersonalDatabaseTest.java new file mode 100644 index 0000000..21cc366 --- /dev/null +++ b/src/test/java/design/persistence/JSONPersonalDatabaseTest.java @@ -0,0 +1,62 @@ +package design.persistence; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +import design.model.Golfer; + +/** Unit Tests for the JSON Personal Database Singleton + * @author Willem Dalton + **/ +@Tag("Persistence-tier") +public class JSONPersonalDatabaseTest { + Path tempDB; + + @BeforeEach + void clearDB() throws IOException + { + tempDB = Files.createTempFile("testdb", ".json"); + Files.writeString(tempDB, "[]"); + JSONPersonalDatabase.testInstance(tempDB.toString()); + } + + @Test + void testInstance() + { + JSONPersonalDatabase instance = JSONPersonalDatabase.instance(); // makes new instance + assertNotNull(instance); + JSONPersonalDatabase instance2 = JSONPersonalDatabase.instance(); // instance already exists + assertNotNull(instance2); + } + + @Test + void testAddRemove() throws IOException + { + JSONPersonalDatabase instance = JSONPersonalDatabase.testInstance(tempDB.toString()); // makes new instance + Golfer testGolfer = new Golfer("Jamie Doe", "joe_cool", "12345"); + instance.addGolfer(testGolfer); + assertEquals(testGolfer, instance.getGolfer("joe_cool")); + instance.removeGolfer(testGolfer); + assertEquals(null, instance.getGolfer("joe_cool")); + } + + @Test + void testUpdateGolfer() throws IOException + { + JSONPersonalDatabase instance = JSONPersonalDatabase.testInstance(tempDB.toString()); // makes new instance + Golfer testGolfer = new Golfer("Jamie Doe", "joe_cool", "12345"); + instance.addGolfer(testGolfer); + testGolfer.setUsername("joe_super_cool"); + instance.updateGolfer(testGolfer); + assertEquals(testGolfer, instance.getGolfer("joe_super_cool")); + } +} |
