diff options
6 files changed, 110 insertions, 17 deletions
diff --git a/data/personaldb.json b/data/personaldb.json index 9b9709d..3a08057 100644 --- a/data/personaldb.json +++ b/data/personaldb.json @@ -61,8 +61,8 @@ "clubUsed": 2 } ], - "swingCount": 3, - "distance": 106 + "distance": 106, + "swingCount": 3 }, { "holeNumber": 2, @@ -76,17 +76,17 @@ "clubUsed": 1 } ], - "swingCount": 2, - "distance": 1002 + "distance": 1002, + "swingCount": 2 } ], "currentHoleIndex": 2, - "totalSwings": 5, "totalDistance": 1108.0, "currentHole": { "number": 3, "par": 4 - } + }, + "totalSwings": 5 }, { "course": 1, @@ -112,20 +112,19 @@ "clubUsed": 1 } ], - "swingCount": 1, - "distance": 204 + "distance": 204, + "swingCount": 1 } ], "currentHoleIndex": 9, - "totalSwings": 1, "totalDistance": 204.0, "currentHole": { "number": 10, "par": 3 - } + }, + "totalSwings": 1 } - ], - "invites": [] + ] }, { "clubs": [], @@ -134,7 +133,6 @@ "passwordHash": 389416948, "fullName": "tyler f", "courses": [], - "rounds": [], - "invites": [] + "rounds": [] } ]
\ No newline at end of file diff --git a/src/main/java/design/persistence/JSONPersonalDatabase.java b/src/main/java/design/persistence/JSONPersonalDatabase.java index 30c280a..ed83ef6 100644 --- a/src/main/java/design/persistence/JSONPersonalDatabase.java +++ b/src/main/java/design/persistence/JSONPersonalDatabase.java @@ -29,6 +29,11 @@ public class JSONPersonalDatabase implements PersonalDatabase { return INSTANCE; } + static JSONPersonalDatabase testInstance(String filename) { + INSTANCE = new JSONPersonalDatabase(filename); + return INSTANCE; + } + private final Map<String, Golfer> cache; private final ObjectMapper mapper; private final File file; diff --git a/src/test/java/design/model/coursesearch/CourseListTest.java b/src/test/java/design/model/coursesearch/CourseListTest.java index 5969486..6bc5529 100644 --- a/src/test/java/design/model/coursesearch/CourseListTest.java +++ b/src/test/java/design/model/coursesearch/CourseListTest.java @@ -13,7 +13,7 @@ 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") 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 60a8735..35fa335 100644 --- a/src/test/java/design/model/coursesearch/sortStrategyTest.java +++ b/src/test/java/design/model/coursesearch/sortStrategyTest.java @@ -11,11 +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 **/ @Tag("Model-tier") -public class sortStrategyTest { +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); diff --git a/src/test/java/design/persistence/JSONPersonalDatabaseTest.java b/src/test/java/design/persistence/JSONPersonalDatabaseTest.java new file mode 100644 index 0000000..55270c4 --- /dev/null +++ b/src/test/java/design/persistence/JSONPersonalDatabaseTest.java @@ -0,0 +1,63 @@ +package design.persistence; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +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")); + } +} |
