1 package org.apidesign.openfixed;
4 import java.util.concurrent.CountDownLatch;
6 /** Test the Calculator.createPending() behavior.
8 * @author Jaroslav Tulach <jtulach@netbeans.org>
10 public class PendingTest extends CalculatorBase {
12 public PendingTest(String testName) {
17 protected Calculator create() {
18 return Calculator.createPending();
21 public void testPendingEvents() throws Exception {
22 BlockingListener bl = new BlockingListener();
24 Calculator calc = create();
25 calc.addModificationListener(bl);
36 List<ModificationEvent> events = bl.assertEvents("Four changes together", 4);
38 assertEquals("No pending events for first event", 0, events.get(0).getPending());
39 assertEquals("Group of three, two remaining", 2, events.get(1).getPending());
40 assertEquals("Group of three, one remaining", 1, events.get(2).getPending());
41 assertEquals("Group of three, last one", 0, events.get(3).getPending());
44 static class BlockingListener extends MockListener {
45 CountDownLatch first = new CountDownLatch(1);
46 CountDownLatch cdl = new CountDownLatch(1);
49 public synchronized void modification(ModificationEvent ev) {
53 } catch (InterruptedException ex) {
54 throw new IllegalStateException(ex);
56 super.modification(ev);