-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserListTest.java
106 lines (100 loc) · 3.45 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import static org.junit.jupiter.api.Assertions.*;
import java.util.ArrayList;
import java.util.Date;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class UserListTest {
private UserList user = UserList.getInstance();
private ArrayList<User> users = user.getUsers();
@BeforeEach
public void setup() {
users.clear();
users.add(new User("Anne","Dennis","[email protected]",new Date(10/02/2023), "adennis2", "catsForLife",AccountType.STUDENT));
users.add(new User("Kim","Nguyen","[email protected]",new Date(10/03/1960), "kNguyen", "foodieForLife",AccountType.AUTHOR));
DataWriter.saveUsers();
}
@AfterEach
public void tearDown(){
UserList.getInstance().getUsers().clear();
DataWriter.saveUsers();
}
//Find one user name
@Test
public void testHaveUserValidFirstItemWithUsername() {
boolean hasAnne = user.haveUser("adennis2");
assertTrue(hasAnne);
}
//Find last user name
@Test
public void testHaveUserValidLastItemWithUsername(){
boolean hasKim = user.haveUser("kNguyen");
assertTrue(hasKim);
}
//Find invalid user
@Test
public void testHaveUserInValidWithUsername(){
boolean hasMatt = user.haveUser("mSmith");
assertFalse(hasMatt);
}
//Find empty username
@Test
public void testHaveUserEmptyWithUsername(){
boolean hasEmpty = user.haveUser("");
assertFalse(hasEmpty);
}
//Find null username
@Test
public void testHaveUserNullWithUsername(){
boolean hasNull = user.haveUser(null);
assertFalse(hasNull);
}
//Find first user with username and password
@Test
public void testHaveUserValidFirstItemWithUsernameAndPassword() {
boolean hasAnne = user.haveUser("adennis2","catsForLife");
assertTrue(hasAnne);
}
//Find last user with username and password
@Test
public void testHaveUserValidLastItemWithUsernameAndPassword(){
boolean hasKim = user.haveUser("kNguyen","foodieForLife");
assertTrue(hasKim);
}
//find invalid user with username and password
@Test
public void testHaveUserInValidWithUsernameAndPassword(){
boolean hasMatt = user.haveUser("mSmith","alsdkf386jhhk$j");
assertFalse(hasMatt);
}
//Find empty user with username and password
@Test
public void testHaveUserEmptyWithUsernameAndPassword(){
boolean hasEmpty = user.haveUser("","");
assertFalse(hasEmpty);
}
//find null user with username and password
@Test
public void testHaveUserNullWithUsernameAndPassword(){
boolean hasNull = user.haveUser(null,null);
assertFalse(hasNull);
}
//adding vaild user
@Test
public void testAddUserValid(){
boolean addBill = user.addUser("Bill", "Dennis", "[email protected]", new Date(01/12/2000), "bdennis", "DogLover3498", AccountType.AUTHOR);
assertTrue(addBill);
}
//adding empty user
@Test
public void testAddUserEmpty(){
boolean addEmpty = user.addUser("", "", "", new Date(), "", "", AccountType.STUDENT);
assertTrue(addEmpty);
}
//adding invalid user
@Test
public void testAddUserInValid(){
boolean addAndrew = user.addUser("Andrew", "Dennis", "[email protected]", new Date(01/12/1923), "adennis2", "catsForLife", AccountType.STUDENT);
assertFalse(addAndrew);
}
}