|
@ -2,6 +2,7 @@ import static org.junit.jupiter.api.Assertions.*; |
|
|
import org.junit.jupiter.api.Test; |
|
|
import org.junit.jupiter.api.Test; |
|
|
import java.io.File; |
|
|
import java.io.File; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.*; |
|
|
|
|
|
|
|
|
class CreateUserTest { |
|
|
class CreateUserTest { |
|
|
|
|
|
|
|
@ -60,5 +61,36 @@ class CreateUserTest { |
|
|
file.delete(); |
|
|
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"; |
|
|
|
|
|
|
|
|
|
|
|
// 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(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|