From 211fd778ac9011ec79d745767b7d23c8de738003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjetil=20=C3=98rbekk?= Date: Tue, 31 Jan 2012 10:51:12 +0100 Subject: =?UTF-8?q?WorkList=20=3D>=20WorkQueue=20=E2=80=93=20A=20worker=20?= =?UTF-8?q?thread=20helper=20class.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/java/com/orbekk/util/WorkQueueTest.java | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 same/src/test/java/com/orbekk/util/WorkQueueTest.java (limited to 'same/src/test') 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 doubled = new ArrayList(); + WorkQueue worker = new WorkQueue() { + @Override protected void onChange() { + List 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)); + } + +} -- cgit v1.2.3