aboutsummaryrefslogtreecommitdiff
path: root/ufund-api/src/test/java/com/ufund/api
diff options
context:
space:
mode:
authorGunther6070 <haydenhartman10@yahoo.com>2025-03-17 16:12:56 -0400
committerGunther6070 <haydenhartman10@yahoo.com>2025-03-17 16:12:56 -0400
commitebccd8c4bddc9799e91a3149040efb4cac647c45 (patch)
tree0ea4dbb616005cc833b7e877bc56eaed412f163d /ufund-api/src/test/java/com/ufund/api
parent60dd2db634de6146671be9546fb3e4bdf6d9b7d9 (diff)
parent251f30c402700169213ed4560a7797a785a50e78 (diff)
downloadJellySolutions-ebccd8c4bddc9799e91a3149040efb4cac647c45.tar.gz
JellySolutions-ebccd8c4bddc9799e91a3149040efb4cac647c45.tar.bz2
JellySolutions-ebccd8c4bddc9799e91a3149040efb4cac647c45.zip
Merge branch 'service-tests' of https://github.com/RIT-SWEN-261-02/team-project-2245-swen-261-02-2b into service-tests
Diffstat (limited to 'ufund-api/src/test/java/com/ufund/api')
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/controller/UserControllerTest.java32
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java8
-rw-r--r--ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserFileDAOTest.java8
3 files changed, 16 insertions, 32 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 a25ec8a..7bedd3e 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
@@ -44,9 +44,9 @@ public class UserControllerTest {
public void testGetUser() throws IOException { // getUser may throw IOException
// 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 service will return the User object
+ User user = User.create(username, "pass");
+ String key = UserAuth.generate(username).getKey( );
+ // When the same id is passed in, our mock User DAO will return the User object
when(mockUserService.getUser(username)).thenReturn(user);
@@ -112,7 +112,7 @@ public class UserControllerTest {
// Setup
String username = "Test";
String password = "Pass";
- User user = new User(username);
+ User user = User.create(username, "pass");
// when createUser is called, return true simulating successful
// creation and save
when(mockUserService.createUser(username, password)).thenReturn(user);
@@ -183,7 +183,7 @@ public class UserControllerTest {
public void testUpdateUser() throws IOException { // updateUser may throw IOException
// Setup
String username = "Test";
- User user = new User("Bob");
+ User user = User.create("Bob", "pass");
String key = UserAuth.generate(username).getKey();
// when updateUser is called, return true simulating successful
// update and save
@@ -201,7 +201,7 @@ public class UserControllerTest {
public void testUpdateUserFailed() throws IOException { // updateUser may throw IOException
// Setup
String username = "Test";
- User user = new User("Bob");
+ User user = User.create("Bob", "pass");
String key = UserAuth.generate(username).getKey();
// when updateUser is called, return true simulating successful
// update and save
@@ -218,25 +218,9 @@ public class UserControllerTest {
public void testUpdateUserInvalidParameter() throws IOException { // updateUser may throw IOException
// Setup
String username = "Test";
- User user = new User("Bob");
- String key = UserAuth.generate(username).getKey();
- // When updateUser is called on the Mock User service, throw a Invalid Parameter exception
- doThrow(new InvalidParameterException()).when(mockUserService).updateUser(user, username);
-
- // Invoke
- ResponseEntity<User> response = userController.updateUser(user, username, key);
-
- // Analyze
- assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
- }
-
- @Test
- public void testUpdateUserHandleException() throws IOException { // updateUser may throw IOException
- // Setup
- String username = "Test";
- User user = new User("Bob");
+ User user = User.create("Bob", "pass");
String key = UserAuth.generate(username).getKey();
- // When updateUser is called on the Mock User service, throw an IOException
+ // When updateUser is called on the Mock User DAO, throw an IOException
doThrow(new IOException()).when(mockUserService).updateUser(user, username);
// Invoke
diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java
index 1725190..5e017dd 100644
--- a/ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java
+++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/model/UserTest.java
@@ -13,7 +13,7 @@ public class UserTest {
String name = "Bob";
- User user = new User(name);
+ User user = User.create(name, "pass");
assertNotNull(user);
@@ -36,7 +36,7 @@ public class UserTest {
String expectedName = "Bob";
- User user = new User(expectedName);
+ User user = User.create(expectedName, "pass");
Need need = new Need("Test", 0, 100, Need.GoalType.MONETARY);
Need[] needs = { need };
@@ -51,7 +51,7 @@ public class UserTest {
String expectedName = "Bob";
- User user = new User(expectedName);
+ User user = User.create(expectedName, "pass");
Need need = new Need("Test", 0, 100, Need.GoalType.MONETARY);
Need need2 = new Need("Test2", 0, 100, Need.GoalType.MONETARY);
@@ -68,7 +68,7 @@ public class UserTest {
String expectedName = "Bob";
- User user = new User(expectedName);
+ User user = User.create(expectedName, "pass");
assertFalse(user.verifyPassword(expectedName));
diff --git a/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserFileDAOTest.java b/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserFileDAOTest.java
index b802669..9361188 100644
--- a/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserFileDAOTest.java
+++ b/ufund-api/src/test/java/com/ufund/api/ufundapi/persistence/UserFileDAOTest.java
@@ -27,9 +27,9 @@ public class UserFileDAOTest {
public void setupHeroFileDAO() throws IOException {
mockObjectMapper = mock(ObjectMapper.class);
testUsers = new User[3];
- testUsers[0] = new User("bob");
- testUsers[1] = new User("admin");
- testUsers[2] = new User("jelly12");
+ testUsers[0] = User.create("bob", "pass");
+ testUsers[1] = User.create("admin", "pass");
+ testUsers[2] = User.create("jelly12", "pass");
// When the object mapper is supposed to read from the file
// the mock object mapper will return the hero array above
@@ -75,7 +75,7 @@ public class UserFileDAOTest {
@Test
public void createUserTest() throws IOException {
- User newUser = new User("keshey");
+ User newUser = User.create("keshey", "pass");
userFileDAO.addUser(newUser);
User actualUser = userFileDAO.getUser("keshey");