aboutsummaryrefslogtreecommitdiff
path: root/ufund-api
diff options
context:
space:
mode:
authorGunther6070 <haydenhartman10@yahoo.com>2025-03-31 20:44:22 -0400
committerGunther6070 <haydenhartman10@yahoo.com>2025-03-31 20:44:22 -0400
commitcd8b846a4455aba7664cc03e219f471d251ff9bf (patch)
tree68f0cf06368cfd707be6ce54772a1ee14e6fa35f /ufund-api
parente1ef22279baccb4b2a5a1ecbb5222e4008d4d523 (diff)
downloadJellySolutions-cd8b846a4455aba7664cc03e219f471d251ff9bf.tar.gz
JellySolutions-cd8b846a4455aba7664cc03e219f471d251ff9bf.tar.bz2
JellySolutions-cd8b846a4455aba7664cc03e219f471d251ff9bf.zip
Fixed broken tests due to new need fields
Diffstat (limited to 'ufund-api')
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java82
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/model/NeedTest.java24
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java6
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/CupboardFileDAOTest.java12
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/service/CupboardServiceTest.java40
5 files changed, 114 insertions, 50 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());
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 c7d17c7..67d2b8f 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
@@ -18,7 +18,9 @@ public class NeedTest {
double maxGoal = 100.0;
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);
assertNotNull(need);
}
@@ -29,7 +31,9 @@ public class NeedTest {
double maxGoal = 100.0;
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);
assertEquals(name, need.getName());
@@ -45,7 +49,9 @@ public class NeedTest {
double maxGoal = 100.0;
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);
double current = 0.00;
need.setCurrent(current);
@@ -69,7 +75,9 @@ public class NeedTest {
double maxGoal = 100.0;
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);
String[] filterAttributes = {"seaweed", "divers", "pacific", "plankton"};
@@ -86,7 +94,9 @@ public class NeedTest {
double maxGoal = 100.0;
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);
double newGoal = 200.00;
need.setMaxGoal(newGoal);
@@ -103,7 +113,9 @@ public class NeedTest {
double maxGoal = 100.0;
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);
String newName = "TESTINGFUN";
need.setName(newName);
diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java
index 01b558c..ed48f54 100644
--- a/ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java
+++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java
@@ -52,7 +52,7 @@ public class UserTest {
String expectedName = "Bob";
User user = User.create(expectedName, "pass");
- Need need = new Need("Test", "Atlantis", 0, 100, Need.GoalType.MONETARY, false);
+ Need need = new Need("Test", "", "Atlantis", 0, 100, Need.GoalType.MONETARY, false, "");
Need[] needs = { need };
when(cupboardService.getNeed(0)).thenReturn(need);
@@ -71,8 +71,8 @@ public class UserTest {
String expectedName = "Bob";
User user = User.create(expectedName, "pass");
- Need need = new Need("Test", "Atlantis", 0, 100, Need.GoalType.MONETARY, false);
- Need need2 = new Need("Test2", "Atlantis", 0, 100, Need.GoalType.MONETARY, false);
+ Need need = new Need("Test", "", "Atlantis", 0, 100, Need.GoalType.MONETARY, false, "");
+ Need need2 = new Need("Test2", "", "Atlantis", 0, 100, Need.GoalType.MONETARY, false, "");
when(cupboardService.getNeed(0)).thenReturn(need2);
user.addToBasket(need);
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 acb759a..76a8b40 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
@@ -28,9 +28,9 @@ public class CupboardFileDAOTest {
public void setupCupboardFileDao() throws IOException {
ObjectMapper mockObjectMapper = mock(ObjectMapper.class);
testNeeds = new Need[] {
- new Need("one", "Atlantis", 0, 100, Need.GoalType.MONETARY, false),
- new Need("two", "Atlantis", 1, 100, Need.GoalType.MONETARY, false),
- new Need("three", "Atlantis", 2, 100, Need.GoalType.MONETARY, false)
+ new Need("one", "", "Atlantis", 0, 100, Need.GoalType.MONETARY, false, ""),
+ new Need("two", "", "Atlantis", 1, 100, Need.GoalType.MONETARY, false, ""),
+ new Need("three", "", "Atlantis", 2, 100, Need.GoalType.MONETARY, false, "")
};
// When the object mapper is supposed to read from the file
// the mock object mapper will return the hero array above
@@ -54,7 +54,7 @@ public class CupboardFileDAOTest {
@Test
public void createNeedTest() throws IOException {
- Need newNeed = new Need("sea urchin hats", "Atlantis", 100, GoalType.PHYSICAL, false);
+ Need newNeed = new Need("sea urchin hats", "", "Atlantis", 100, GoalType.PHYSICAL, false, "");
Need actualNeed = cupboardFileDao.addNeed(newNeed);
@@ -90,7 +90,7 @@ public class CupboardFileDAOTest {
Need unupdatedNeed = needs[needs.length - 1];
assertNotNull(unupdatedNeed);
- Need updatedNeed = new Need("sequin sea urchin hats", "Atlantis", 100, GoalType.PHYSICAL, false);
+ Need updatedNeed = new Need("sequin sea urchin hats", "", "Atlantis", 100, GoalType.PHYSICAL, false, "");
Need actualNeed = cupboardFileDao.updateNeed(updatedNeed);
assertEquals(actualNeed, updatedNeed);
@@ -103,7 +103,7 @@ public class CupboardFileDAOTest {
Need unupdatedNeed = needs[needs.length - 1];
assertNotNull(unupdatedNeed);
- Need updatedNeed = new Need("sequin sea urchin hats", "Atlantis", 5, 100, GoalType.PHYSICAL, false);
+ Need updatedNeed = new Need("sequin sea urchin hats", "", "Atlantis", 5, 100, GoalType.PHYSICAL, false, "");
Need actualNeed = cupboardFileDao.updateNeed(updatedNeed);
assertNull(actualNeed);
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 f3cbc23..2a3c8ee 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
@@ -40,14 +40,16 @@ public class CupboardServiceTest {
double 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, image, location, maxGoal, type, urgent, description);
// 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, location, maxGoal, type, urgent);
+ Need response = cupboardService.createNeed(name, location, image, maxGoal, type, urgent, description);
// Analyze
assertNotNull(response);
@@ -62,7 +64,9 @@ public class CupboardServiceTest {
double maxGoal = -100.0;
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, image, location, maxGoal, type, urgent, description);
// When the same id is passed in, our mock User DAO will return the User object
when(mockCupboardDAO.addNeed(any())).thenReturn(need);
@@ -73,7 +77,7 @@ public class CupboardServiceTest {
// Analyze
assertThrows(IllegalArgumentException.class, () ->
- cupboardService.createNeed(name, location, maxGoal, type, urgent));
+ cupboardService.createNeed(name, location, image, maxGoal, type, urgent, description));
}
@Test
@@ -84,7 +88,9 @@ public class CupboardServiceTest {
double maxGoal = 100.0;
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, image, location, maxGoal, type, urgent, description);
Need[] needs = { need };
// When the same id is passed in, our mock User DAO will return the User object
@@ -96,7 +102,7 @@ public class CupboardServiceTest {
// Analyze
assertThrows(DuplicateKeyException.class, () ->
- cupboardService.createNeed(name, location, maxGoal, type, urgent));
+ cupboardService.createNeed(name, location, image, maxGoal, type, urgent, description));
}
@Test
@@ -107,7 +113,9 @@ public class CupboardServiceTest {
double maxGoal = 100.0;
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, image, location, maxGoal, type, urgent, description);
Need[] needs = { need };
// When the same id is passed in, our mock User DAO will return the User object
@@ -129,7 +137,9 @@ public class CupboardServiceTest {
double maxGoal = 100.0;
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, image, location, maxGoal, type, urgent, description);
Need[] needs = { need };
// When the same id is passed in, our mock User DAO will return the User object
@@ -150,7 +160,9 @@ public class CupboardServiceTest {
double maxGoal = 100.0;
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, image, location, maxGoal, type, urgent, description);
// When the same id is passed in, our mock User DAO will return the User object
when(mockCupboardDAO.getNeed(0)).thenReturn(need);
@@ -170,8 +182,10 @@ public class CupboardServiceTest {
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);
+ String image = "";
+ String description = "";
+ var need = new Need(name, image, location, maxGoal, type, urgent, description);
+ Need newNeed = new Need("Octopus", image, location, maxGoal, type, urgent, description);
// When the same id is passed in, our mock User DAO will return the User object
when(mockCupboardDAO.updateNeed(any())).thenReturn(newNeed);
@@ -191,7 +205,9 @@ public class CupboardServiceTest {
double maxGoal = 100.0;
GoalType type = Need.GoalType.MONETARY;
boolean urgent = false;
- Need need = new Need(name, location, maxGoal, type, urgent);
+ String image = "";
+ String description = "";
+ var need = new Need(name, image, location, maxGoal, type, urgent, description);
// When the same id is passed in, our mock User DAO will return the User object
when(mockCupboardDAO.deleteNeed(0)).thenReturn(true);