@Test public void events() throws Exception { // Check that events are registered with the right chains and that if a chain is added, it gets // the event // listeners attached properly even post-hoc. final AtomicReference<ECKey> ran = new AtomicReference<ECKey>(null); final KeyChainEventListener listener = new KeyChainEventListener() { @Override public void onKeysAdded(List<ECKey> keys) { ran.set(keys.get(0)); } }; group.addEventListener(listener, Threading.SAME_THREAD); ECKey key = group.freshKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertEquals(key, ran.getAndSet(null)); ECKey key2 = new ECKey(); group.importKeys(key2); assertEquals(key2, ran.getAndSet(null)); group.removeEventListener(listener); ECKey key3 = new ECKey(); group.importKeys(key3); assertNull(ran.get()); }