From acac4aba2f7876c557b466ae6578c7012419679b Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Mon, 3 Mar 2025 17:06:15 -0500 Subject: Added IOException tests --- .../controller/CupboardControllerTest.java | 87 ++++++++++++++++++++-- 1 file changed, 80 insertions(+), 7 deletions(-) (limited to 'ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java') 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; @@ -33,6 +35,26 @@ public class CupboardControllerTest { assertEquals(need, res.getBody()); } + @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); @@ -44,6 +66,16 @@ public class CupboardControllerTest { assertArrayEquals(new Need[]{need}, res.getBody()); } + @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[]{}); @@ -65,6 +97,16 @@ public class CupboardControllerTest { assertArrayEquals(new Need[]{need}, res.getBody()); } + @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[]{}); @@ -86,6 +128,16 @@ public class CupboardControllerTest { assertEquals(need, res.getBody()); } + @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); @@ -108,6 +160,16 @@ public class CupboardControllerTest { assertEquals(need, res.getBody()); } + @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); @@ -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()); + } } -- cgit v1.2.3 From 4a6c06f669a62c84ed59c52397e2b0632e8f7f5d Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Mon, 3 Mar 2025 17:08:34 -0500 Subject: Fixed semicolon error --- .../com/ufund/api/ufundapi/controller/CupboardControllerTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java') 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 c9b0c5e..3702581 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 @@ -129,9 +129,9 @@ public class CupboardControllerTest { } @Test - public void getNeed() { + public void getNeedIOException() { var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); - when(mockCupboardDAO.getNeed(need.getId())).thenThrow(new IOException()) + when(mockCupboardDAO.getNeed(need.getId())).thenThrow(new IOException()); var res = cupboardController.getNeed(need.getId()); -- cgit v1.2.3 From 9db38f2874b16fa345f4dde660d99465c8dcb1c2 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Mon, 3 Mar 2025 17:10:06 -0500 Subject: Fixed httpstatus in assert statement --- .../java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java') 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 3702581..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 @@ -42,7 +42,7 @@ public class CupboardControllerTest { var res = cupboardController.createNeed(need); - assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, res.getStatusCode()); + assertEquals(HttpStatus.BAD_REQUEST, res.getStatusCode()); } @Test -- cgit v1.2.3 From bb9ce55cb5b55a6aaed2399e39a01d68f2491ce3 Mon Sep 17 00:00:00 2001 From: sowgro Date: Thu, 6 Mar 2025 21:41:39 -0500 Subject: Push current changes (working on documentation and tests) --- .../com/ufund/api/ufundapi/controller/CupboardControllerTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java') 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..1cc84bf 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,7 +1,7 @@ package com.ufund.api.ufundapi.controller; import com.ufund.api.ufundapi.model.Need; -import com.ufund.api.ufundapi.persistence.CupboardFileDao; +import com.ufund.api.ufundapi.persistence.CupboardFileDAO; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.http.HttpStatus; @@ -14,11 +14,11 @@ import static org.mockito.Mockito.when; 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); } -- cgit v1.2.3 From fa1f1140b1e13d495c8e06e80928efb333917d31 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Fri, 7 Mar 2025 15:35:31 -0500 Subject: Updated cupboard controller tests to use service class --- .../controller/CupboardControllerTest.java | 53 ++++++++++++++-------- 1 file changed, 34 insertions(+), 19 deletions(-) (limited to 'ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java') 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..a78c45c 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,33 +1,48 @@ package com.ufund.api.ufundapi.controller; import com.ufund.api.ufundapi.model.Need; -import com.ufund.api.ufundapi.persistence.CupboardFileDAO; +import com.ufund.api.ufundapi.model.Need.GoalType; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.http.HttpStatus; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import static java.util.Map.entry; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import com.ufund.api.ufundapi.service.CupboardService; + public class CupboardControllerTest { private CupboardController cupboardController; - private CupboardFileDAO mockCupboardDAO; + private CupboardService mockCupboardService; @BeforeEach public void setupCupboardDAO() { - mockCupboardDAO = mock(CupboardFileDAO.class); - cupboardController = new CupboardController(mockCupboardDAO); + mockCupboardService = mock(CupboardService.class); + cupboardController = new CupboardController(mockCupboardService); } @Test - public void createNeed() throws IOException { - var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); - when(mockCupboardDAO.createNeed(need)).thenReturn(need); + public void createNeed() throws IOException, CupboardService.DuplicateKeyException { + String name = "Test"; + int maxGoal = 100; + GoalType type = Need.GoalType.MONETARY; + var need = new Need(name, type, maxGoal); + when(mockCupboardService.createNeed(name, maxGoal, type)).thenReturn(need); + + + Map needMap = Map.ofEntries( + entry("id", need.getId()), + entry("need", need) + ); - var res = cupboardController.createNeed(need); + var res = cupboardController.createNeed(needMap); assertEquals(HttpStatus.OK, res.getStatusCode()); assertEquals(need, res.getBody()); @@ -36,7 +51,7 @@ public class CupboardControllerTest { @Test public void getNeeds() { var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); - when(mockCupboardDAO.getNeeds()).thenReturn(new Need[]{need}); + when(mockCupboardService.getNeeds()).thenReturn(new Need[]{need}); var res = cupboardController.getNeeds(); @@ -46,7 +61,7 @@ public class CupboardControllerTest { @Test public void getNeedsEmpty() { - when(mockCupboardDAO.getNeeds()).thenReturn(new Need[]{}); + when(mockCupboardService.getNeeds()).thenReturn(new Need[]{}); var res = cupboardController.getNeeds(); @@ -57,7 +72,7 @@ public class CupboardControllerTest { @Test public void searchNeeds() { var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); - when(mockCupboardDAO.findNeeds("Na")).thenReturn(new Need[]{need}); + when(mockCupboardService.findNeeds("Na")).thenReturn(new Need[]{need}); var res = cupboardController.searchNeeds("Na"); @@ -67,7 +82,7 @@ public class CupboardControllerTest { @Test public void searchNeedsEmpty() { - when(mockCupboardDAO.findNeeds("Na")).thenReturn(new Need[]{}); + when(mockCupboardService.findNeeds("Na")).thenReturn(new Need[]{}); var res = cupboardController.searchNeeds("Na"); @@ -78,7 +93,7 @@ public class CupboardControllerTest { @Test public void getNeed() { var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); - when(mockCupboardDAO.getNeed(need.getId())).thenReturn(need); + when(mockCupboardService.getNeed(need.getId())).thenReturn(need); var res = cupboardController.getNeed(need.getId()); @@ -89,7 +104,7 @@ public class CupboardControllerTest { @Test public void getNeedFail() { var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); - when(mockCupboardDAO.getNeed(need.getId())).thenReturn(null); + when(mockCupboardService.getNeed(need.getId())).thenReturn(null); var res = cupboardController.getNeed(need.getId()); @@ -100,7 +115,7 @@ public class CupboardControllerTest { @Test public void updateNeeds() throws IOException { var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); - when(mockCupboardDAO.updateNeed(need)).thenReturn(need); + when(mockCupboardService.updateNeed(need)).thenReturn(need); var res = cupboardController.updateNeed(need); @@ -111,8 +126,8 @@ public class CupboardControllerTest { @Test public void deleteNeed() throws IOException { var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); - when(mockCupboardDAO.getNeed(1)).thenReturn(need); - when(mockCupboardDAO.deleteNeed(1)).thenReturn(true); + when(mockCupboardService.getNeed(1)).thenReturn(need); + when(mockCupboardService.deleteNeed(1)).thenReturn(true); var res = cupboardController.deleteNeed(1); @@ -121,8 +136,8 @@ public class CupboardControllerTest { @Test public void deleteNeedFail() throws IOException { - when(mockCupboardDAO.getNeed(1)).thenReturn(null); - when(mockCupboardDAO.deleteNeed(1)).thenReturn(false); + when(mockCupboardService.getNeed(1)).thenReturn(null); + when(mockCupboardService.deleteNeed(1)).thenReturn(false); var res = cupboardController.deleteNeed(1); -- cgit v1.2.3 From a9dd0b0035db327f8be91344115afc96c86b6210 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Thu, 13 Mar 2025 16:54:14 -0400 Subject: Fixed broken tests --- .../controller/CupboardControllerTest.java | 95 ++++++++++++---------- 1 file changed, 51 insertions(+), 44 deletions(-) (limited to 'ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java') 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 c7a5584..100bf09 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,21 +1,21 @@ package com.ufund.api.ufundapi.controller; -import com.ufund.api.ufundapi.model.Need; -import com.ufund.api.ufundapi.model.Need.GoalType; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.http.HttpStatus; - import java.io.IOException; -import java.util.HashMap; import java.util.Map; import static java.util.Map.entry; -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.DuplicateKeyException; +import com.ufund.api.ufundapi.model.Need; +import com.ufund.api.ufundapi.model.Need.GoalType; import com.ufund.api.ufundapi.service.CupboardService; public class CupboardControllerTest { @@ -29,7 +29,7 @@ public class CupboardControllerTest { } @Test - public void createNeed() throws IOException, CupboardService.DuplicateKeyException { + public void createNeed() throws IOException, DuplicateKeyException { String name = "Test"; int maxGoal = 100; GoalType type = Need.GoalType.MONETARY; @@ -37,9 +37,10 @@ public class CupboardControllerTest { when(mockCupboardService.createNeed(name, maxGoal, type)).thenReturn(need); - Map needMap = Map.ofEntries( - entry("id", need.getId()), - entry("need", need) + Map needMap = Map.ofEntries( + entry("name", "Test"), + entry("maxGoal", "100"), + entry("goalType", "MONETARY") ); var res = cupboardController.createNeed(needMap); @@ -49,27 +50,35 @@ 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); + public void createNeedBadMaxGoal() throws IOException, DuplicateKeyException { + when(mockCupboardService.createNeed("Name", -100, Need.GoalType.MONETARY)).thenThrow(new IllegalArgumentException()); - var res = cupboardController.createNeed(need); + Map needMap = Map.ofEntries( + entry("name", "Name"), + entry("maxGoal", "-100"), + entry("goalType", "MONETARY")); - assertEquals(HttpStatus.BAD_REQUEST, res.getStatusCode()); + var res = cupboardController.createNeed(needMap); + + assertEquals(HttpStatus.UNPROCESSABLE_ENTITY, 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()); + public void createNeedIOException() throws IOException, DuplicateKeyException { + when(mockCupboardService.createNeed("Name", 100, Need.GoalType.MONETARY)).thenThrow(new IOException()); - var res = cupboardController.createNeed(need); + Map needMap = Map.ofEntries( + entry("name", "Name"), + entry("maxGoal", "100"), + entry("goalType", "MONETARY")); + + var res = cupboardController.createNeed(needMap); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, res.getStatusCode()); } @Test - public void getNeeds() { + public void getNeeds() throws IOException { var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); when(mockCupboardService.getNeeds()).thenReturn(new Need[]{need}); @@ -80,9 +89,8 @@ public class CupboardControllerTest { } @Test - public void getNeedsIOException() { - var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); - when(mockCupboardDAO.getNeeds()).thenThrow(new IOException()); + public void getNeedsIOException() throws IOException { + when(mockCupboardService.getNeeds()).thenThrow(new IOException()); var res = cupboardController.getNeeds(); @@ -90,7 +98,7 @@ public class CupboardControllerTest { } @Test - public void getNeedsEmpty() { + public void getNeedsEmpty() throws IOException { when(mockCupboardService.getNeeds()).thenReturn(new Need[]{}); var res = cupboardController.getNeeds(); @@ -100,9 +108,9 @@ public class CupboardControllerTest { } @Test - public void searchNeeds() { + public void searchNeeds() throws IOException { var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); - when(mockCupboardService.findNeeds("Na")).thenReturn(new Need[]{need}); + when(mockCupboardService.searchNeeds("Na")).thenReturn(new Need[]{need}); var res = cupboardController.searchNeeds("Na"); @@ -111,9 +119,8 @@ public class CupboardControllerTest { } @Test - public void searchNeedsIOException() { - var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); - when(mockCupboardDAO.findNeeds("Na")).thenThrow(new IOException()); + public void searchNeedsIOException() throws IOException { + when(mockCupboardService.searchNeeds("Na")).thenThrow(new IOException()); var res = cupboardController.searchNeeds("Na"); @@ -121,8 +128,8 @@ public class CupboardControllerTest { } @Test - public void searchNeedsEmpty() { - when(mockCupboardService.findNeeds("Na")).thenReturn(new Need[]{}); + public void searchNeedsEmpty() throws IOException { + when(mockCupboardService.searchNeeds("Na")).thenReturn(new Need[]{}); var res = cupboardController.searchNeeds("Na"); @@ -131,7 +138,7 @@ public class CupboardControllerTest { } @Test - public void getNeed() { + public void getNeed() throws IOException { var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); when(mockCupboardService.getNeed(need.getId())).thenReturn(need); @@ -142,9 +149,9 @@ public class CupboardControllerTest { } @Test - public void getNeedIOException() { + public void getNeedIOException() throws IOException { var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); - when(mockCupboardDAO.getNeed(need.getId())).thenThrow(new IOException()); + when(mockCupboardService.getNeed(need.getId())).thenThrow(new IOException()); var res = cupboardController.getNeed(need.getId()); @@ -152,7 +159,7 @@ public class CupboardControllerTest { } @Test - public void getNeedFail() { + public void getNeedFail() throws IOException { var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); when(mockCupboardService.getNeed(need.getId())).thenReturn(null); @@ -165,9 +172,9 @@ public class CupboardControllerTest { @Test public void updateNeeds() throws IOException { var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); - when(mockCupboardService.updateNeed(need)).thenReturn(need); + when(mockCupboardService.updateNeed(need, 1)).thenReturn(need); - var res = cupboardController.updateNeed(need); + var res = cupboardController.updateNeed(need, 1); assertEquals(HttpStatus.OK, res.getStatusCode()); assertEquals(need, res.getBody()); @@ -176,9 +183,9 @@ 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()); + when(mockCupboardService.updateNeed(need, 1)).thenThrow(new IOException()); - var res = cupboardController.updateNeed(need); + var res = cupboardController.updateNeed(need, 1); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, res.getStatusCode()); } @@ -207,8 +214,8 @@ public class CupboardControllerTest { @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()); + when(mockCupboardService.getNeed(1)).thenReturn(need); + when(mockCupboardService.deleteNeed(1)).thenThrow(new IOException()); var res = cupboardController.deleteNeed(1); -- cgit v1.2.3