CallbackRegistry implements Cloneable { public synchronized void clear() { if (mNotificationLevel == 0) { mCallbacks.clear(); } else if (!mCallbacks.isEmpty()) { for (int i = mCallbacks.size() - 1; i >= 0; i--) { setRemovalBit(i); } } } CallbackRegistry(NotifierCallback<C, T, A> notifier); synchronized void notifyCallbacks(T sender, int arg, A arg2); synchronized void add(C callback); synchronized void remove(C callback); synchronized ArrayList<C> copyCallbacks(); synchronized void copyCallbacks(List<C> callbacks); synchronized boolean isEmpty(); synchronized void clear(); @SuppressWarnings("unchecked") synchronized CallbackRegistry<C, T, A> clone();  }
@Test public void testClear() { CallbackRegistry.NotifierCallback<Integer, CallbackRegistryTest, Integer> notifier = new CallbackRegistry.NotifierCallback<Integer, CallbackRegistryTest, Integer>() { @Override public void onNotifyCallback(Integer callback, CallbackRegistryTest sender, int arg1, Integer arg) { addNotifyCount(callback); } }; registry = new CallbackRegistry<Integer, CallbackRegistryTest, Integer>(notifier); for (int i = 0; i < deepNotifyCount.length; i++) { registry.add(i); } registry.clear(); ArrayList<Integer> callbackList = registry.copyCallbacks(); assertEquals(0, callbackList.size()); registry.notifyCallbacks(this, 0, null); for (int i = 0; i < deepNotifyCount.length; i++) { assertEquals(0, deepNotifyCount[i]); } }