diff options
| author | Gunther6070 <haydenhartman10@yahoo.com> | 2025-03-07 15:43:17 -0500 | 
|---|---|---|
| committer | Gunther6070 <haydenhartman10@yahoo.com> | 2025-03-07 15:43:17 -0500 | 
| commit | 94869200a0d2f80f71fcd0efd4f82c0138b5440d (patch) | |
| tree | 52eff6463b3cec7c3d6bda18e186f9272f528a2c /ufund-api/src/test/java/com/ufund/api/ufundapi/controller | |
| parent | fa1f1140b1e13d495c8e06e80928efb333917d31 (diff) | |
| parent | caaf278d1fa69fef69c210edb337fa54102d2737 (diff) | |
| download | JellySolutions-94869200a0d2f80f71fcd0efd4f82c0138b5440d.tar.gz JellySolutions-94869200a0d2f80f71fcd0efd4f82c0138b5440d.tar.bz2 JellySolutions-94869200a0d2f80f71fcd0efd4f82c0138b5440d.zip  | |
Merge branch 'api-auth' of https://github.com/RIT-SWEN-261-02/team-project-2245-swen-261-02-2b into api-auth
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.java | 71 | 
1 files changed, 71 insertions, 0 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 a78c45c..c7a5584 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 @@ -49,6 +49,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(mockCupboardService.getNeeds()).thenReturn(new Need[]{need}); @@ -60,6 +80,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(mockCupboardService.getNeeds()).thenReturn(new Need[]{}); @@ -81,6 +111,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(mockCupboardService.findNeeds("Na")).thenReturn(new Need[]{}); @@ -102,6 +142,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(mockCupboardService.getNeed(need.getId())).thenReturn(null); @@ -124,6 +174,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(mockCupboardService.getNeed(1)).thenReturn(need); @@ -143,4 +203,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()); +    }  }  | 
