From bb9ce55cb5b55a6aaed2399e39a01d68f2491ce3 Mon Sep 17 00:00:00 2001 From: sowgro Date: Thu, 6 Mar 2025 21:41:39 -0500 Subject: Push current changes (working on documentation and tests) --- .../ufundapi/persistence/CupboardFileDAOTest.java | 107 +++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/CupboardFileDAOTest.java (limited to 'ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/CupboardFileDAOTest.java') 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 new file mode 100644 index 0000000..e554f9d --- /dev/null +++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/CupboardFileDAOTest.java @@ -0,0 +1,107 @@ +package com.ufund.api.ufundapi.persistence; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +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.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.File; +import java.io.IOException; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.ufund.api.ufundapi.model.Need; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +import com.ufund.api.ufundapi.model.Need.GoalType; + +@Tag("Persistence-tier") +public class CupboardFileDAOTest { + CupboardFileDAO cupboardFileDao; + Need[] testNeeds; + ObjectMapper mockObjectMapper; + + @BeforeEach + public void setupCupboardFileDao() throws IOException { + mockObjectMapper = mock(ObjectMapper.class); + testNeeds = new Need[3]; + testNeeds[0] = new Need("one", 0, 100, Need.GoalType.MONETARY); + testNeeds[1] = new Need("two", 1, 100, Need.GoalType.MONETARY); + testNeeds[2] = new Need("three", 2, 100, Need.GoalType.MONETARY); + // 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() throws IOException { + Need[] needs = cupboardFileDao.getNeeds(); + assertEquals(needs.length,testNeeds.length); + assertEquals(needs[0].getName(), testNeeds[0].getName()); + } + + @Test + public void GetNeedTest() throws IOException { + Need need1 = cupboardFileDao.getNeed(0); + + assertEquals(testNeeds[0], need1); + } + + @Test + public void Fet() throws IOException { + String targetName1 = "one"; + String targetName2 = "two"; + + Need need1 = cupboardFileDao.findNeeds(targetName1)[0]; + Need need2 = cupboardFileDao.findNeeds(targetName2)[0]; + + assertEquals(testNeeds[0], need1); + assertEquals(testNeeds[1], need2); + } + + @Test + public void CreateNeedTest() throws IOException { + Need newNeed = new Need("sea urchin hats", 3, 100, GoalType.PHYSICAL); + + + Need actualNeed = cupboardFileDao.createNeed(newNeed); + + assertNotNull(actualNeed); + + assertEquals(actualNeed.getName(), newNeed.getName()); + } + + @Test + public void DeleteNeedTest() throws IOException { + Need undeletedNeed = cupboardFileDao.getNeed(0); + assertNotNull(undeletedNeed); + + boolean isDeleted = cupboardFileDao.deleteNeed(0); + assertTrue(isDeleted); + + Need deletedNeed = cupboardFileDao.getNeed(0); + assertNull(deletedNeed); + } + + @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 actualNeed = cupboardFileDao.updateNeed(updatedNeed); + assertEquals(actualNeed, updatedNeed); + assertNotEquals(actualNeed, unupdatedNeed); + } + +} -- cgit v1.2.3 From 30c301ed050cb0deeb9755b28300c311610b7f98 Mon Sep 17 00:00:00 2001 From: sowgro Date: Thu, 13 Mar 2025 20:47:44 -0400 Subject: Fix and clean up remaining tests --- .../ufundapi/persistence/CupboardFileDAOTest.java | 24 ++++++---------------- 1 file changed, 6 insertions(+), 18 deletions(-) (limited to 'ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/CupboardFileDAOTest.java') 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 e554f9d..cbfa30c 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 @@ -42,37 +42,25 @@ public class CupboardFileDAOTest { } @Test - public void GetNeedsTest() throws IOException { + public void getNeedsTest() { Need[] needs = cupboardFileDao.getNeeds(); assertEquals(needs.length,testNeeds.length); assertEquals(needs[0].getName(), testNeeds[0].getName()); } @Test - public void GetNeedTest() throws IOException { + public void getNeedTest() { Need need1 = cupboardFileDao.getNeed(0); assertEquals(testNeeds[0], need1); } @Test - public void Fet() throws IOException { - String targetName1 = "one"; - String targetName2 = "two"; - - Need need1 = cupboardFileDao.findNeeds(targetName1)[0]; - Need need2 = cupboardFileDao.findNeeds(targetName2)[0]; - - assertEquals(testNeeds[0], need1); - assertEquals(testNeeds[1], need2); - } - - @Test - public void CreateNeedTest() throws IOException { + public void createNeedTest() throws IOException { Need newNeed = new Need("sea urchin hats", 3, 100, GoalType.PHYSICAL); - Need actualNeed = cupboardFileDao.createNeed(newNeed); + Need actualNeed = cupboardFileDao.addNeed(newNeed); assertNotNull(actualNeed); @@ -80,7 +68,7 @@ public class CupboardFileDAOTest { } @Test - public void DeleteNeedTest() throws IOException { + public void deleteNeedTest() throws IOException { Need undeletedNeed = cupboardFileDao.getNeed(0); assertNotNull(undeletedNeed); @@ -92,7 +80,7 @@ public class CupboardFileDAOTest { } @Test - public void UpdateNeedTest() throws IOException { + public void updateNeedTest() throws IOException { Need[] needs = cupboardFileDao.getNeeds(); Need unupdatedNeed = needs[needs.length - 1]; assertNotNull(unupdatedNeed); -- cgit v1.2.3 From a50b260a6f33dbe78e7ac2aa80011b0a2397f3bc Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Fri, 14 Mar 2025 19:50:10 -0400 Subject: Fixed imports --- .../api/ufundapi/persistence/CupboardFileDAOTest.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/CupboardFileDAOTest.java') 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 cbfa30c..7888084 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 @@ -1,23 +1,21 @@ package com.ufund.api.ufundapi.persistence; +import java.io.File; +import java.io.IOException; + import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; 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 org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import java.io.File; -import java.io.IOException; - import com.fasterxml.jackson.databind.ObjectMapper; import com.ufund.api.ufundapi.model.Need; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; - import com.ufund.api.ufundapi.model.Need.GoalType; @Tag("Persistence-tier") -- cgit v1.2.3