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)); } }