diff options
author | Gunther6070 <haydenhartman10@yahoo.com> | 2025-02-27 13:02:20 -0500 |
---|---|---|
committer | Gunther6070 <haydenhartman10@yahoo.com> | 2025-02-27 13:02:20 -0500 |
commit | 708bfd1ac3be6a7032875240157b71f7eaeed6af (patch) | |
tree | 7dbf28fb66b9567c317bc046bca81f93874c0040 | |
parent | 0b1a83093b2255f3dcebc3b55bb638304c58bf47 (diff) | |
download | JellySolutions-708bfd1ac3be6a7032875240157b71f7eaeed6af.tar.gz JellySolutions-708bfd1ac3be6a7032875240157b71f7eaeed6af.tar.bz2 JellySolutions-708bfd1ac3be6a7032875240157b71f7eaeed6af.zip |
Updated comments and formatting
-rw-r--r-- | ufund-api/src/test/java/com/ufund/api/ufundapi/controller/UserControllerTest.java | 62 |
1 files changed, 32 insertions, 30 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 1bd2e8e..c4a3a08 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,11 +1,14 @@ package com.ufund.api.ufundapi.controller; - import java.io.IOException; -import org.junit.jupiter.api.*; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Mockito.*; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import static org.mockito.Mockito.doThrow; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -21,16 +24,15 @@ public class UserControllerTest { public void setupUserController() { mockUserDAO = mock(UserFileDAO.class); userController = new UserController(mockUserDAO); - } @Test - public void testGetUser() throws IOException { // getHero may throw IOException + public void testGetUser() throws IOException { // getUser may throw IOException // Setup String username = "Test"; User user = new User(username); - // When the same id is passed in, our mock Hero DAO will return the Hero object + // When the same id is passed in, our mock User DAO will return the User object when(mockUserDAO.getUser(username)).thenReturn(user); // Invoke @@ -42,11 +44,11 @@ public class UserControllerTest { } @Test - public void testGetUserNotFound() throws Exception { // createHero may throw IOException + public void testGetUserNotFound() throws Exception { // createUser may throw IOException // Setup String username = "Test"; - // When the same id is passed in, our mock Hero DAO will return null, simulating - // no hero found + // 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 @@ -57,10 +59,10 @@ public class UserControllerTest { } @Test - public void testGetHeroHandleException() throws Exception { // createHero may throw IOException + public void testGetUserHandleException() throws Exception { // createUser may throw IOException // Setup String username = "Test"; - // When getHero is called on the Mock Hero DAO, throw an IOException + // When getUser is called on the Mock User DAO, throw an IOException doThrow(new IOException()).when(mockUserDAO).getUser(username); // Invoke @@ -76,11 +78,11 @@ public class UserControllerTest { ****************************************************************/ @Test - public void testCreateHero() throws IOException { // createHero may throw IOException + public void testCreateUser() throws IOException { // createUser may throw IOException // Setup String username = "Test"; User user = new User(username); - // when createHero is called, return true simulating successful + // when createUser is called, return true simulating successful // creation and save when(mockUserDAO.createUser(user)).thenReturn(user); @@ -93,11 +95,11 @@ public class UserControllerTest { } @Test - public void testCreateHeroFailed() throws IOException { // createHero may throw IOException + public void testCreateUserFailed() throws IOException { // createUser may throw IOException // Setup String username = "Test"; User user = new User(username); - // when createHero is called, return false simulating failed + // when createUser is called, return false simulating failed // creation and save when(mockUserDAO.createUser(user)).thenReturn(null); @@ -109,12 +111,12 @@ public class UserControllerTest { } @Test - public void testCreateHeroHandleException() throws IOException { // createHero may throw IOException + public void testCreateUserHandleException() throws IOException { // createUser may throw IOException // Setup String username = "Test"; User user = new User(username); - // When createHero is called on the Mock Hero DAO, throw an IOException + // When createUser is called on the Mock User DAO, throw an IOException doThrow(new IOException()).when(mockUserDAO).createUser(user); // Invoke @@ -125,11 +127,11 @@ public class UserControllerTest { } @Test - public void testUpdateHero() throws IOException { // updateHero may throw IOException + public void testUpdateUser() throws IOException { // updateUser may throw IOException // Setup String username = "Test"; User user = new User("Bob"); - // when updateHero is called, return true simulating successful + // when updateUser is called, return true simulating successful // update and save when(mockUserDAO.updateUser(user, username)).thenReturn(user); ResponseEntity<User> response = userController.updateUser(user, username); @@ -143,11 +145,11 @@ public class UserControllerTest { } @Test - public void testUpdateHeroFailed() throws IOException { // updateHero may throw IOException + public void testUpdateUserFailed() throws IOException { // updateUser may throw IOException // Setup String username = "Test"; User user = new User("Bob"); - // when updateHero is called, return true simulating successful + // when updateUser is called, return true simulating successful // update and save when(mockUserDAO.updateUser(user, username)).thenReturn(null); @@ -159,11 +161,11 @@ public class UserControllerTest { } @Test - public void testUpdateHeroHandleException() throws IOException { // updateHero may throw IOException + public void testUpdateUserHandleException() throws IOException { // updateUser may throw IOException // Setup String username = "Test"; User user = new User("Bob"); - // When updateHero is called on the Mock Hero DAO, throw an IOException + // When updateUser is called on the Mock User DAO, throw an IOException doThrow(new IOException()).when(mockUserDAO).updateUser(user, username); // Invoke @@ -174,10 +176,10 @@ public class UserControllerTest { } @Test - public void testDeleteHero() throws IOException { // deleteHero may throw IOException + public void testDeleteUser() throws IOException { // deleteUser may throw IOException // Setup String username = "Test"; - // when deleteHero is called return true, simulating successful deletion + // when deleteUser is called return true, simulating successful deletion when(mockUserDAO.deleteUser(username)).thenReturn(true); // Invoke @@ -188,10 +190,10 @@ public class UserControllerTest { } @Test - public void testDeleteHeroNotFound() throws IOException { // deleteHero may throw IOException + public void testDeleteUserNotFound() throws IOException { // deleteUser may throw IOException // Setup String username = "Test"; - // when deleteHero is called return false, simulating failed deletion + // when deleteUser is called return false, simulating failed deletion when(mockUserDAO.deleteUser(username)).thenReturn(false); // Invoke @@ -202,10 +204,10 @@ public class UserControllerTest { } @Test - public void testDeleteHeroHandleException() throws IOException { // deleteHero may throw IOException + public void testDeleteUserHandleException() throws IOException { // deleteUser may throw IOException // Setup String username = "Test"; - // When deleteHero is called on the Mock Hero DAO, throw an IOException + // When deleteUser is called on the Mock User DAO, throw an IOException doThrow(new IOException()).when(mockUserDAO).deleteUser(username); // Invoke @@ -214,5 +216,5 @@ public class UserControllerTest { // Analyze assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); } - + } |