RefreshHelper implements Refreshable { @Override public void refresh(Collection<Refreshable> alreadyRefreshed) { if (refreshLock.tryLock()) { try { alreadyRefreshed = buildRefreshed(alreadyRefreshed); for (Refreshable dependency : dependencies) { maybeRefresh(alreadyRefreshed, dependency); } if (refreshRunnable != null) { try { refreshRunnable.call(); } catch (Exception e) { log.warn("Unexpected exception while refreshing", e); } } } finally { refreshLock.unlock(); } } } RefreshHelper(Callable<?> refreshRunnable); void addDependency(Refreshable refreshable); void removeDependency(Refreshable refreshable); @Override void refresh(Collection<Refreshable> alreadyRefreshed); static Collection<Refreshable> buildRefreshed(Collection<Refreshable> currentAlreadyRefreshed); static void maybeRefresh(Collection<Refreshable> alreadyRefreshed, Refreshable refreshable);  }
@Test public void testCallable() { MockRefreshable mock = new MockRefreshable(); Refreshable helper = new RefreshHelper(mock); helper.refresh(null); assertEquals(1, mock.getCallCount()); }
@Test public void testNoCallable() { Refreshable helper = new RefreshHelper(null); helper.refresh(null); }