diff options
author | sowgro <tpoke.ferrari@gmail.com> | 2025-03-07 12:24:14 -0500 |
---|---|---|
committer | sowgro <tpoke.ferrari@gmail.com> | 2025-03-07 12:24:14 -0500 |
commit | dd2b912af94b08c2daae20bf861a6f30b5c20253 (patch) | |
tree | bc68cb449baec0d5f1e712dcfdc52370f449e943 /ufund-api/src/test/java/com/ufund/api/ufundapi | |
parent | 34903015992ac0cd7719b662af3ceb54a801351c (diff) | |
parent | e4e6ae9a3d142fc78f31ee19464ec5e54bfb516f (diff) | |
download | JellySolutions-dd2b912af94b08c2daae20bf861a6f30b5c20253.tar.gz JellySolutions-dd2b912af94b08c2daae20bf861a6f30b5c20253.tar.bz2 JellySolutions-dd2b912af94b08c2daae20bf861a6f30b5c20253.zip |
Merge branch 'main' into api-auth
# Conflicts:
# ufund-api/src/main/java/com/ufund/api/ufundapi/controller/CupboardController.java
# ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java
Diffstat (limited to 'ufund-api/src/test/java/com/ufund/api/ufundapi')
3 files changed, 142 insertions, 9 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 1cc84bf..839c518 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 @@ -1,24 +1,26 @@ package com.ufund.api.ufundapi.controller; -import com.ufund.api.ufundapi.model.Need; -import com.ufund.api.ufundapi.persistence.CupboardFileDAO; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.http.HttpStatus; - import java.io.IOException; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import org.springframework.http.HttpStatus; + +import com.ufund.api.ufundapi.model.Need; +import com.ufund.api.ufundapi.persistence.CupboardFileDao; public class CupboardControllerTest { private CupboardController cupboardController; - private CupboardFileDAO mockCupboardDAO; + private CupboardFileDao mockCupboardDAO; @BeforeEach public void setupCupboardDAO() { - mockCupboardDAO = mock(CupboardFileDAO.class); + mockCupboardDAO = mock(CupboardFileDao.class); cupboardController = new CupboardController(mockCupboardDAO); } @@ -34,6 +36,26 @@ public class CupboardControllerTest { } @Test + public void createNeedBadMaxGoal() throws IOException { + var need = new Need("Name", 1, -100, Need.GoalType.MONETARY); + when(mockCupboardDAO.createNeed(need)).thenReturn(need); + + var res = cupboardController.createNeed(need); + + assertEquals(HttpStatus.BAD_REQUEST, res.getStatusCode()); + } + + @Test + public void createNeedIOException() throws IOException { + var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); + when(mockCupboardDAO.createNeed(need)).thenThrow(new IOException()); + + var res = cupboardController.createNeed(need); + + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, res.getStatusCode()); + } + + @Test public void getNeeds() { var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); when(mockCupboardDAO.getNeeds()).thenReturn(new Need[]{need}); @@ -45,6 +67,16 @@ public class CupboardControllerTest { } @Test + public void getNeedsIOException() { + var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); + when(mockCupboardDAO.getNeeds()).thenThrow(new IOException()); + + var res = cupboardController.getNeeds(); + + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, res.getStatusCode()); + } + + @Test public void getNeedsEmpty() { when(mockCupboardDAO.getNeeds()).thenReturn(new Need[]{}); @@ -66,6 +98,16 @@ public class CupboardControllerTest { } @Test + public void searchNeedsIOException() { + var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); + when(mockCupboardDAO.findNeeds("Na")).thenThrow(new IOException()); + + var res = cupboardController.searchNeeds("Na"); + + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, res.getStatusCode()); + } + + @Test public void searchNeedsEmpty() { when(mockCupboardDAO.findNeeds("Na")).thenReturn(new Need[]{}); @@ -87,6 +129,16 @@ public class CupboardControllerTest { } @Test + public void getNeedIOException() { + var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); + when(mockCupboardDAO.getNeed(need.getId())).thenThrow(new IOException()); + + var res = cupboardController.getNeed(need.getId()); + + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, res.getStatusCode()); + } + + @Test public void getNeedFail() { var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); when(mockCupboardDAO.getNeed(need.getId())).thenReturn(null); @@ -109,6 +161,16 @@ public class CupboardControllerTest { } @Test + public void updateNeedsIOException() throws IOException { + var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); + when(mockCupboardDAO.updateNeed(need)).thenThrow(new IOException()); + + var res = cupboardController.updateNeed(need); + + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, res.getStatusCode()); + } + + @Test public void deleteNeed() throws IOException { var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); when(mockCupboardDAO.getNeed(1)).thenReturn(need); @@ -128,4 +190,15 @@ public class CupboardControllerTest { assertEquals(HttpStatus.NOT_FOUND, res.getStatusCode()); } + + @Test + public void deleteNeedIOException() throws IOException { + var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); + when(mockCupboardDAO.getNeed(1)).thenReturn(need); + when(mockCupboardDAO.deleteNeed(1)).thenThrow(new IOException()); + + var res = cupboardController.deleteNeed(1); + + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, res.getStatusCode()); + } } 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 50b5cf2..ffcd808 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 @@ -59,6 +59,7 @@ public class NeedTest { assertEquals(need.getCurrent(), current); } + @Test public void testFilterAttributes() { @@ -75,4 +76,35 @@ public class NeedTest { assertEquals(need.getFilterAttributes(), filterAttributes); } + @Test + public void testSetMaxGoal() { + + String name = "Jellyfish"; + int id = 0; + double maxGoal = 100.00; + GoalType type = GoalType.MONETARY; + Need need = new Need(name, id, maxGoal, type); + + double newGoal = 200.00; + need.setMaxGoal(newGoal); + + + assertEquals(newGoal, need.getMaxGoal()); + } + + @Test + public void testSetName() { + + String name = "Jellyfish"; + int id = 0; + double maxGoal = 100.00; + GoalType type = GoalType.MONETARY; + Need need = new Need(name, id, maxGoal, type); + + String newName = "TESTINGFUN"; + need.setName(newName); + + assertEquals(newName, need.getName()); + } + } 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 6f35df0..22f6ffb 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 @@ -46,4 +46,32 @@ public class UserTest { } + @Test + public void testRemoveBasketNeed() { + + String expectedName = "Bob"; + + User user = new User(expectedName); + Need need = new Need("Test", 0, 100, Need.GoalType.MONETARY); + Need need2 = new Need("Test2", 0, 100, Need.GoalType.MONETARY); + + user.addToBasket(need); + user.removeBasketNeed(need); + user.addToBasket(need2); + + assertEquals(need2, user.getBasketNeeds()[0]); + + } + + @Test + public void testVerifyPassword() { + + String expectedName = "Bob"; + + User user = new User(expectedName); + + assertEquals(false, user.verifyPassword(expectedName)); + + } + } |