-
Notifications
You must be signed in to change notification settings - Fork 0
/
UserListTest.java
58 lines (45 loc) · 1.62 KB
/
UserListTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
//Tested by Nick Arboscello
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
public class UserListTest {
private UserList userList;
/**
* Set up the UserList instance before each test.
*/
@Before
public void setUp() {
userList = UserList.getInstance();
}
/**
* Test the addition of a new user to the user list.
* Verifies that a user is correctly added, increasing the user count.
*/
@Test
public void testAddUser() {
int initialSize = userList.getUserList().size();
UserList.addUser("testuser", "testpassword", "Test", "User", "test@example.com", 1);
assertEquals(initialSize + 1, userList.getUserList().size());
}
/**
* Test the validation of user login credentials.
* Checks if the login is valid for an existing user and rejects an invalid login.
*/
@Test
public void testIsValidLogin() {
UserList.addUser("testuser", "testpassword", "Test", "User", "test@example.com", 1);
assertTrue(UserList.isValidLogin("testuser", "testpassword"));
assertFalse(UserList.isValidLogin("testuser", "wrongpassword"));
}
/**
* Test the retrieval of a user by their username.
* Verifies that the user with the specified username is correctly retrieved.
*/
@Test
public void testGetUser() {
UserList.addUser("testuser", "testpassword", "Test", "User", "test@example.com", 1);
User testUser = UserList.getUser("testuser");
assertNotNull(testUser);
assertEquals("testuser", testUser.getUserName());
}
}