ActivityQueue implements Closeable { public synchronized void replace(QueueGroups group, Activity activity) { replace(group, activity, 0, TimeUnit.MILLISECONDS); } ActivityQueue(); void start(); synchronized void add(QueueGroups group, Activity activity); synchronized void add(QueueGroups group, Activity activity, long delay, TimeUnit unit); @Override void close(); synchronized void replace(QueueGroups group, Activity activity); synchronized void replace(QueueGroups group, Activity activity, long delay, TimeUnit unit);  }
@Test public void testReplace() throws Exception { ActivityQueue queue = new ActivityQueue(); queue.start(); try { final AtomicInteger count = new AtomicInteger(0); final CountDownLatch latch = new CountDownLatch(1); Activity activity = new Activity() { @Override public void completed(boolean wasSuccessful) { } @Override public Boolean call() throws Exception { count.incrementAndGet(); latch.countDown(); return true; } }; queue.add(QueueGroups.MAIN, activity, 1, TimeUnit.MINUTES); queue.replace(QueueGroups.MAIN, activity); Assert.assertTrue(latch.await(5, TimeUnit.SECONDS)); Assert.assertEquals(count.get(), 1); } finally { CloseableUtils.closeQuietly(queue); } }