-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccountListTest.java
77 lines (71 loc) · 2.49 KB
/
AccountListTest.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
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
/**
* @author Matthew Olson
*/
public class AccountListTest {
private AccountList accountList = AccountList.getInstance();
@BeforeEach
public void setup() {
AccountList.getInstance().getAccounts().clear();
}
@AfterEach
public void tearDown() {
AccountList.getInstance().getAccounts().clear();
}
@Test
public void testaddaccountFound(){
Account account = new Account("username", "password");
accountList.addAccount(account);
DataWriter.saveAllAccounts();
assertEquals(account, accountList.getAccount("username"));
}
@Test
public void testaddaccountnotFound(){
Account account = new Account("username", "password");
accountList.addAccount(account);
DataWriter.saveAllAccounts();
assertEquals(null, accountList.getAccount("NewUser"));
}
@Test
public void testaddaccountnullPassword(){
Account account = new Account("username", null);
accountList.addAccount(account);
DataWriter.saveAllAccounts();
assertEquals(account, accountList.getAccount("username"));
}
@Test
public void testaddaccountnullUsername(){
Account account = new Account(null, "password");
accountList.addAccount(account);
DataWriter.saveAllAccounts();
assertEquals(account, accountList.getAccount(null));
}
@Test
public void testgetaccountDuplicate(){
// Add a account to accountlist
Account account = new Account("username", "password");
Account account2 = new Account("username", "password");
ArrayList<Account> expected = new ArrayList<Account>();
expected.add(account);
expected.add(account2);
assertEquals(account, accountList.getAccount("username"));
}
@Test
public void testgetaccountNullUsername(){
Account account = new Account(null, "password");
ArrayList<Account> expected = new ArrayList<Account>();
expected.add(account);
assertEquals(expected.equals(account), false);
}
@Test
public void testgetaccountNullPassword(){
Account account = new Account("Username", null);
ArrayList<Account> expected = new ArrayList<Account>();
expected.add(account);
assertEquals(expected.equals(account), false);
}
}