summaryrefslogtreecommitdiff
path: root/src/test/java/design/model/GolferTest.java
diff options
context:
space:
mode:
authorWillemDalton <willemhdalton@gmail.com>2025-11-05 16:34:03 -0500
committerWillemDalton <willemhdalton@gmail.com>2025-11-05 16:34:03 -0500
commitac4a71e3b43370fe45e39ac4e735b88f2e284a14 (patch)
treebfca90c11d697e6da02f0032453aaa10acb869d6 /src/test/java/design/model/GolferTest.java
parent17aba16fbb3272a73b1a1b6b1c459e3597fc066e (diff)
downloaddesignproject-design-6-ac4a71e3b43370fe45e39ac4e735b88f2e284a14.tar.gz
designproject-design-6-ac4a71e3b43370fe45e39ac4e735b88f2e284a14.tar.bz2
designproject-design-6-ac4a71e3b43370fe45e39ac4e735b88f2e284a14.zip
working on unit tests, added to pom to support jacoco
Diffstat (limited to 'src/test/java/design/model/GolferTest.java')
-rw-r--r--src/test/java/design/model/GolferTest.java136
1 files changed, 136 insertions, 0 deletions
diff --git a/src/test/java/design/model/GolferTest.java b/src/test/java/design/model/GolferTest.java
new file mode 100644
index 0000000..4dce705
--- /dev/null
+++ b/src/test/java/design/model/GolferTest.java
@@ -0,0 +1,136 @@
+
+package design.model;
+
+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 design.model.Club.ClubType;
+
+import java.lang.reflect.Constructor;
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.lang.reflect.Modifier;
+
+/** Unit Tests for the Club class.
+ * @author Willem Dalton
+ **/
+@Tag("Model-tier")
+public class GolferTest {
+
+ @Test
+ void testConstructor()
+ {
+ Golfer testGolfer = new Golfer("John Doe", "jdoesgolf2", "weback4321");
+ assertEquals("John Doe", testGolfer.getFullName());
+ assertEquals("jdoesgolf2", testGolfer.getUsername());
+ assertTrue(testGolfer.checkPassword("weback4321"));
+ }
+
+ // @Test
+ // void testPrivateConstructor() throws Exception
+ // {
+ // Constructor<Golfer> constructor = Golfer.class.getDeclaredConstructor();
+ // assertTrue(Modifier.isPrivate(constructor.getModifiers()));
+ // }
+
+ @Test
+ void testSetUserName()
+ {
+ Golfer testGolfer = new Golfer("John Doe", "jdoesgolf2", "weback4321");
+ testGolfer.setUsername("jquitgolf2");
+ assertEquals("jquitgolf2", testGolfer.getUsername());
+ }
+
+ @Test
+ void testSetFullName()
+ {
+ Golfer testGolfer = new Golfer("John Doe", "jdoesgolf2", "weback4321");
+ testGolfer.setFullName("John Joe");
+ assertEquals("John Joe", testGolfer.getFullName());
+ }
+
+ @Test
+ void testSetPassword()
+ {
+ Golfer testGolfer = new Golfer("John Doe", "jdoesgolf2", "weback4321");
+ testGolfer.setPassword("lifeisroblox1234");
+ assertTrue(testGolfer.checkPassword("lifeisroblox1234"));
+ }
+
+ @Test
+ void testWrongPassword()
+ {
+ Golfer testGolfer = new Golfer("John Doe", "jdoesgolf2", "weback4321");
+ assertFalse(testGolfer.checkPassword("lifeisroblox1234"));
+ }
+
+ @Test
+ void testAddCourse()
+ {
+ Golfer testGolfer = new Golfer("John Doe", "jdoesgolf2", "weback4321");
+ Course exampleCourse = new Course(0, "Rolling Hills", 68, "Rochester, NY", 9, 30, new ArrayList<Hole>());
+ testGolfer.addCourse(exampleCourse);
+ assertEquals(exampleCourse, testGolfer.getCourses()[0]);
+ assertTrue(testGolfer.hasCourses());
+ }
+
+ @Test
+ void testRemoveCourse()
+ {
+ Golfer testGolfer = new Golfer("John Doe", "jdoesgolf2", "weback4321");
+ Course exampleCourse = new Course(0, "Rolling Hills", 68, "Rochester, NY", 9, 30, new ArrayList<Hole>());
+ testGolfer.addCourse(exampleCourse);
+ testGolfer.removeCourse(exampleCourse);
+ assertFalse(testGolfer.hasCourses());
+ }
+
+ @Test
+ void testRounds()
+ {
+ Golfer testGolfer = new Golfer("John Doe", "jdoesgolf2", "weback4321");
+ Course exampleCourse = new Course(0, "Rolling Hills", 68, "Rochester, NY", 9, 30, new ArrayList<Hole>());
+ Round exampleRound = new Round(exampleCourse, LocalDateTime.MAX, new Hole(0, 3));
+ testGolfer.addRound(exampleRound);
+ assertEquals(exampleRound, testGolfer.getRounds()[0]);
+ }
+
+ @Test
+ void testAddClub()
+ {
+ Golfer testGolfer = new Golfer("John Doe", "jdoesgolf2", "weback4321");
+
+ testGolfer.addClub("John Doe", "The Slammer", ClubType.DRIVER);
+ Club addedClub = testGolfer.getClubs()[0];
+ assertTrue(testGolfer.hasClub(addedClub));
+ assertTrue(testGolfer.hasClubs());
+ }
+
+ @Test
+ void testRemoveClub()
+ {
+ Golfer testGolfer = new Golfer("John Doe", "jdoesgolf2", "weback4321");
+
+ testGolfer.addClub("John Doe", "The Slammer", ClubType.DRIVER);
+ Club addedClub = testGolfer.getClubs()[0];
+ testGolfer.removeClub(addedClub);
+ assertFalse(testGolfer.hasClub(addedClub));
+ assertFalse(testGolfer.hasClubs());
+
+ }
+
+ @Test
+ void testToString()
+ {
+ Golfer testGolfer = new Golfer("John Doe", "jdoesgolf2", "weback4321");
+ String expectedString = "John Doe (@jdoesgolf2)";
+ assertEquals(expectedString, testGolfer.toString());
+ }
+
+
+
+}
+