summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pom.xml87
-rw-r--r--src/test/java/design/HelloWorldTest.java12
-rw-r--r--src/test/java/design/model/ClubTest.java61
-rw-r--r--src/test/java/design/model/GolferTest.java136
4 files changed, 282 insertions, 14 deletions
diff --git a/pom.xml b/pom.xml
index 1486a8b..6e37b12 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,5 +1,6 @@
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>design</groupId>
<artifactId>design</artifactId>
@@ -61,6 +62,88 @@
<!-- JUnit 5 requires Surefire version 2.22.0 or higher -->
<version>3.0.0-M8</version>
</plugin>
+ <plugin>
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <version>0.8.11</version>
+ <configuration>
+ <destfile>/target/coverage-reports/jacoco-unit.exec</destfile>
+ <datafile>/target/coverage-reports/jacoco-unit.exec</datafile>
+ </configuration>
+ <executions>
+ <execution>
+ <id>jacoco-initialize</id>
+ <configuration>
+ <!-- throw away the old data with each test run -->
+ <append>false</append>
+ </configuration>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ </execution>
+ <!-- attached to Maven test phase -->
+ <execution>
+ <id>report</id>
+ <phase>test</phase>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>controller</id>
+ <configuration>
+ <footer>Controller Tier</footer>
+ <title>U-Fund API Controller Tier Test Coverage</title>
+ <outputDirectory>target/site/jacoco/controller</outputDirectory>
+ </configuration>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>persistence</id>
+ <configuration>
+ <footer>Persistence Tier</footer>
+ <title>U-Fund API Persistence Tier Test Coverage</title>
+ <outputDirectory>target/site/jacoco/persistence</outputDirectory>
+ </configuration>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>model</id>
+ <configuration>
+ <footer>Model Tier</footer>
+ <title>U-Fund API Model Tier Test Coverage</title>
+ <outputDirectory>target/site/jacoco/model</outputDirectory>
+ </configuration>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>jacoco-check</id>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ <configuration>
+ <rules>
+ <rule>
+ <element>BUNDLE</element>
+ <limits>
+ <limit>
+ <counter>INSTRUCTION</counter>
+ <value>COVEREDRATIO</value>
+ <minimum>0.90</minimum>
+ </limit>
+ </limits>
+ </rule>
+ </rules>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
</project> \ No newline at end of file
diff --git a/src/test/java/design/HelloWorldTest.java b/src/test/java/design/HelloWorldTest.java
deleted file mode 100644
index 98238d7..0000000
--- a/src/test/java/design/HelloWorldTest.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package design;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-import org.junit.jupiter.api.Test;
-
-public class HelloWorldTest {
- @Test
- public void helloWorld() {
- assertEquals("Hello, World!", "Hello, World!");
- }
-}
diff --git a/src/test/java/design/model/ClubTest.java b/src/test/java/design/model/ClubTest.java
new file mode 100644
index 0000000..9cbfa87
--- /dev/null
+++ b/src/test/java/design/model/ClubTest.java
@@ -0,0 +1,61 @@
+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;
+
+/** Unit Tests for the Club class.
+ * @author Willem Dalton
+ **/
+@Tag("Model-tier")
+public class ClubTest {
+
+ @Test
+ void testConstructor()
+ {
+ Club testClub = new Club(0, "John Doe", "The Slammer", ClubType.DRIVER);
+
+ assertEquals(0, testClub.getId());
+ assertEquals("John Doe", testClub.getManufacture());
+ assertEquals("The Slammer", testClub.getNickname());
+ assertEquals(ClubType.DRIVER, testClub.getClubType());
+ }
+
+ @Test
+ void testGetClubType()
+ {
+ Club testClub = new Club(0, "John Doe", "The Slammer", ClubType.DRIVER);
+ assertEquals(ClubType.DRIVER, testClub.getClubType());
+ }
+
+ @Test
+ void testGetNickname()
+ {
+ Club testClub = new Club(0, "John Doe", "The Slammer", ClubType.DRIVER);
+ assertEquals("The Slammer", testClub.getNickname());
+ }
+
+ @Test
+ void testGetManufacture()
+ {
+ Club testClub = new Club(0, "John Doe", "The Slammer", ClubType.DRIVER);
+ assertEquals("John Doe", testClub.getManufacture());
+ }
+
+ @Test
+ void testGetId()
+ {
+ Club testClub = new Club(0, "John Doe", "The Slammer", ClubType.DRIVER);
+ assertEquals(0, testClub.getId());
+ }
+
+ @Test
+ void testToString()
+ {
+ Club testClub = new Club(0, "John Doe", "The Slammer", ClubType.DRIVER);
+ String expectedString = "#0 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
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());
+ }
+
+
+
+}
+