aboutsummaryrefslogtreecommitdiff
path: root/ufund-api/src/test/java/com/ufund/api/ufundapi/controller
diff options
context:
space:
mode:
Diffstat (limited to 'ufund-api/src/test/java/com/ufund/api/ufundapi/controller')
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java82
1 files changed, 59 insertions, 23 deletions
diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java
index 75dbf84..15353bf 100644
--- a/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java
+++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java
@@ -43,16 +43,20 @@ public class CupboardControllerTest {
int maxGoal = 100;
GoalType type = Need.GoalType.MONETARY;
boolean urgent = false;
- var need = new Need(name, location, maxGoal, type, urgent);
- when(mockCupboardService.createNeed(name, "Atlantis", maxGoal, type, false)).thenReturn(need);
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
+ when(mockCupboardService.createNeed(name, image, location, maxGoal, type, urgent, description)).thenReturn(need);
Map<String, Object> needMap = Map.ofEntries(
entry("name", "Test"),
+ entry("image", ""),
entry("location", "Atlantis"),
- entry("maxGoal", 100.0),
+ entry("maxGoal", 100),
entry("type", "MONETARY"),
- entry("urgent", false)
+ entry("urgent", false),
+ entry("description", "")
);
var res = cupboardController.createNeed(needMap, key);
@@ -63,14 +67,16 @@ public class CupboardControllerTest {
@Test
public void createNeedBadMaxGoal() throws IOException, DuplicateKeyException {
- when(mockCupboardService.createNeed("Test", "Atlantis", -100, Need.GoalType.MONETARY, false)).thenThrow(new IllegalArgumentException());
+ when(mockCupboardService.createNeed("Test", "", "Atlantis", -100, Need.GoalType.MONETARY, false, "")).thenThrow(new IllegalArgumentException());
Map<String, Object> needMap = Map.ofEntries(
entry("name", "Test"),
+ entry("image", ""),
entry("location", "Atlantis"),
entry("maxGoal", -100),
entry("type", "MONETARY"),
- entry("urgent", false)
+ entry("urgent", false),
+ entry("description", "")
);
var res = cupboardController.createNeed(needMap, key);
@@ -80,14 +86,16 @@ public class CupboardControllerTest {
@Test
public void createNeedIOException() throws IOException, DuplicateKeyException {
- when(mockCupboardService.createNeed("Test", "Atlantis", 100, Need.GoalType.MONETARY, false)).thenThrow(new IOException());
+ when(mockCupboardService.createNeed("Test", "", "Atlantis", 100, Need.GoalType.MONETARY, false, "")).thenThrow(new IOException());
Map<String, Object> needMap = Map.ofEntries(
entry("name", "Test"),
+ entry("image", ""),
entry("location", "Atlantis"),
entry("maxGoal", 100),
entry("type", "MONETARY"),
- entry("urgent", false)
+ entry("urgent", false),
+ entry("description", "")
);
var res = cupboardController.createNeed(needMap, key);
@@ -97,14 +105,16 @@ public class CupboardControllerTest {
@Test
public void createNeedConflict() throws IOException, DuplicateKeyException {
- when(mockCupboardService.createNeed("Test", "Atlantis", 100, Need.GoalType.MONETARY, false)).thenThrow(new DuplicateKeyException(""));
+ when(mockCupboardService.createNeed("Test", "", "Atlantis", 100, Need.GoalType.MONETARY, false, "")).thenThrow(new DuplicateKeyException(""));
Map<String, Object> needMap = Map.ofEntries(
entry("name", "Test"),
+ entry("image", ""),
entry("location", "Atlantis"),
entry("maxGoal", 100),
entry("type", "MONETARY"),
- entry("urgent", false)
+ entry("urgent", false),
+ entry("description", "")
);
var res = cupboardController.createNeed(needMap, key);
@@ -136,7 +146,9 @@ public class CupboardControllerTest {
int maxGoal = 100;
GoalType type = Need.GoalType.MONETARY;
boolean urgent = false;
- var need = new Need(name, location, maxGoal, type, urgent);
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
when(mockCupboardService.getNeeds()).thenReturn(new Need[]{need});
var res = cupboardController.getNeeds();
@@ -171,7 +183,9 @@ public class CupboardControllerTest {
int maxGoal = 100;
GoalType type = Need.GoalType.MONETARY;
boolean urgent = false;
- var need = new Need(name, location, maxGoal, type, urgent);
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
when(mockCupboardService.searchNeeds("Na")).thenReturn(new Need[]{need});
var res = cupboardController.searchNeeds("Na");
@@ -206,7 +220,9 @@ public class CupboardControllerTest {
int maxGoal = 100;
GoalType type = Need.GoalType.MONETARY;
boolean urgent = false;
- var need = new Need(name, location, maxGoal, type, urgent);
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
when(mockCupboardService.getNeed(need.getId())).thenReturn(need);
var res = cupboardController.getNeed(need.getId());
@@ -222,7 +238,9 @@ public class CupboardControllerTest {
int maxGoal = 100;
GoalType type = Need.GoalType.MONETARY;
boolean urgent = false;
- var need = new Need(name, location, maxGoal, type, urgent);
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
when(mockCupboardService.getNeed(need.getId())).thenThrow(new IOException());
var res = cupboardController.getNeed(need.getId());
@@ -237,7 +255,9 @@ public class CupboardControllerTest {
int maxGoal = 100;
GoalType type = Need.GoalType.MONETARY;
boolean urgent = false;
- var need = new Need(name, location, maxGoal, type, urgent);
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
when(mockCupboardService.getNeed(need.getId())).thenReturn(null);
var res = cupboardController.getNeed(need.getId());
@@ -253,7 +273,9 @@ public class CupboardControllerTest {
int maxGoal = 100;
GoalType type = Need.GoalType.MONETARY;
boolean urgent = false;
- var need = new Need(name, location, maxGoal, type, urgent);
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
when(mockCupboardService.updateNeed(need, 1)).thenReturn(need);
var res = cupboardController.updateNeed(need, 1, key);
@@ -269,7 +291,9 @@ public class CupboardControllerTest {
int maxGoal = 100;
GoalType type = Need.GoalType.MONETARY;
boolean urgent = false;
- var need = new Need(name, location, maxGoal, type, urgent);
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
when(mockCupboardService.updateNeed(need, 1)).thenThrow(new IOException());
var res = cupboardController.updateNeed(need, 1, key);
@@ -284,7 +308,9 @@ public class CupboardControllerTest {
int maxGoal = 100;
GoalType type = Need.GoalType.MONETARY;
boolean urgent = false;
- var need = new Need(name, location, maxGoal, type, urgent);
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
when(mockCupboardService.updateNeed(need, 1)).thenReturn(null);
var res = cupboardController.updateNeed(need, 1, key);
@@ -299,7 +325,9 @@ public class CupboardControllerTest {
int maxGoal = 100;
GoalType type = Need.GoalType.MONETARY;
boolean urgent = false;
- var need = new Need(name, location, maxGoal, type, urgent);
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
when(mockCupboardService.updateNeed(need, 1)).thenThrow(new IllegalArgumentException());
var res = cupboardController.updateNeed(need, 1, key);
@@ -314,7 +342,9 @@ public class CupboardControllerTest {
int maxGoal = 100;
GoalType type = Need.GoalType.MONETARY;
boolean urgent = false;
- var need = new Need(name, location, maxGoal, type, urgent);
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
doThrow(new IllegalAccessException()).when(mockAuthService).keyHasAccessToCupboard(key);
var res = cupboardController.updateNeed(need, 1, key);
@@ -329,7 +359,9 @@ public class CupboardControllerTest {
int maxGoal = 100;
GoalType type = Need.GoalType.MONETARY;
boolean urgent = false;
- var need = new Need(name, location, maxGoal, type, urgent);
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
when(mockCupboardService.getNeed(1)).thenReturn(need);
when(mockCupboardService.deleteNeed(1)).thenReturn(true);
@@ -355,7 +387,9 @@ public class CupboardControllerTest {
int maxGoal = 100;
GoalType type = Need.GoalType.MONETARY;
boolean urgent = false;
- var need = new Need(name, location, maxGoal, type, urgent);
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
when(mockCupboardService.getNeed(1)).thenReturn(need);
doThrow(new IllegalAccessException()).when(mockAuthService).keyHasAccessToCupboard(key);
@@ -371,7 +405,9 @@ public class CupboardControllerTest {
int maxGoal = 100;
GoalType type = Need.GoalType.MONETARY;
boolean urgent = false;
- var need = new Need(name, location, maxGoal, type, urgent);
+ String image = "";
+ String description = "";
+ var need = new Need(name, location, image, maxGoal, type, urgent, description);
when(mockCupboardService.getNeed(1)).thenReturn(need);
when(mockCupboardService.deleteNeed(1)).thenThrow(new IOException());