diff options
Diffstat (limited to 'ufund-api/src/test/java/com')
4 files changed, 68 insertions, 84 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 7ea4455..54873c8 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 @@ -20,14 +20,14 @@ 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 { +class CupboardControllerTest { private CupboardController cupboardController; private CupboardService mockCupboardService; private final String key = "dummyKey"; private AuthService mockAuthService; @BeforeEach - public void setupCupboardDAO() { + void setupCupboardDAO() { mockAuthService = mock(AuthService.class); mockCupboardService = mock(CupboardService.class); cupboardController = new CupboardController(mockCupboardService, mockAuthService); @@ -38,7 +38,7 @@ public class CupboardControllerTest { } @Test - public void createNeed() throws IOException, DuplicateKeyException { + void createNeed() throws IOException, DuplicateKeyException { String name = "Test"; String location = "Atlantis"; int maxGoal = 100; @@ -67,7 +67,7 @@ public class CupboardControllerTest { } @Test - public void createNeedBadMaxGoal() throws IOException, DuplicateKeyException { + void createNeedBadMaxGoal() throws IOException, DuplicateKeyException { when(mockCupboardService.createNeed("Test", "", "Atlantis", -100, Need.GoalType.MONETARY, false, "")).thenThrow(new IllegalArgumentException()); Map<String, Object> needMap = Map.ofEntries( @@ -86,7 +86,7 @@ public class CupboardControllerTest { } @Test - public void createNeedIOException() throws IOException, DuplicateKeyException { + void createNeedIOException() throws IOException, DuplicateKeyException { when(mockCupboardService.createNeed("Test", "", "Atlantis", 100, Need.GoalType.MONETARY, false, "")).thenThrow(new IOException()); Map<String, Object> needMap = Map.ofEntries( @@ -105,7 +105,7 @@ public class CupboardControllerTest { } @Test - public void createNeedConflict() throws IOException, DuplicateKeyException { + void createNeedConflict() throws IOException, DuplicateKeyException { when(mockCupboardService.createNeed("Test", "", "Atlantis", 100, Need.GoalType.MONETARY, false, "")).thenThrow(new DuplicateKeyException("")); Map<String, Object> needMap = Map.ofEntries( @@ -124,7 +124,7 @@ public class CupboardControllerTest { } @Test - public void createNeedUnauthorized() throws IOException, IllegalAccessException { + void createNeedUnauthorized() throws IOException, IllegalAccessException { doThrow(new IllegalAccessException()).when(mockAuthService).keyHasAccessToCupboard(key); Map<String, Object> needMap = Map.ofEntries( @@ -141,7 +141,7 @@ public class CupboardControllerTest { } @Test - public void getNeeds() throws IOException { + void getNeeds() throws IOException { String name = "Test"; String location = "Atlantis"; int maxGoal = 100; @@ -159,7 +159,7 @@ public class CupboardControllerTest { } @Test - public void getNeedsIOException() throws IOException { + void getNeedsIOException() throws IOException { when(mockCupboardService.getNeeds()).thenThrow(new IOException()); var res = cupboardController.getNeeds(); @@ -168,7 +168,7 @@ public class CupboardControllerTest { } @Test - public void getNeedsEmpty() throws IOException { + void getNeedsEmpty() throws IOException { when(mockCupboardService.getNeeds()).thenReturn(new Need[]{}); var res = cupboardController.getNeeds(); @@ -178,7 +178,7 @@ public class CupboardControllerTest { } @Test - public void searchNeeds() throws IOException { + void searchNeeds() throws IOException { String name = "Test"; String location = "Atlantis"; int maxGoal = 100; @@ -196,7 +196,7 @@ public class CupboardControllerTest { } @Test - public void searchNeedsIOException() throws IOException { + void searchNeedsIOException() throws IOException { when(mockCupboardService.searchNeeds("Na")).thenThrow(new IOException()); var res = cupboardController.searchNeeds("Na"); @@ -205,7 +205,7 @@ public class CupboardControllerTest { } @Test - public void searchNeedsEmpty() throws IOException { + void searchNeedsEmpty() throws IOException { when(mockCupboardService.searchNeeds("Na")).thenReturn(new Need[]{}); var res = cupboardController.searchNeeds("Na"); @@ -215,7 +215,7 @@ public class CupboardControllerTest { } @Test - public void getNeed() throws IOException { + void getNeed() throws IOException { String name = "Test"; String location = "Atlantis"; int maxGoal = 100; @@ -233,7 +233,7 @@ public class CupboardControllerTest { } @Test - public void getNeedIOException() throws IOException { + void getNeedIOException() throws IOException { String name = "Test"; String location = "Atlantis"; int maxGoal = 100; @@ -250,7 +250,7 @@ public class CupboardControllerTest { } @Test - public void getNeedFail() throws IOException { + void getNeedFail() throws IOException { String name = "Test"; String location = "Atlantis"; int maxGoal = 100; @@ -268,7 +268,7 @@ public class CupboardControllerTest { } @Test - public void updateNeeds() throws IOException { + void updateNeeds() throws IOException { String name = "Test"; String location = "Atlantis"; int maxGoal = 100; @@ -286,7 +286,7 @@ public class CupboardControllerTest { } @Test - public void updateNeedsIOException() throws IOException { + void updateNeedsIOException() throws IOException { String name = "Test"; String location = "Atlantis"; int maxGoal = 100; @@ -303,7 +303,7 @@ public class CupboardControllerTest { } @Test - public void updateNeedMissing() throws IOException { + void updateNeedMissing() throws IOException { String name = "Test"; String location = "Atlantis"; int maxGoal = 100; @@ -320,7 +320,7 @@ public class CupboardControllerTest { } @Test - public void updateNeedBadRequest() throws IOException { + void updateNeedBadRequest() throws IOException { String name = "Test"; String location = "Atlantis"; int maxGoal = 100; @@ -337,7 +337,7 @@ public class CupboardControllerTest { } @Test - public void updateNeedUnauthorized() throws IOException, IllegalAccessException { + void updateNeedUnauthorized() throws IOException, IllegalAccessException { String name = "Test"; String location = "Atlantis"; int maxGoal = 100; @@ -354,7 +354,7 @@ public class CupboardControllerTest { } @Test - public void deleteNeed() throws IOException { + void deleteNeed() throws IOException { String name = "Test"; String location = "Atlantis"; int maxGoal = 100; @@ -372,7 +372,7 @@ public class CupboardControllerTest { } @Test - public void deleteNeedFail() throws IOException { + void deleteNeedFail() throws IOException { when(mockCupboardService.getNeed(1)).thenReturn(null); when(mockCupboardService.deleteNeed(1)).thenReturn(false); @@ -382,7 +382,7 @@ public class CupboardControllerTest { } @Test - public void deleteNeedUnauthorized() throws IOException, IllegalAccessException { + void deleteNeedUnauthorized() throws IOException, IllegalAccessException { String name = "Test"; String location = "Atlantis"; int maxGoal = 100; @@ -400,7 +400,7 @@ public class CupboardControllerTest { } @Test - public void deleteNeedIOException() throws IOException { + void deleteNeedIOException() throws IOException { String name = "Test"; String location = "Atlantis"; int maxGoal = 100; @@ -418,7 +418,7 @@ public class CupboardControllerTest { } @Test - public void checkoutNeeds() throws IOException, IllegalAccessException { + void checkoutNeeds() throws IOException, IllegalAccessException { when(mockCupboardService.getNeed(0)).thenReturn(new Need("name", "image", "location", 0, 10, GoalType.MONETARY, true, "a")); doNothing().when(mockCupboardService).checkoutNeed(0, 20, key); @@ -435,7 +435,7 @@ public class CupboardControllerTest { } @Test - public void checkoutNeedsBadRequest() throws IOException, IllegalAccessException { + void checkoutNeedsBadRequest() throws IOException, IllegalAccessException { doThrow(new IllegalArgumentException()).when(mockCupboardService).checkoutNeed(0, 20, key); var needMap = List.of( @@ -455,7 +455,7 @@ public class CupboardControllerTest { } @Test - public void checkoutNeedsUnauthorized() throws IOException, IllegalAccessException { + void checkoutNeedsUnauthorized() throws IOException, IllegalAccessException { doThrow(new IllegalAccessException()).when(mockAuthService).keyIsValid(key); var needMap = List.of( @@ -475,7 +475,7 @@ public class CupboardControllerTest { } @Test - public void checkoutNeedsInternalError() throws IOException, IllegalAccessException { + void checkoutNeedsInternalError() throws IOException, IllegalAccessException { when(mockCupboardService.getNeed(0)).thenReturn(new Need("name", "image", "location", 0, 10, GoalType.MONETARY, true, "a")); doThrow(new IOException()).when(mockCupboardService).checkoutNeed(0, 20, key); diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/service/AuthServiceTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/service/AuthServiceTest.java index db849f2..e0bbd04 100644 --- a/ufund-api/src/test/java/com/ufund/api/ufundapi/service/AuthServiceTest.java +++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/service/AuthServiceTest.java @@ -110,29 +110,29 @@ public class AuthServiceTest { @Test void keyIsValid() throws IOException { - String key = "sowgro"; - when(mockAuthDAO.getUserAuth(key)).thenReturn(null); + String key2 = "sowgro"; + when(mockAuthDAO.getUserAuth(key2)).thenReturn(null); - assertThrows(IllegalAccessException.class, () -> authService.keyIsValid(key)); + assertThrows(IllegalAccessException.class, () -> authService.keyIsValid(key2)); } @Test void keyHasAccessToCupboard1() throws IOException { - String key = "sowgro"; - when(mockAuthDAO.getUserAuth(key)).thenReturn(null); + String key2 = "sowgro"; + when(mockAuthDAO.getUserAuth(key2)).thenReturn(null); - assertThrows(IllegalAccessException.class, () -> authService.keyHasAccessToCupboard(key)); + assertThrows(IllegalAccessException.class, () -> authService.keyHasAccessToCupboard(key2)); } @Test void keyHasAccessToCupboard2() throws IOException { - String key = "sowgro"; + String key2 = "sowgro"; UserAuth userAuth = new UserAuth("sowgro", "sowgro", LocalDateTime.MAX); User user = new User("sowgro", 8675309, List.of(), User.UserType.HELPER); - when(mockAuthDAO.getUserAuth(key)).thenReturn(userAuth); - when(mockUserService.getUser(key)).thenReturn(user); + when(mockAuthDAO.getUserAuth(key2)).thenReturn(userAuth); + when(mockUserService.getUser(key2)).thenReturn(user); - assertThrows(IllegalAccessException.class, () -> authService.keyHasAccessToCupboard(key)); + assertThrows(IllegalAccessException.class, () -> authService.keyHasAccessToCupboard(key2)); } } diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/service/CupboardServiceTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/service/CupboardServiceTest.java index 57cb0bf..d1109c5 100644 --- a/ufund-api/src/test/java/com/ufund/api/ufundapi/service/CupboardServiceTest.java +++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/service/CupboardServiceTest.java @@ -15,22 +15,22 @@ import com.ufund.api.ufundapi.model.Need.GoalType; import com.ufund.api.ufundapi.persistence.CupboardDAO; @Tag("Service-tier") -public class CupboardServiceTest { +class CupboardServiceTest { private CupboardDAO mockCupboardDAO; private CupboardService cupboardService; private AuthService mockAuthService; @BeforeEach - public void setupCupboardService() { + void setupCupboardService() { mockCupboardDAO = mock(CupboardDAO.class); - AuthService mockAuthService = mock(AuthService.class); + mockAuthService = mock(AuthService.class); cupboardService = new CupboardService(mockAuthService, mockCupboardDAO); this.mockAuthService = mock(AuthService.class); } @Test - public void testCreateNeed() throws IOException, DuplicateKeyException { + void testCreateNeed() throws IOException, DuplicateKeyException { // Setup String name = "Jellyfish"; String location = "Atlantis"; @@ -54,7 +54,7 @@ public class CupboardServiceTest { } @Test - public void testCreateNeedBadGoal() throws IOException { + void testCreateNeedBadGoal() throws IOException { // Setup String name = "Jellyfish"; String location = "Atlantis"; @@ -69,16 +69,13 @@ public class CupboardServiceTest { when(mockCupboardDAO.addNeed(any())).thenReturn(need); when(mockCupboardDAO.getNeeds()).thenReturn(new Need[0]); - // Invoke - // Need response = cupboardService.createNeed(name, maxGoal, type); - // Analyze assertThrows(IllegalArgumentException.class, () -> cupboardService.createNeed(name, location, image, maxGoal, type, urgent, description)); } @Test - public void testCreateNeedBadPhysicalGoal() throws IOException { + void testCreateNeedBadPhysicalGoal() throws IOException { // Setup String name = "Jellyfish"; String location = "Atlantis"; @@ -93,16 +90,13 @@ public class CupboardServiceTest { when(mockCupboardDAO.addNeed(any())).thenReturn(need); when(mockCupboardDAO.getNeeds()).thenReturn(new Need[0]); - // Invoke - // Need response = cupboardService.createNeed(name, maxGoal, type); - // Analyze assertThrows(IllegalArgumentException.class, () -> cupboardService.createNeed(name, location, image, maxGoal, type, urgent, description)); } @Test - public void testCreateNeedBadBlankFields() throws IOException { + void testCreateNeedBadBlankFields() throws IOException { // Setup String name = ""; String location = "Atlantis"; @@ -117,16 +111,13 @@ public class CupboardServiceTest { when(mockCupboardDAO.addNeed(any())).thenReturn(need); when(mockCupboardDAO.getNeeds()).thenReturn(new Need[0]); - // Invoke - // Need response = cupboardService.createNeed(name, maxGoal, type); - // Analyze assertThrows(IllegalArgumentException.class, () -> cupboardService.createNeed(name, location, image, maxGoal, type, urgent, description)); } @Test - public void testCreateNeedNullFields() throws IOException { + void testCreateNeedNullFields() throws IOException { // Setup String name = ""; String location = "Atlantis"; @@ -141,16 +132,13 @@ public class CupboardServiceTest { when(mockCupboardDAO.addNeed(any())).thenReturn(need); when(mockCupboardDAO.getNeeds()).thenReturn(new Need[0]); - // Invoke - // Need response = cupboardService.createNeed(name, maxGoal, type); - // Analyze assertThrows(IllegalArgumentException.class, () -> cupboardService.createNeed(name, location, image, maxGoal, type, urgent, description)); } @Test - public void testCreateNeedDuplicate() throws IOException { + void testCreateNeedDuplicate() throws IOException { // Setup String name = "Jellyfish"; String location = "Atlantis"; @@ -166,16 +154,13 @@ public class CupboardServiceTest { when(mockCupboardDAO.addNeed(any())).thenReturn(need); when(mockCupboardDAO.getNeeds()).thenReturn(needs); - // Invoke - // Need response = cupboardService.createNeed(name, maxGoal, type); - // Analyze assertThrows(DuplicateKeyException.class, () -> cupboardService.createNeed(name, location, image, maxGoal, type, urgent, description)); } @Test - public void testSearchNeeds() throws IOException { + void testSearchNeeds() throws IOException { // Setup String name = "Jellyfish"; String location = "Atlantis"; @@ -199,7 +184,7 @@ public class CupboardServiceTest { } @Test - public void testSearchNeedsFail() throws IOException { + void testSearchNeedsFail() throws IOException { // Setup String name = "Jellyfish"; String location = "Atlantis"; @@ -222,7 +207,7 @@ public class CupboardServiceTest { } @Test - public void testGetNeed() throws IOException { + void testGetNeed() throws IOException { // Setup String name = "Jellyfish"; String location = "Atlantis"; @@ -244,7 +229,7 @@ public class CupboardServiceTest { } @Test - public void testUpdateNeed() throws IOException { + void testUpdateNeed() throws IOException { // Setup String name = "Jellyfish"; String location = "Atlantis"; @@ -267,7 +252,7 @@ public class CupboardServiceTest { } @Test - public void testUpdateNeedBadGoal() throws IOException { + void testUpdateNeedBadGoal() throws IOException { // Setup String name = "Jellyfish"; String location = "Atlantis"; @@ -289,7 +274,7 @@ public class CupboardServiceTest { } @Test - public void testUpdateNeedBadPhysicalGoal() throws IOException { + void testUpdateNeedBadPhysicalGoal() throws IOException { // Setup String name = "Jellyfish"; String location = "Atlantis"; @@ -311,7 +296,7 @@ public class CupboardServiceTest { } @Test - public void testUpdateNeedBlankFields() throws IOException { + void testUpdateNeedBlankFields() throws IOException { // Setup String name = "Jellyfish"; String location = "Atlantis"; @@ -333,7 +318,7 @@ public class CupboardServiceTest { } @Test - public void testUpdateNeedNotMatchingIDs() throws IOException { + void testUpdateNeedNotMatchingIDs() throws IOException { // Setup String name = "Jellyfish"; String location = "Atlantis"; @@ -342,7 +327,6 @@ public class CupboardServiceTest { boolean urgent = false; String image = ""; String description = ""; - var need = new Need(name, image, location, maxGoal, type, urgent, description); // passed in blank name, should throw error Need newNeed = new Need(name, image, location, maxGoal, type, urgent, description); @@ -355,7 +339,7 @@ public class CupboardServiceTest { } @Test - public void testDeleteNeed() throws IOException { + void testDeleteNeed() throws IOException { // Setup String name = "Jellyfish"; String location = "Atlantis"; diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/service/UserServiceTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/service/UserServiceTest.java index 6234416..74f5c63 100644 --- a/ufund-api/src/test/java/com/ufund/api/ufundapi/service/UserServiceTest.java +++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/service/UserServiceTest.java @@ -16,21 +16,21 @@ import com.ufund.api.ufundapi.DuplicateKeyException; import com.ufund.api.ufundapi.model.User; import com.ufund.api.ufundapi.persistence.UserDAO; -public class UserServiceTest { +class UserServiceTest { private UserService userService; private UserDAO mockUserDAO; @BeforeEach - public void setupUserService() { + void setupUserService() { mockUserDAO = mock(UserDAO.class); CupboardService mockCupboardService = mock(CupboardService.class); userService = new UserService(mockUserDAO, mockCupboardService); } @Test - public void testCreateUser() throws IOException, DuplicateKeyException { + void testCreateUser() throws IOException, DuplicateKeyException { // Setup String username = "Jelly"; String password = "Fish"; @@ -47,7 +47,7 @@ public class UserServiceTest { } @Test - public void testCreateUserDuplicate() throws IOException { + void testCreateUserDuplicate() throws IOException { // Setup String username = "Jelly"; String password = "Fish"; @@ -62,7 +62,7 @@ public class UserServiceTest { } @Test - public void testGetUser() throws IOException { + void testGetUser() throws IOException { // Setup String username = "Jelly"; String password = "Fish"; @@ -76,7 +76,7 @@ public class UserServiceTest { } @Test - public void testGetUserBlank() throws IOException { + void testGetUserBlank() throws IOException { // Setup String username = "Jelly"; String password = "Fish"; @@ -89,7 +89,7 @@ public class UserServiceTest { assertNull(userService.getUser(username)); } - @Test public void testGetUserCount() throws IOException { + @Test void testGetUserCount() throws IOException { // Setup String username = "Jelly"; String password = "Fish"; @@ -105,12 +105,12 @@ public class UserServiceTest { int userCount = userService.getUserCount(); // Analyze - assertEquals(userCount, 1); + assertEquals(1, userCount); } @Test - public void testUpdateUser() throws IOException { + void testUpdateUser() throws IOException { // Setup String username = "Jelly"; String password = "Fish"; @@ -128,7 +128,7 @@ public class UserServiceTest { } @Test - public void testUpdateUserDifferentUsernames() throws IOException { + void testUpdateUserDifferentUsernames() throws IOException { // Setup String username = "Jelly"; String password = "Fish"; @@ -146,7 +146,7 @@ public class UserServiceTest { } @Test - public void testDeleteUser() throws IOException { + void testDeleteUser() throws IOException { // Setup String username = "Jelly"; String password = "Fish"; |