summaryrefslogtreecommitdiff
path: root/same/src/test/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'same/src/test/java/com')
-rw-r--r--same/src/test/java/com/orbekk/util/WorkQueueTest.java37
1 files changed, 37 insertions, 0 deletions
diff --git a/same/src/test/java/com/orbekk/util/WorkQueueTest.java b/same/src/test/java/com/orbekk/util/WorkQueueTest.java
new file mode 100644
index 0000000..ab6e138
--- /dev/null
+++ b/same/src/test/java/com/orbekk/util/WorkQueueTest.java
@@ -0,0 +1,37 @@
+package com.orbekk.util;
+
+import static org.junit.Assert.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+
+public class WorkQueueTest {
+ @Test
+ public void testPerformsWork() throws Exception {
+ final ArrayList<Integer> doubled = new ArrayList<Integer>();
+ WorkQueue<Integer> worker = new WorkQueue<Integer>() {
+ @Override protected void onChange() {
+ List<Integer> list = getAndClear();
+ for (int x : list) {
+ doubled.add(x * 2);
+ }
+ synchronized (doubled) {
+ doubled.notifyAll();
+ }
+ }
+ };
+
+ synchronized (doubled) {
+ worker.start();
+ worker.add(1);
+ doubled.wait();
+ worker.interrupt();
+ }
+
+ worker.join();
+ assertEquals(2, (int)doubled.get(0));
+ }
+
+}