Richard Schmidt
11 months ago
2 changed files with 64 additions and 29 deletions
@ -0,0 +1,64 @@ |
|||
import static org.junit.jupiter.api.Assertions.*; |
|||
import org.junit.jupiter.api.Test; |
|||
import java.io.File; |
|||
import java.util.List; |
|||
|
|||
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()); |
|||
} |
|||
|
|||
|
|||
@Test |
|||
public void testSaveAndReadFromJsonFile() { |
|||
String filename = "test_users.json"; |
|||
String id = "2"; |
|||
String userName = "testUser2"; |
|||
String password = "password456"; |
|||
String birthday = "2001-01-01"; |
|||
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()); |
|||
assertEquals(userName, savedUser.getUserName()); |
|||
assertEquals(birthday, savedUser.getBirthday()); |
|||
assertEquals(firstName, savedUser.getFirstName()); |
|||
assertEquals(surname, savedUser.surname()); |
|||
|
|||
// Clean up - delete the test file after the test |
|||
File file = new File(filename); |
|||
file.delete(); |
|||
} |
|||
|
|||
|
|||
} |
@ -1,29 +0,0 @@ |
|||
import static org.junit.jupiter.api.Assertions.*; |
|||
|
|||
import org.junit.jupiter.api.Test; |
|||
|
|||
class CreateUsertTest { |
|||
|
|||
@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()); |
|||
} |
|||
|
|||
|
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue