diff options
author | Gunther6070 <haydenhartman10@yahoo.com> | 2025-03-06 08:16:42 -0500 |
---|---|---|
committer | Gunther6070 <haydenhartman10@yahoo.com> | 2025-03-06 08:17:38 -0500 |
commit | b3487d216b576a2b2614674eae0a1be139eb1ea3 (patch) | |
tree | d272cb8ab4c56bf952945cf59d7ee9e6f772edf0 /ufund-api/src/test/java/com | |
parent | d752a75a8496f0c5abe3d8ee41af95ae5b7875c3 (diff) | |
download | JellySolutions-b3487d216b576a2b2614674eae0a1be139eb1ea3.tar.gz JellySolutions-b3487d216b576a2b2614674eae0a1be139eb1ea3.tar.bz2 JellySolutions-b3487d216b576a2b2614674eae0a1be139eb1ea3.zip |
Fixed some UserController tests
Diffstat (limited to 'ufund-api/src/test/java/com')
-rw-r--r-- | ufund-api/src/test/java/com/ufund/api/ufundapi/controller/UserControllerTest.java | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/UserControllerTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/UserControllerTest.java index 496c68c..d189836 100644 --- a/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/UserControllerTest.java +++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/controller/UserControllerTest.java @@ -1,6 +1,7 @@ package com.ufund.api.ufundapi.controller; import java.io.IOException; +import java.util.HashMap; import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.BeforeEach; @@ -13,18 +14,21 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import com.ufund.api.ufundapi.model.User; +import com.ufund.api.ufundapi.model.UserAuth; +import com.ufund.api.ufundapi.persistence.UserAuthFIleDAO; import com.ufund.api.ufundapi.persistence.UserFileDAO; @Tag("Controller-tier") public class UserControllerTest { private UserController userController; private UserFileDAO mockUserDAO; + private UserAuthFIleDAO mockAuthUserDAO; @BeforeEach public void setupUserController() { mockUserDAO = mock(UserFileDAO.class); - userController = new UserController(mockUserDAO); - + mockAuthUserDAO = mock(UserAuthFIleDAO.class); + userController = new UserController(mockUserDAO, mockAuthUserDAO); } @Test @@ -32,11 +36,13 @@ public class UserControllerTest { // Setup String username = "Test"; User user = new User(username); + String key = UserAuth.generate(username).getKey(); // When the same id is passed in, our mock User DAO will return the User object when(mockUserDAO.getUser(username)).thenReturn(user); + // Invoke - ResponseEntity<User> response = userController.getUser(username); + ResponseEntity<User> response = userController.getUser(username, key); // Analyze assertEquals(HttpStatus.OK, response.getStatusCode()); @@ -47,12 +53,14 @@ public class UserControllerTest { public void testGetUserNotFound() throws Exception { // createUser may throw IOException // Setup String username = "Test"; + String key = UserAuth.generate(username).getKey(); // When the same id is passed in, our mock User DAO will return null, simulating // no User found when(mockUserDAO.getUser(username)).thenReturn(null); + // Invoke - ResponseEntity<User> response = userController.getUser(username); + ResponseEntity<User> response = userController.getUser(username, key); // Analyze assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode()); @@ -62,11 +70,12 @@ public class UserControllerTest { public void testGetUserHandleException() throws Exception { // createUser may throw IOException // Setup String username = "Test"; + String key = UserAuth.generate(username).getKey(); // When getUser is called on the Mock User DAO, throw an IOException doThrow(new IOException()).when(mockUserDAO).getUser(username); // Invoke - ResponseEntity<User> response = userController.getUser(username); + ResponseEntity<User> response = userController.getUser(username, key); // Analyze assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); @@ -82,12 +91,15 @@ public class UserControllerTest { // Setup String username = "Test"; User user = new User(username); + String key = UserAuth.generate(username).getKey(); // when createUser is called, return true simulating successful // creation and save when(mockUserDAO.addUser(user)).thenReturn(user); + + // Invoke - ResponseEntity<User> response = userController.createUser(user); + ResponseEntity<User> response = userController.createUser(params); // Analyze assertEquals(HttpStatus.CREATED, response.getStatusCode()); |