aboutsummaryrefslogtreecommitdiff
path: root/ufund-api/src/test/java/com/ufund/api/ufundapi/service/CupboardServiceTest.java
diff options
context:
space:
mode:
authorAkash Keshav <112591754+domesticchores@users.noreply.github.com>2025-04-08 00:52:47 -0400
committerAkash Keshav <112591754+domesticchores@users.noreply.github.com>2025-04-08 00:52:47 -0400
commit78e9791da675783124c76a20f756886005ffa904 (patch)
tree56faeae845c2d22876c0f5978c164c10a1bccbdb /ufund-api/src/test/java/com/ufund/api/ufundapi/service/CupboardServiceTest.java
parentef62e670a4af08026581db83410bbc8b98e45d7d (diff)
downloadJellySolutions-78e9791da675783124c76a20f756886005ffa904.tar.gz
JellySolutions-78e9791da675783124c76a20f756886005ffa904.tar.bz2
JellySolutions-78e9791da675783124c76a20f756886005ffa904.zip
update designdoc and add more test coverage
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.java160
1 files changed, 160 insertions, 0 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 2a3c8ee..da098d0 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
@@ -81,6 +81,78 @@ public class CupboardServiceTest {
}
@Test
+ public void testCreateNeedBadPhysicalGoal() throws IOException {
+ // Setup
+ String name = "Jellyfish";
+ String location = "Atlantis";
+ double maxGoal = 1.23;
+ GoalType type = Need.GoalType.PHYSICAL;
+ boolean urgent = false;
+ 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, maxGoal, type);
+
+ // Analyze
+ assertThrows(IllegalArgumentException.class, () ->
+ cupboardService.createNeed(name, location, image, maxGoal, type, urgent, description));
+ }
+
+ @Test
+ public void testCreateNeedBadBlankFields() throws IOException {
+ // Setup
+ String name = "";
+ String location = "Atlantis";
+ double maxGoal = 1.23;
+ GoalType type = Need.GoalType.PHYSICAL;
+ boolean urgent = false;
+ 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, maxGoal, type);
+
+ // Analyze
+ assertThrows(IllegalArgumentException.class, () ->
+ cupboardService.createNeed(name, location, image, maxGoal, type, urgent, description));
+ }
+
+ @Test
+ public void testCreateNeedNullFields() throws IOException {
+ // Setup
+ String name = "";
+ String location = "Atlantis";
+ double maxGoal = 100.0;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ 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, maxGoal, type);
+
+ // Analyze
+ assertThrows(IllegalArgumentException.class, () ->
+ cupboardService.createNeed(name, location, image, maxGoal, type, urgent, description));
+ }
+
+ @Test
public void testCreateNeedDuplicate() throws IOException {
// Setup
String name = "Jellyfish";
@@ -198,6 +270,94 @@ public class CupboardServiceTest {
}
@Test
+ public void testUpdateNeedBadGoal() throws IOException {
+ // Setup
+ String name = "Jellyfish";
+ String location = "Atlantis";
+ double maxGoal = 100.0;
+ GoalType type = Need.GoalType.MONETARY;
+ boolean urgent = false;
+ String image = "";
+ String description = "";
+ var need = new Need(name, image, location, maxGoal, type, urgent, description);
+ // goal should not be 0, should throw error
+ Need newNeed = new Need(name, image, location, 0, 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);
+
+ // Invoke and Analyze
+ assertThrows(IllegalArgumentException.class, () ->
+ cupboardService.updateNeed(newNeed, need.getId()));
+ }
+
+ @Test
+ public void testUpdateNeedBadPhysicalGoal() throws IOException {
+ // Setup
+ String name = "Jellyfish";
+ String location = "Atlantis";
+ double maxGoal = 10;
+ GoalType type = Need.GoalType.PHYSICAL;
+ boolean urgent = false;
+ String image = "";
+ String description = "";
+ var need = new Need(name, image, location, maxGoal, type, urgent, description);
+ // goal should be integer, should throw error
+ Need newNeed = new Need(name, image, location, 1.23, 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);
+
+ // Invoke and Analyze
+ assertThrows(IllegalArgumentException.class, () ->
+ cupboardService.updateNeed(newNeed, need.getId()));
+ }
+
+ @Test
+ public void testUpdateNeedBlankFields() throws IOException {
+ // Setup
+ String name = "Jellyfish";
+ String location = "Atlantis";
+ double maxGoal = 10;
+ GoalType type = Need.GoalType.PHYSICAL;
+ boolean urgent = false;
+ String image = "";
+ String description = "";
+ var need = new Need(name, image, location, maxGoal, type, urgent, description);
+ // passed in blank name, should throw error
+ Need newNeed = new Need("", 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);
+
+ // Invoke and Analyze
+ assertThrows(IllegalArgumentException.class, () ->
+ cupboardService.updateNeed(newNeed, need.getId()));
+ }
+
+ @Test
+ public void testUpdateNeedNotMatchingIDs() throws IOException {
+ // Setup
+ String name = "Jellyfish";
+ String location = "Atlantis";
+ double maxGoal = 10;
+ GoalType type = Need.GoalType.PHYSICAL;
+ boolean urgent = false;
+ String image = "";
+ String description = "";
+ var need = new Need(name, image, location, maxGoal, type, urgent, description);
+ // passed in blank name, should throw error
+ Need newNeed = 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.updateNeed(any())).thenReturn(newNeed);
+
+ // Invoke and Analyze
+ assertThrows(IllegalArgumentException.class, () ->
+ cupboardService.updateNeed(newNeed, -1));
+ }
+
+ @Test
public void testDeleteNeed() throws IOException {
// Setup
String name = "Jellyfish";