diff options
Diffstat (limited to 'ufund-api/src/test/java/com/ufund/api/ufundapi/controller/UserControllerTest.java')
-rw-r--r-- | ufund-api/src/test/java/com/ufund/api/ufundapi/controller/UserControllerTest.java | 42 |
1 files changed, 21 insertions, 21 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 5542f49..5870a93 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 @@ -50,12 +50,12 @@ public class UserControllerTest { // Invoke - ResponseEntity<User> response = userController.getUser(username, key); + ResponseEntity<Object> response = userController.getUser(username, key); // Analyze assertEquals(HttpStatus.OK, response.getStatusCode()); assertNotNull(response.getBody()); - assertEquals(user.getUsername(), response.getBody().getUsername()); + assertEquals(user.getUsername(), ((User) response.getBody()).getUsername()); } @Test @@ -69,7 +69,7 @@ public class UserControllerTest { // Invoke - ResponseEntity<User> response = userController.getUser(username, key); + ResponseEntity<Object> response = userController.getUser(username, key); // Analyze assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode()); @@ -82,10 +82,10 @@ public class UserControllerTest { String key = UserAuth.generate(username).getKey(); // When getUser is called on the Mock User service, throw an IOException // doThrow(new IllegalAccessException()).when(mockUserService).getUser(username); - doThrow(new IllegalAccessException()).when(mockAuthService).authenticate(username, key); + doThrow(new IllegalAccessException()).when(mockAuthService).keyHasAccessToUser(username, key); // Invoke - ResponseEntity<User> response = userController.getUser(username, key); + ResponseEntity<Object> response = userController.getUser(username, key); // Analyze assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode()); @@ -100,7 +100,7 @@ public class UserControllerTest { doThrow(new IOException()).when(mockUserService).getUser(username); // Invoke - ResponseEntity<User> response = userController.getUser(username, key); + ResponseEntity<Object> response = userController.getUser(username, key); // Analyze assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); @@ -119,7 +119,7 @@ public class UserControllerTest { // Invoke - ResponseEntity<User> response = userController.createUser(userMap); + ResponseEntity<Object> response = userController.createUser(userMap); // Analyze assertEquals(HttpStatus.CREATED, response.getStatusCode()); @@ -138,7 +138,7 @@ public class UserControllerTest { // Invoke - ResponseEntity<User> response = userController.createUser(userMap); + ResponseEntity<Object> response = userController.createUser(userMap); // Analyze assertEquals(HttpStatus.CONFLICT, response.getStatusCode()); @@ -154,7 +154,7 @@ public class UserControllerTest { when(mockUserService.createUser(username, password)).thenThrow(DuplicateKeyException.class); // Invoke - ResponseEntity<User> response = userController.createUser(userMap); + ResponseEntity<Object> response = userController.createUser(userMap); // Analyze assertEquals(HttpStatus.CONFLICT, response.getStatusCode()); @@ -172,7 +172,7 @@ public class UserControllerTest { // Invoke - ResponseEntity<User> response = userController.createUser(userMap); + ResponseEntity<Object> response = userController.createUser(userMap); // Analyze assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); @@ -189,7 +189,7 @@ public class UserControllerTest { when(mockUserService.updateUser(user, username)).thenReturn(user); // Invoke - ResponseEntity<User> response = userController.updateUser(user, username, key); + ResponseEntity<Object> response = userController.updateUser(user, username, key); // Analyze assertEquals(HttpStatus.OK, response.getStatusCode()); @@ -207,7 +207,7 @@ public class UserControllerTest { when(mockUserService.updateUser(user, username)).thenReturn(null); // Invoke - ResponseEntity<User> response = userController.updateUser(user, username, key); + ResponseEntity<Object> response = userController.updateUser(user, username, key); // Analyze assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode()); @@ -223,7 +223,7 @@ public class UserControllerTest { doThrow(new IOException()).when(mockUserService).updateUser(user, username); // Invoke - ResponseEntity<User> response = userController.updateUser(user, username, key); + ResponseEntity<Object> response = userController.updateUser(user, username, key); // Analyze assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); @@ -237,14 +237,14 @@ public class UserControllerTest { String key = UserAuth.generate(username).getKey(); // When updateUser is called on the Mock User service, throw a Invalid Parameter exception // exception - doThrow(new IllegalAccessException()).when(mockAuthService).authenticate(username, key); + doThrow(new IllegalAccessException()).when(mockAuthService).keyHasAccessToUser(username, key); // Invoke - ResponseEntity<User> response = userController.updateUser(user, username, key); + ResponseEntity<Object> response = userController.updateUser(user, username, key); // Analyze - assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode()); + assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode()); } @Test @@ -256,7 +256,7 @@ public class UserControllerTest { when(mockUserService.deleteUser(username)).thenReturn(true); // Invoke - ResponseEntity<Boolean> response = userController.deleteUser(username, key); + ResponseEntity<Object> response = userController.deleteUser(username, key); // Analyze assertEquals(HttpStatus.OK, response.getStatusCode()); @@ -271,7 +271,7 @@ public class UserControllerTest { when(mockUserService.deleteUser(username)).thenReturn(false); // Invoke - ResponseEntity<Boolean> response = userController.deleteUser(username, key); + ResponseEntity<Object> response = userController.deleteUser(username, key); // Analyze assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode()); @@ -286,7 +286,7 @@ public class UserControllerTest { doThrow(new IOException()).when(mockUserService).deleteUser(username); // Invoke - ResponseEntity<Boolean> response = userController.deleteUser(username, key); + ResponseEntity<Object> response = userController.deleteUser(username, key); // Analyze assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); @@ -298,10 +298,10 @@ public class UserControllerTest { String username = "Test"; String key = UserAuth.generate(username).getKey(); // When deleteUser is called on the Mock User service, throw an IOException - doThrow(new IllegalAccessException()).when(mockAuthService).authenticate(username, key); + doThrow(new IllegalAccessException()).when(mockAuthService).keyHasAccessToUser(username, key); // Invoke - ResponseEntity<Boolean> response = userController.deleteUser(username, key); + ResponseEntity<Object> response = userController.deleteUser(username, key); // Analyze assertEquals(HttpStatus.UNAUTHORIZED, response.getStatusCode()); |