aboutsummaryrefslogtreecommitdiff
path: root/ufund-api/src/test/java/com/ufund/api/ufundapi/service/CupboardServiceTest.java
diff options
context:
space:
mode:
authorsowgro <tpoke.ferrari@gmail.com>2025-04-08 01:01:10 -0400
committersowgro <tpoke.ferrari@gmail.com>2025-04-08 01:01:10 -0400
commit778a0327e0853ebd94d0ccade111e759a1fe1fb3 (patch)
tree5547bb6fda0e9aabd359d1246c18118a5656548f /ufund-api/src/test/java/com/ufund/api/ufundapi/service/CupboardServiceTest.java
parentb45f391bf999c2ffc32890072b9fdbbb1dcfeef3 (diff)
downloadJellySolutions-778a0327e0853ebd94d0ccade111e759a1fe1fb3.tar.gz
JellySolutions-778a0327e0853ebd94d0ccade111e759a1fe1fb3.tar.bz2
JellySolutions-778a0327e0853ebd94d0ccade111e759a1fe1fb3.zip
checkoutNeed test
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.java75
1 files changed, 69 insertions, 6 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 da098d0..57cb0bf 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
@@ -2,11 +2,7 @@ package com.ufund.api.ufundapi.service;
import java.io.IOException;
-import static org.junit.jupiter.api.Assertions.assertArrayEquals;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
import org.junit.jupiter.api.BeforeEach;
@@ -23,13 +19,14 @@ public class CupboardServiceTest {
private CupboardDAO mockCupboardDAO;
private CupboardService cupboardService;
+ private AuthService mockAuthService;
@BeforeEach
public void setupCupboardService() {
mockCupboardDAO = mock(CupboardDAO.class);
AuthService mockAuthService = mock(AuthService.class);
cupboardService = new CupboardService(mockAuthService, mockCupboardDAO);
-
+ this.mockAuthService = mock(AuthService.class);
}
@Test
@@ -382,4 +379,70 @@ public class CupboardServiceTest {
assertArrayEquals(new Need[0], responseNeeds);
}
+ @Test
+ void checkoutNeed() throws IOException, IllegalAccessException {
+ int id = 1;
+ 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);
+ String key = "anything";
+ var amount = 10;
+
+ doNothing().when(mockAuthService).keyIsValid(key);
+ when(mockCupboardDAO.getNeed(id)).thenReturn(need);
+
+ assertDoesNotThrow(() -> cupboardService.checkoutNeed(id, amount, key));
+ }
+
+ @Test
+ void checkoutNeed2() {
+ int id = 1;
+ String key = "anything";
+ var amount = -5;
+
+ assertThrows(IllegalArgumentException.class, () -> cupboardService.checkoutNeed(id, amount, key));
+ }
+
+ @Test
+ void checkoutNeed3() throws IOException {
+ int id = 1;
+ String name = "Jellyfish";
+ String location = "Atlantis";
+ double maxGoal = 100.0;
+ GoalType type = GoalType.PHYSICAL;
+ boolean urgent = false;
+ String image = "";
+ String description = "";
+ var need = new Need(name, image, location, maxGoal, type, urgent, description);
+ String key = "anything";
+ var amount = 3.1459;
+
+ when(mockCupboardDAO.getNeed(id)).thenReturn(need);
+
+ assertThrows(IllegalArgumentException.class, () -> cupboardService.checkoutNeed(id, amount, key));
+ }
+
+ @Test
+ void checkoutNeed4() throws IOException {
+ int id = 1;
+ String name = "Jellyfish";
+ String location = "Atlantis";
+ double maxGoal = 100.0;
+ GoalType type = GoalType.MONETARY;
+ boolean urgent = false;
+ String image = "";
+ String description = "";
+ var need = new Need(name, image, location, maxGoal, type, urgent, description);
+ String key = "anything";
+ var amount = 3.1459;
+
+ when(mockCupboardDAO.getNeed(id)).thenReturn(need);
+
+ assertDoesNotThrow(() -> cupboardService.checkoutNeed(id, amount, key));
+ }
} \ No newline at end of file