blob: ab6e138f608a5d30d30543d5abfb8ca98ced9458 (
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
|
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));
}
}
|