Updating to NBMs from NetBeans 8.0.1 as some of them are required to run on JDK8
1 package org.apidesign.openfixed;
3 import java.util.ArrayList;
5 import junit.framework.TestCase;
7 public abstract class CalculatorBase extends TestCase {
9 public CalculatorBase(String testName) {
13 protected abstract Calculator create();
15 // BEGIN: openfixed.commontest
16 public void testSumAndListeners() throws Exception {
17 Calculator a = create();
18 MockListener l = new MockListener();
19 a.addModificationListener(l);
23 int ch = allChanges(l.assertEvents("Three changes", 3));
24 assertEquals("35 was the change", 35, ch);
25 assertEquals("Current value", 35, a.getSum());
27 int ch2 = allChanges(l.assertEvents("One change", 1));
28 assertEquals("minus five was the change", -5, ch2);
29 assertEquals("Final value", 30, a.getSum());
32 private static int allChanges(List<ModificationEvent> events) {
34 for (ModificationEvent me : events) {
35 changes += me.getChange();
40 public static class MockListener implements ModificationListener {
41 private List<ModificationEvent> events;
44 public synchronized void modification(ModificationEvent ev) {
46 events = new ArrayList<ModificationEvent>();
52 public synchronized List<ModificationEvent> assertEvents(
54 ) throws InterruptedException {
55 for (int i = 0; i < 10; i++) {
56 if (events != null && events.size() >= cnt) {
61 assertEquals(msg + ":\n" + events, cnt, events.size());
62 List<ModificationEvent> res = events;
66 } // end of ModificationListener
67 // END: openfixed.commontest