blob: 948aa4e82b26dde4cdedf8414ab9a8f117339e9e (
plain)
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
|
package model;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Unit tests for the EventLog class
*/
public class EventLogTest {
private Event e1;
private Event e2;
private Event e3;
@BeforeEach
public void loadEvents() {
e1 = new Event("A1");
e2 = new Event("A2");
e3 = new Event("A3");
EventLog el = EventLog.getInstance();
el.logEvent(e1);
el.logEvent(e2);
el.logEvent(e3);
}
@Test
public void testLogEvent() {
List<Event> l = new ArrayList<Event>();
EventLog el = EventLog.getInstance();
for (Event next : el) {
l.add(next);
}
assertTrue(l.contains(e1));
assertTrue(l.contains(e2));
assertTrue(l.contains(e3));
}
@Test
public void testClear() {
EventLog el = EventLog.getInstance();
el.clear();
Iterator<Event> itr = el.iterator();
assertTrue(itr.hasNext()); // After log is cleared, the clear log event is added
assertEquals("Event log cleared.", itr.next().getDescription());
assertFalse(itr.hasNext());
}
}
|