diff options
Diffstat (limited to 'ufund-api/src/test/java/com/ufund/api/ufundapi/service')
3 files changed, 39 insertions, 55 deletions
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"; |