diff options
Diffstat (limited to 'ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java')
-rw-r--r-- | ufund-api/src/test/java/com/ufund/api/ufundapi/controller/CupboardControllerTest.java | 95 |
1 files changed, 75 insertions, 20 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 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<String, Object> 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<String, Object> 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<String, Object> 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()); |