diff options
Diffstat (limited to 'ufund-api/src/test/java')
-rw-r--r-- | ufund-api/src/test/java/com/ufund/api/ufundapi/model/NeedTest.java | 19 | ||||
-rw-r--r-- | ufund-api/src/test/java/com/ufund/api/ufundapi/service/CupboardServiceTest.java | 57 |
2 files changed, 63 insertions, 13 deletions
diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/model/NeedTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/model/NeedTest.java index 772af5c..6b4ddfc 100644 --- a/ufund-api/src/test/java/com/ufund/api/ufundapi/model/NeedTest.java +++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/model/NeedTest.java @@ -14,13 +14,10 @@ public class NeedTest { public void createNeed() { String name = "Jellyfish"; - int id = 0; double maxGoal = 100.00; GoalType type = GoalType.MONETARY; - Need need = new Need(name, id, maxGoal, type); - + Need need = new Need(name, type, maxGoal); assertNotNull(need); - } @Test @@ -29,7 +26,7 @@ public class NeedTest { int id = 0; double maxGoal = 100.00; GoalType type = GoalType.MONETARY; - Need need = new Need(name, id, maxGoal, type); + Need need = new Need(name, type, maxGoal); assertEquals(name, need.getName()); @@ -41,10 +38,9 @@ public class NeedTest { @Test public void testCurrentGoal() { String name = "Jellyfish"; - int id = 0; double maxGoal = 100.00; GoalType type = GoalType.MONETARY; - Need need = new Need(name, id, maxGoal, type); + Need need = new Need(name, type, maxGoal); double current = 0.00; need.setCurrent(current); @@ -64,10 +60,9 @@ public class NeedTest { public void testFilterAttributes() { String name = "Jellyfish"; - int id = 0; double maxGoal = 100.00; GoalType type = GoalType.MONETARY; - Need need = new Need(name, id, maxGoal, type); + Need need = new Need(name, type, maxGoal); String[] filterAttributes = {"seaweed", "divers", "pacific", "plankton"}; @@ -80,10 +75,9 @@ public class NeedTest { public void testSetMaxGoal() { String name = "Jellyfish"; - int id = 0; double maxGoal = 100.00; GoalType type = GoalType.MONETARY; - Need need = new Need(name, id, maxGoal, type); + Need need = new Need(name, type, maxGoal); double newGoal = 200.00; need.setMaxGoal(newGoal); @@ -96,10 +90,9 @@ public class NeedTest { public void testSetName() { String name = "Jellyfish"; - int id = 0; double maxGoal = 100.00; GoalType type = GoalType.MONETARY; - Need need = new Need(name, id, maxGoal, type); + Need need = new Need(name, type, maxGoal); String newName = "TESTINGFUN"; need.setName(newName); diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/service/CupboardServiceTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/service/CupboardServiceTest.java new file mode 100644 index 0000000..09d7c89 --- /dev/null +++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/service/CupboardServiceTest.java @@ -0,0 +1,57 @@ +package com.ufund.api.ufundapi.service; + +import java.io.IOException; +import java.util.TreeMap; + +import static org.junit.jupiter.api.Assertions.assertEquals; +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 static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import com.ufund.api.ufundapi.DuplicateKeyException; +import com.ufund.api.ufundapi.model.Need; +import com.ufund.api.ufundapi.model.Need.GoalType; +import com.ufund.api.ufundapi.persistence.CupboardDAO; + +@Tag("Service-tier") +public class CupboardServiceTest { + + private CupboardDAO mockCupboardDAO; + private AuthService mockAuthService; + private CupboardService cupboardService; + + @BeforeEach + public void setupCupboardService() throws IOException { + mockCupboardDAO = mock(CupboardDAO.class); + mockAuthService = mock(AuthService.class); + cupboardService = new CupboardService(mockCupboardDAO); + + } + + @Test + public void testCreateNeed() throws IOException, DuplicateKeyException { + // Setup + String name = "Jellyfish"; + double maxGoal = 100.00; + int id = 0; + GoalType type = GoalType.MONETARY; + Need need = new Need(name, type, maxGoal); + + // When the same id is passed in, our mock User DAO will return the User object + when(mockCupboardDAO.getNeed(id)).thenReturn(need); + when(mockCupboardDAO.addNeed(need)).thenReturn(need); + when(mockCupboardDAO.getNeeds()).thenReturn(new Need[0]); + + + // Invoke + Need response = cupboardService.createNeed(name, maxGoal, type); + + // Analyze + assertNotNull(response); + assertEquals(need, response); + } + +} |