aboutsummaryrefslogtreecommitdiff
path: root/ufund-api/src/test/java/com/ufund/api/ufundapi/service/CupboardServiceTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'ufund-api/src/test/java/com/ufund/api/ufundapi/service/CupboardServiceTest.java')
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/service/CupboardServiceTest.java85
1 files changed, 49 insertions, 36 deletions
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
index 05ea2e8..f3cbc23 100644
--- 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
@@ -36,16 +36,18 @@ public class CupboardServiceTest {
public void testCreateNeed() throws IOException, DuplicateKeyException {
// Setup
String name = "Jellyfish";
- double maxGoal = 100.00;
- GoalType type = GoalType.MONETARY;
- Need need = new Need(name, type, maxGoal);
+ String location = "Atlantis";
+ double maxGoal = 100;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ var need = new Need(name, location, maxGoal, type, urgent);
// When the same id is passed in, our mock User DAO will return the User object
when(mockCupboardDAO.addNeed(any())).thenReturn(need);
when(mockCupboardDAO.getNeeds()).thenReturn(new Need[0]);
// Invoke
- Need response = cupboardService.createNeed(name, maxGoal, type);
+ Need response = cupboardService.createNeed(name, location, maxGoal, type, urgent);
// Analyze
assertNotNull(response);
@@ -56,9 +58,11 @@ public class CupboardServiceTest {
public void testCreateNeedBadGoal() throws IOException {
// Setup
String name = "Jellyfish";
- double maxGoal = -100.00;
- GoalType type = GoalType.MONETARY;
- Need need = new Need(name, type, maxGoal);
+ String location = "Atlantis";
+ double maxGoal = -100.0;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ var need = new Need(name, location, maxGoal, type, urgent);
// When the same id is passed in, our mock User DAO will return the User object
when(mockCupboardDAO.addNeed(any())).thenReturn(need);
@@ -69,16 +73,18 @@ public class CupboardServiceTest {
// Analyze
assertThrows(IllegalArgumentException.class, () ->
- cupboardService.createNeed(name, maxGoal, type));
+ cupboardService.createNeed(name, location, maxGoal, type, urgent));
}
@Test
public void testCreateNeedDuplicate() throws IOException {
// Setup
String name = "Jellyfish";
- double maxGoal = 100.00;
- GoalType type = GoalType.MONETARY;
- Need need = new Need(name, type, maxGoal);
+ String location = "Atlantis";
+ double maxGoal = 100.0;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ var need = new Need(name, location, maxGoal, type, urgent);
Need[] needs = { need };
// When the same id is passed in, our mock User DAO will return the User object
@@ -90,16 +96,18 @@ public class CupboardServiceTest {
// Analyze
assertThrows(DuplicateKeyException.class, () ->
- cupboardService.createNeed(name, maxGoal, type));
+ cupboardService.createNeed(name, location, maxGoal, type, urgent));
}
@Test
public void testSearchNeeds() throws IOException {
// Setup
String name = "Jellyfish";
- double maxGoal = 100.00;
- GoalType type = GoalType.MONETARY;
- Need need = new Need(name, type, maxGoal);
+ String location = "Atlantis";
+ double maxGoal = 100.0;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ var need = new Need(name, location, maxGoal, type, urgent);
Need[] needs = { need };
// When the same id is passed in, our mock User DAO will return the User object
@@ -117,9 +125,11 @@ public class CupboardServiceTest {
public void testSearchNeedsFail() throws IOException {
// Setup
String name = "Jellyfish";
- double maxGoal = 100.00;
- GoalType type = GoalType.MONETARY;
- Need need = new Need(name, type, maxGoal);
+ String location = "Atlantis";
+ double maxGoal = 100.0;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ var need = new Need(name, location, maxGoal, type, urgent);
Need[] needs = { need };
// When the same id is passed in, our mock User DAO will return the User object
@@ -136,16 +146,17 @@ public class CupboardServiceTest {
public void testGetNeed() throws IOException {
// Setup
String name = "Jellyfish";
- double maxGoal = 100.00;
- int id = 0;
- GoalType type = GoalType.MONETARY;
- Need need = new Need(name, type, maxGoal);
+ String location = "Atlantis";
+ double maxGoal = 100.0;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ var need = new Need(name, location, maxGoal, type, urgent);
// When the same id is passed in, our mock User DAO will return the User object
- when(mockCupboardDAO.getNeed(id)).thenReturn(need);
+ when(mockCupboardDAO.getNeed(0)).thenReturn(need);
// Invoke
- Need response = cupboardService.getNeed(id);
+ Need response = cupboardService.getNeed(need.getId());
// Analyze
assertEquals(need, response);
@@ -155,17 +166,18 @@ public class CupboardServiceTest {
public void testUpdateNeed() throws IOException {
// Setup
String name = "Jellyfish";
- double maxGoal = 100.00;
- int id = 0;
- GoalType type = GoalType.MONETARY;
- Need need = new Need(name, type, maxGoal);
- Need newNeed = new Need("Octopus", type, maxGoal);
+ String location = "Atlantis";
+ double maxGoal = 100.0;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ Need need = new Need(name, location, maxGoal, type, urgent);
+ Need newNeed = new Need("Octopus", location, maxGoal, type, urgent);
// When the same id is passed in, our mock User DAO will return the User object
when(mockCupboardDAO.updateNeed(any())).thenReturn(newNeed);
// Invoke
- Need response = cupboardService.updateNeed(newNeed, id);
+ Need response = cupboardService.updateNeed(newNeed, need.getId());
// Analyze
assertEquals(newNeed, response);
@@ -175,17 +187,18 @@ public class CupboardServiceTest {
public void testDeleteNeed() throws IOException {
// Setup
String name = "Jellyfish";
- double maxGoal = 100.00;
- int id = 0;
- GoalType type = GoalType.MONETARY;
- Need need = new Need(name, type, maxGoal);
+ String location = "Atlantis";
+ double maxGoal = 100.0;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ Need need = new Need(name, location, maxGoal, type, urgent);
// When the same id is passed in, our mock User DAO will return the User object
- when(mockCupboardDAO.deleteNeed(id)).thenReturn(true);
+ when(mockCupboardDAO.deleteNeed(0)).thenReturn(true);
when(mockCupboardDAO.getNeeds()).thenReturn(new Need[0]);
// Invoke
- boolean response = cupboardService.deleteNeed(id);
+ boolean response = cupboardService.deleteNeed(need.getId());
Need[] responseNeeds = cupboardService.getNeeds();
// Analyze