aboutsummaryrefslogtreecommitdiff
path: root/src/test/model/EventLogTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/model/EventLogTest.java')
-rw-r--r--src/test/model/EventLogTest.java56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/test/model/EventLogTest.java b/src/test/model/EventLogTest.java
new file mode 100644
index 0000000..948aa4e
--- /dev/null
+++ b/src/test/model/EventLogTest.java
@@ -0,0 +1,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());
+ }
+}