diff options
| author | Gunther6070 <haydenhartman10@yahoo.com> | 2025-03-03 17:06:15 -0500 | 
|---|---|---|
| committer | Gunther6070 <haydenhartman10@yahoo.com> | 2025-03-03 17:06:15 -0500 | 
| commit | acac4aba2f7876c557b466ae6578c7012419679b (patch) | |
| tree | 66030f4101209b1f8beedbcca0933b56d0d38187 /ufund-api/src/test/java/com/ufund/api | |
| parent | bc169f677817a180b8535f14c908345c2d1a29bc (diff) | |
| download | JellySolutions-acac4aba2f7876c557b466ae6578c7012419679b.tar.gz JellySolutions-acac4aba2f7876c557b466ae6578c7012419679b.tar.bz2 JellySolutions-acac4aba2f7876c557b466ae6578c7012419679b.zip  | |
Added IOException tests
Diffstat (limited to 'ufund-api/src/test/java/com/ufund/api')
| -rw-r--r-- | ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java | 87 | 
1 files changed, 80 insertions, 7 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 04ce41d..c9b0c5e 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,16 +1,18 @@  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; @@ -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.INTERNAL_SERVER_ERROR, 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 getNeed() { +        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()); +    }  }  | 
