aboutsummaryrefslogtreecommitdiff
path: root/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/CupboardFileDAOTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/CupboardFileDAOTest.java')
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/CupboardFileDAOTest.java74
1 files changed, 47 insertions, 27 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..d83e825 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,42 @@ 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", 0, 100, Need.GoalType.MONETARY),
+ new Need("two", 1, 100, Need.GoalType.MONETARY),
+ 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() {
- 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 actualNeed = cupboardFileDao.addNeed(newNeed);
@@ -79,6 +78,15 @@ 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];
@@ -91,4 +99,16 @@ public class CupboardFileDAOTest {
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", 20, 100, GoalType.PHYSICAL);
+
+ Need actualNeed = cupboardFileDao.updateNeed(updatedNeed);
+ assertNull(actualNeed);
+ }
+
}