### Question:
SwingUpdateManager { public synchronized void update() { if (disposed) { return; } requestTime = System.currentTimeMillis(); SystemUtilities.runSwingLater(this::checkForWork); } SwingUpdateManager(Runnable r);  SwingUpdateManager(int minDelay, Runnable r);  SwingUpdateManager(int minDelay, int maxDelay, Runnable r);  SwingUpdateManager(int minDelay, int maxDelay, String name, Runnable r); synchronized void update(); synchronized void updateLater(); void updateNow(); synchronized void stop(); synchronized boolean hasPendingUpdates(); synchronized boolean isBusy(); synchronized void dispose(); synchronized boolean isDisposed(); @Override String toString(); String toStringDebug(); static final int DEFAULT_MAX_DELAY; }### Answer:
@Test public void testCallToUpdateWhileAnUpdateIsWorking() throws Exception { CountDownLatch startLatch = new CountDownLatch(1); CountDownLatch endLatch = new CountDownLatch(1); AtomicBoolean exception = new AtomicBoolean(); Runnable r = () -> { runnableCalled++; startLatch.countDown(); try { endLatch.await(10, TimeUnit.SECONDS); } catch (InterruptedException e) { exception.set(true); } }; manager = new SwingUpdateManager(MIN_DELAY, MAX_DELAY, r); manager.update(); startLatch.await(10, TimeUnit.SECONDS); manager.update(); endLatch.countDown(); waitForManager(); assertEquals("Expected exactly 2 callbacks", 2, runnableCalled); }
@Test public void testOneCallForOneUpdate() { manager.update(); waitForManager(); assertEquals("Expected only 1 callback", 1, runnableCalled); }
@Test public void testTwoCallForMultipleFastUpdateCalls() { for (int i = 0; i < 10; i++) { manager.update(); sleep(10); } waitForManager(); assertEquals("Expected 2 callbacks", 2, runnableCalled); }
@Test public void testMaxTimeout() { int sleepyTime = 5; int maxDelay = 600; manager = createUpdateManager(200, maxDelay); for (int i = 0; i < 4; i++) { manager.update(); sleep(sleepyTime); } assertEquals("Expected 1 max delay callback", 1, runnableCalled); waitForManager(); assertEquals("Expected one immediate callback and one max delay callback (2 total)", 2, runnableCalled); }