From 1abdb1408159796d12ed28c73862dd8d186384f0 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Sun, 30 Mar 2025 16:41:24 -0400 Subject: Fixed broken tests and made them more consistent --- .../controller/CupboardControllerTest.java | 95 +++++++++++++++++----- 1 file changed, 75 insertions(+), 20 deletions(-) (limited to 'ufund-api/src/test/java/com/ufund/api/ufundapi/controller') 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 89697bf..31e085b 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 @@ -38,16 +38,20 @@ public class CupboardControllerTest { @Test public void createNeed() throws IOException, DuplicateKeyException { String name = "Test"; + String location = "Atlantis"; int maxGoal = 100; GoalType type = Need.GoalType.MONETARY; - var need = new Need(name, type, maxGoal); - when(mockCupboardService.createNeed(name, maxGoal, type)).thenReturn(need); + boolean urgent = false; + var need = new Need(name, location, maxGoal, type, urgent); + when(mockCupboardService.createNeed(name, "Atlantis", maxGoal, type, false)).thenReturn(need); Map needMap = Map.ofEntries( entry("name", "Test"), + entry("location", "Atlantis"), entry("maxGoal", 100.0), - entry("type", "MONETARY") + entry("type", "MONETARY"), + entry("urgent", false) ); var res = cupboardController.createNeed(needMap, key); @@ -58,12 +62,15 @@ public class CupboardControllerTest { @Test public void createNeedBadMaxGoal() throws IOException, DuplicateKeyException { - when(mockCupboardService.createNeed("Name", -100, Need.GoalType.MONETARY)).thenThrow(new IllegalArgumentException()); + when(mockCupboardService.createNeed("Test", "Atlantis", -100, Need.GoalType.MONETARY, false)).thenThrow(new IllegalArgumentException()); Map needMap = Map.ofEntries( - entry("name", "Name"), - entry("maxGoal", -100.0), - entry("type", "MONETARY")); + entry("name", "Test"), + entry("location", "Atlantis"), + entry("maxGoal", -100), + entry("type", "MONETARY"), + entry("urgent", false) + ); var res = cupboardController.createNeed(needMap, key); @@ -72,12 +79,15 @@ public class CupboardControllerTest { @Test public void createNeedIOException() throws IOException, DuplicateKeyException { - when(mockCupboardService.createNeed("Name", 100, Need.GoalType.MONETARY)).thenThrow(new IOException()); + when(mockCupboardService.createNeed("Test", "Atlantis", 100, Need.GoalType.MONETARY, false)).thenThrow(new IOException()); Map needMap = Map.ofEntries( - entry("name", "Name"), - entry("maxGoal", 100.0), - entry("type", "MONETARY")); + entry("name", "Test"), + entry("location", "Atlantis"), + entry("maxGoal", 100), + entry("type", "MONETARY"), + entry("urgent", false) + ); var res = cupboardController.createNeed(needMap, key); @@ -86,7 +96,12 @@ public class CupboardControllerTest { @Test public void getNeeds() throws IOException { - var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); + String name = "Test"; + String location = "Atlantis"; + int maxGoal = 100; + GoalType type = Need.GoalType.MONETARY; + boolean urgent = false; + var need = new Need(name, location, maxGoal, type, urgent); when(mockCupboardService.getNeeds()).thenReturn(new Need[]{need}); var res = cupboardController.getNeeds(); @@ -116,7 +131,12 @@ public class CupboardControllerTest { @Test public void searchNeeds() throws IOException { - var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); + String name = "Test"; + String location = "Atlantis"; + int maxGoal = 100; + GoalType type = Need.GoalType.MONETARY; + boolean urgent = false; + var need = new Need(name, location, maxGoal, type, urgent); when(mockCupboardService.searchNeeds("Na")).thenReturn(new Need[]{need}); var res = cupboardController.searchNeeds("Na"); @@ -146,7 +166,12 @@ public class CupboardControllerTest { @Test public void getNeed() throws IOException { - var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); + String name = "Test"; + String location = "Atlantis"; + int maxGoal = 100; + GoalType type = Need.GoalType.MONETARY; + boolean urgent = false; + var need = new Need(name, location, maxGoal, type, urgent); when(mockCupboardService.getNeed(need.getId())).thenReturn(need); var res = cupboardController.getNeed(need.getId()); @@ -157,7 +182,12 @@ public class CupboardControllerTest { @Test public void getNeedIOException() throws IOException { - var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); + String name = "Test"; + String location = "Atlantis"; + int maxGoal = 100; + GoalType type = Need.GoalType.MONETARY; + boolean urgent = false; + var need = new Need(name, location, maxGoal, type, urgent); when(mockCupboardService.getNeed(need.getId())).thenThrow(new IOException()); var res = cupboardController.getNeed(need.getId()); @@ -167,7 +197,12 @@ public class CupboardControllerTest { @Test public void getNeedFail() throws IOException { - var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); + String name = "Test"; + String location = "Atlantis"; + int maxGoal = 100; + GoalType type = Need.GoalType.MONETARY; + boolean urgent = false; + var need = new Need(name, location, maxGoal, type, urgent); when(mockCupboardService.getNeed(need.getId())).thenReturn(null); var res = cupboardController.getNeed(need.getId()); @@ -178,7 +213,12 @@ public class CupboardControllerTest { @Test public void updateNeeds() throws IOException { - var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); + String name = "Test"; + String location = "Atlantis"; + int maxGoal = 100; + GoalType type = Need.GoalType.MONETARY; + boolean urgent = false; + var need = new Need(name, location, maxGoal, type, urgent); when(mockCupboardService.updateNeed(need, 1)).thenReturn(need); var res = cupboardController.updateNeed(need, 1, key); @@ -189,7 +229,12 @@ public class CupboardControllerTest { @Test public void updateNeedsIOException() throws IOException { - var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); + String name = "Test"; + String location = "Atlantis"; + int maxGoal = 100; + GoalType type = Need.GoalType.MONETARY; + boolean urgent = false; + var need = new Need(name, location, maxGoal, type, urgent); when(mockCupboardService.updateNeed(need, 1)).thenThrow(new IOException()); var res = cupboardController.updateNeed(need, 1, key); @@ -199,7 +244,12 @@ public class CupboardControllerTest { @Test public void deleteNeed() throws IOException { - var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); + String name = "Test"; + String location = "Atlantis"; + int maxGoal = 100; + GoalType type = Need.GoalType.MONETARY; + boolean urgent = false; + var need = new Need(name, location, maxGoal, type, urgent); when(mockCupboardService.getNeed(1)).thenReturn(need); when(mockCupboardService.deleteNeed(1)).thenReturn(true); @@ -220,7 +270,12 @@ public class CupboardControllerTest { @Test public void deleteNeedIOException() throws IOException { - var need = new Need("Name", 1, 100, Need.GoalType.MONETARY); + String name = "Test"; + String location = "Atlantis"; + int maxGoal = 100; + GoalType type = Need.GoalType.MONETARY; + boolean urgent = false; + var need = new Need(name, location, maxGoal, type, urgent); when(mockCupboardService.getNeed(1)).thenReturn(need); when(mockCupboardService.deleteNeed(1)).thenThrow(new IOException()); -- cgit v1.2.3 From fd3fcd8f0e13e32774c020aee1b46e91d9b96c50 Mon Sep 17 00:00:00 2001 From: Gunther6070 Date: Sun, 30 Mar 2025 18:52:27 -0400 Subject: Fixed 2 broken tests in CupboardControllerTest --- .../ufundapi/controller/CupboardControllerTest.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'ufund-api/src/test/java/com/ufund/api/ufundapi/controller') 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 4702771..75dbf84 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 @@ -97,12 +97,14 @@ public class CupboardControllerTest { @Test public void createNeedConflict() throws IOException, DuplicateKeyException { - when(mockCupboardService.createNeed("Name", "Atlantis", 100, Need.GoalType.MONETARY, false)).thenThrow(new DuplicateKeyException("")); + when(mockCupboardService.createNeed("Test", "Atlantis", 100, Need.GoalType.MONETARY, false)).thenThrow(new DuplicateKeyException("")); Map needMap = Map.ofEntries( - entry("name", "Name"), - entry("maxGoal", 100.0), - entry("type", "MONETARY") + entry("name", "Test"), + entry("location", "Atlantis"), + entry("maxGoal", 100), + entry("type", "MONETARY"), + entry("urgent", false) ); var res = cupboardController.createNeed(needMap, key); @@ -115,9 +117,11 @@ public class CupboardControllerTest { doThrow(new IllegalAccessException()).when(mockAuthService).keyHasAccessToCupboard(key); Map needMap = Map.ofEntries( - entry("name", "Name"), - entry("maxGoal", 100.0), - entry("type", "MONETARY") + entry("name", "Test"), + entry("location", "Atlantis"), + entry("maxGoal", 100), + entry("type", "MONETARY"), + entry("urgent", false) ); var res = cupboardController.createNeed(needMap, key); -- cgit v1.2.3