|
|
@ -8,23 +8,22 @@ class CreateUserTest { |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testCreateUser() { |
|
|
|
String id = "1"; |
|
|
|
String userName = "testUser"; |
|
|
|
String password = "password123"; |
|
|
|
String birthday = "2000-01-01"; |
|
|
|
String firstName = "John"; |
|
|
|
String surname = "Doe"; |
|
|
|
|
|
|
|
CreateUser user = new CreateUser(id, userName, password, birthday, firstName, surname); |
|
|
|
|
|
|
|
assertEquals(id, user.getId()); |
|
|
|
assertEquals(userName, user.getUserName()); |
|
|
|
assertEquals(birthday, user.getBirthday()); |
|
|
|
assertEquals(firstName, user.getFirstName()); |
|
|
|
assertEquals(surname, user.surname()); |
|
|
|
|
|
|
|
// Password should be hashed |
|
|
|
assertNotEquals(password, user.getPassword()); |
|
|
|
String id = "1"; |
|
|
|
String userName = "testUser"; |
|
|
|
String password = "password123"; |
|
|
|
String birthday = "2000-01-01"; |
|
|
|
String firstName = "John"; |
|
|
|
String surname = "Doe"; |
|
|
|
|
|
|
|
CreateUser user = new CreateUser(id, userName, password, birthday, firstName, surname); |
|
|
|
|
|
|
|
assertEquals(id, user.getId()); |
|
|
|
assertEquals(userName, user.getUserName()); |
|
|
|
assertEquals(birthday, user.getBirthday()); |
|
|
|
assertEquals(firstName, user.getFirstName()); |
|
|
|
assertEquals(surname, user.surname()); |
|
|
|
|
|
|
|
assertNotEquals(password, user.getPassword()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -38,16 +37,12 @@ class CreateUserTest { |
|
|
|
String firstName = "Jane"; |
|
|
|
String surname = "Doe"; |
|
|
|
|
|
|
|
// Create a user |
|
|
|
CreateUser user = new CreateUser(id, userName, password, birthday, firstName, surname); |
|
|
|
|
|
|
|
// Save user to JSON file |
|
|
|
user.saveToJsonFile(filename); |
|
|
|
|
|
|
|
// Read users from JSON file |
|
|
|
List<CreateUser> userList = CreateUser.readUserListFromJsonFile(filename); |
|
|
|
|
|
|
|
// Ensure that the user has been saved and can be read correctly |
|
|
|
assertEquals(1, userList.size()); |
|
|
|
CreateUser savedUser = userList.get(0); |
|
|
|
assertEquals(id, savedUser.getId()); |
|
|
@ -56,37 +51,30 @@ class CreateUserTest { |
|
|
|
assertEquals(firstName, savedUser.getFirstName()); |
|
|
|
assertEquals(surname, savedUser.surname()); |
|
|
|
|
|
|
|
// Clean up - delete the test file after the test |
|
|
|
File file = new File(filename); |
|
|
|
file.delete(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testUpdateStayLoggedIn() { |
|
|
|
String filename = "test_users.json"; |
|
|
|
String id = "3"; |
|
|
|
String userName = "testUser3"; |
|
|
|
String password = "password789"; |
|
|
|
String birthday = "2002-01-01"; |
|
|
|
String firstName = "Jack"; |
|
|
|
String surname = "Doe"; |
|
|
|
String filename = "test_users.json"; |
|
|
|
String id = "3"; |
|
|
|
String userName = "testUser3"; |
|
|
|
String password = "password789"; |
|
|
|
String birthday = "2002-01-01"; |
|
|
|
String firstName = "Jack"; |
|
|
|
String surname = "Doe"; |
|
|
|
|
|
|
|
// Create a user |
|
|
|
CreateUser user = new CreateUser(id, userName, password, birthday, firstName, surname); |
|
|
|
|
|
|
|
// Save user to JSON file |
|
|
|
user.saveToJsonFile(filename); |
|
|
|
|
|
|
|
// Update stayLoggedIn flag |
|
|
|
CreateUser.updateStayLoggedIn(filename, userName, true); |
|
|
|
|
|
|
|
// Read updated user from JSON file |
|
|
|
List<CreateUser> userList = CreateUser.readUserListFromJsonFile(filename); |
|
|
|
|
|
|
|
// Ensure that the stayLoggedIn flag is updated |
|
|
|
assertTrue(userList.get(0).isStayLoggedIn()); |
|
|
|
|
|
|
|
// Clean up - delete the test file after the test |
|
|
|
File file = new File(filename); |
|
|
|
file.delete(); |
|
|
|
} |
|
|
|