-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserListTest.java
60 lines (48 loc) · 1.83 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
import static org.junit.jupiter.api.Assertions.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.Date;
public class UserListTest {
private UserList users = UserList.getInstance();
private ArrayList<User> userList = users.getUsers();
private UserList authors = UserList.getInstance();
private ArrayList<Author> authorList = authors.getAuthors();
@BeforeEach
public void setup() {
userList.clear();
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
String dateOfBirth = "10/12/2002";
Date dob = new Date();
try {
dob = dateFormat.parse(dateOfBirth);
} catch (Exception e) {
e.printStackTrace();
}
User tempUser = new User("jimmy", "johnson","jjohnson", "password", dob , "874-000-3440", "[email protected]");
userList.add(tempUser);
Author tempAuthor = new Author("samantha", "jackson","SJACK12", "sjack", dob , "980-234-2234", "[email protected]");
authorList.add(tempAuthor);
DataWriter.writeUsers(userList);
DataWriter.writeAuthors(authorList);
}
@AfterEach
public void tearDown() {
UserList.getInstance().getUsers().clear();
DataWriter.writeUsers(userList);
UserList.getInstance().getAuthors().clear();
DataWriter.writeAuthors(authorList);
}
@Test
void testHaveUserIsValid() {
User user = users.getUserByName("jjohnson");
assertEquals("jjohnson", user.getUserName());
}
@Test
void testHaveAuthorIsValid() {
Author author = authors.geAuthorByName("SJACK12");
assertEquals("SJACK12", author.getUserName());
}
}