diff options
author | benal01 <bja4245@rit.edu> | 2025-04-01 09:34:36 -0400 |
---|---|---|
committer | benal01 <bja4245@rit.edu> | 2025-04-01 09:34:36 -0400 |
commit | 7ed26c5ee7171a502f6f8527fc55de2bb77eab3b (patch) | |
tree | 2046e58c146097aac21c9e352771420c31df6589 /ufund-api/src/test/java/com/ufund/api/ufundapi/persistence | |
parent | ef46ddd082bb91d0262363536d46fe3eb4da47be (diff) | |
parent | d8330f1ac85b26d08ca4df5ce3875078d7b4f47f (diff) | |
download | JellySolutions-7ed26c5ee7171a502f6f8527fc55de2bb77eab3b.tar.gz JellySolutions-7ed26c5ee7171a502f6f8527fc55de2bb77eab3b.tar.bz2 JellySolutions-7ed26c5ee7171a502f6f8527fc55de2bb77eab3b.zip |
Merge branch 'main' of https://github.com/RIT-SWEN-261-02/team-project-2245-swen-261-02-2b-jellysolutions
Diffstat (limited to 'ufund-api/src/test/java/com/ufund/api/ufundapi/persistence')
3 files changed, 74 insertions, 38 deletions
diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/CupboardFileDAOTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/CupboardFileDAOTest.java index f786a8c..76a8b40 100644 --- a/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/CupboardFileDAOTest.java +++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/CupboardFileDAOTest.java @@ -4,6 +4,7 @@ import java.io.File; import java.io.IOException; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; @@ -20,44 +21,40 @@ import com.ufund.api.ufundapi.model.Need.GoalType; @Tag("Persistence-tier") public class CupboardFileDAOTest { - private CupboardFileDAO cupboardFileDao; - private Need[] testNeeds; - private ObjectMapper mockObjectMapper; + private CupboardFileDAO cupboardFileDao; + private Need[] testNeeds; @BeforeEach - public void setupCupboardFileDao() throws IOException { - mockObjectMapper = mock(ObjectMapper.class); - testNeeds = new Need[]{ - new Need("one", 0, 100, Need.GoalType.MONETARY), - new Need("two", 1, 100, Need.GoalType.MONETARY), - new Need("three", 2, 100, Need.GoalType.MONETARY) + public void setupCupboardFileDao() throws IOException { + ObjectMapper mockObjectMapper = mock(ObjectMapper.class); + testNeeds = new Need[] { + new Need("one", "", "Atlantis", 0, 100, Need.GoalType.MONETARY, false, ""), + new Need("two", "", "Atlantis", 1, 100, Need.GoalType.MONETARY, false, ""), + new Need("three", "", "Atlantis", 2, 100, Need.GoalType.MONETARY, false, "") }; - // When the object mapper is supposed to read from the file - // the mock object mapper will return the hero array above - when(mockObjectMapper - .readValue(new File("doesnt_matter.txt"),Need[].class)) - .thenReturn(testNeeds); - cupboardFileDao = new CupboardFileDAO("doesnt_matter.txt",mockObjectMapper); - } - - @Test - public void getNeedsTest() { - Need[] needs = cupboardFileDao.getNeeds(); - assertEquals(needs.length,testNeeds.length); + // When the object mapper is supposed to read from the file + // the mock object mapper will return the hero array above + when(mockObjectMapper.readValue(new File("doesnt_matter.txt"), Need[].class)).thenReturn(testNeeds); + cupboardFileDao = new CupboardFileDAO("doesnt_matter.txt", mockObjectMapper); + } + + @Test + public void getNeedsTest() { + Need[] needs = cupboardFileDao.getNeeds(); + assertEquals(needs.length, testNeeds.length); assertEquals(needs[0].getName(), testNeeds[0].getName()); - } + } - @Test - public void getNeedTest() { + @Test + public void getNeedTest() { Need need1 = cupboardFileDao.getNeed(0); - + assertEquals(testNeeds[0], need1); - } + } @Test public void createNeedTest() throws IOException { - Need newNeed = new Need("sea urchin hats", 3, 100, GoalType.PHYSICAL); - + Need newNeed = new Need("sea urchin hats", "", "Atlantis", 100, GoalType.PHYSICAL, false, ""); Need actualNeed = cupboardFileDao.addNeed(newNeed); @@ -79,16 +76,37 @@ public class CupboardFileDAOTest { } @Test + public void deleteNeedTestFail() throws IOException { + Need undeletedNeed = cupboardFileDao.getNeed(0); + assertNotNull(undeletedNeed); + + boolean nullNeed = cupboardFileDao.deleteNeed(20); + assertFalse(nullNeed); + } + + @Test public void updateNeedTest() throws IOException { Need[] needs = cupboardFileDao.getNeeds(); Need unupdatedNeed = needs[needs.length - 1]; assertNotNull(unupdatedNeed); - Need updatedNeed = new Need("sequin sea urchin hats", 2, 100, GoalType.PHYSICAL); + Need updatedNeed = new Need("sequin sea urchin hats", "", "Atlantis", 100, GoalType.PHYSICAL, false, ""); Need actualNeed = cupboardFileDao.updateNeed(updatedNeed); assertEquals(actualNeed, updatedNeed); assertNotEquals(actualNeed, unupdatedNeed); } + @Test + public void updateNeedTestFail() throws IOException { + Need[] needs = cupboardFileDao.getNeeds(); + Need unupdatedNeed = needs[needs.length - 1]; + assertNotNull(unupdatedNeed); + + Need updatedNeed = new Need("sequin sea urchin hats", "", "Atlantis", 5, 100, GoalType.PHYSICAL, false, ""); + + Need actualNeed = cupboardFileDao.updateNeed(updatedNeed); + assertNull(actualNeed); + } + } diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserAuthFileDAOTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserAuthFileDAOTest.java index f7db747..a4842c5 100644 --- a/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserAuthFileDAOTest.java +++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserAuthFileDAOTest.java @@ -2,6 +2,7 @@ package com.ufund.api.ufundapi.persistence; import java.io.File; import java.io.IOException; +import java.time.LocalDateTime; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -18,22 +19,21 @@ import com.ufund.api.ufundapi.model.UserAuth; public class UserAuthFileDAOTest { private UserAuthFIleDAO userAuthFIleDAO; - private ObjectMapper mockObjectMapper; private UserAuth[] userAuths; @BeforeEach public void setupUserAuthFileDAO() throws IOException { - mockObjectMapper = mock(ObjectMapper.class); + ObjectMapper mockObjectMapper = mock(ObjectMapper.class); userAuths = new UserAuth[]{ - new UserAuth("123", "Phil", null), - new UserAuth("456", "Bob", null), - new UserAuth("789", "Steve", null) + new UserAuth("123", "Phil", LocalDateTime.MAX), + new UserAuth("456", "Bob", LocalDateTime.MAX), + new UserAuth("789", "Steve", LocalDateTime.MAX) }; // When the object mapper is supposed to read from the file // the mock object mapper will return the hero array above when(mockObjectMapper - .readValue(new File("doesnt_matter.txt"),UserAuth[].class)) + .readValue(new File("doesnt_matter.txt"),UserAuth[].class)) .thenReturn(userAuths); userAuthFIleDAO = new UserAuthFIleDAO(mockObjectMapper, "doesnt_matter.txt"); } @@ -43,18 +43,18 @@ public class UserAuthFileDAOTest { String key = "123"; UserAuth auth = userAuthFIleDAO.getUserAuth(key); - assertEquals(auth, userAuths[0]); + assertEquals(userAuths[0], auth); } @Test - public void addUserAuthTest() throws IOException { + public void addUserAuthTest() { UserAuth auth = new UserAuth("999", "Fish", null); assertDoesNotThrow(() -> userAuthFIleDAO.addUserAuth(auth)); } @Test - public void removeUserAuthTest() throws IOException { + public void removeUserAuthTest() { String key = "123"; assertDoesNotThrow(() -> userAuthFIleDAO.removeUserAuth(key)); diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserFileDAOTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserFileDAOTest.java index 9361188..2ee0fc0 100644 --- a/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserFileDAOTest.java +++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserFileDAOTest.java @@ -39,6 +39,24 @@ public class UserFileDAOTest { userFileDAO = new UserFileDAO("doesnt_matter.txt",mockObjectMapper); } + @Test + public void addUsersTest() throws IOException { + User user = User.create("Name", "Pass"); + + User addedUser = userFileDAO.addUser(user); + + assertEquals(addedUser, user); + } + + @Test + public void addUsersTestFail() throws IOException { + User user = User.create("bob", "test"); + + User existingUser = userFileDAO.addUser(user); + + assertEquals(existingUser, testUsers[0]); + } + @Test public void getUsersTest() { User[] users = userFileDAO.getUsers(); |