### Question:
AbstractEventStoreCommitNotifier implements EventStoreCommitNotifier { @Override @Lock(LockType.WRITE) public void addListener(String bucketId, EventStoreCommitListener listener) { if (listener == null) throw new IllegalArgumentException("listener must not be null"); List<EventStoreCommitListener> list = listFor(bucketId, true); if (list.contains(listener)) throw new IllegalStateException("Listener already listening."); list.add(listener); }  @Override @Lock(LockType.WRITE) void addListener(String bucketId, EventStoreCommitListener listener); @Override @Lock(LockType.WRITE) void removeListener(String bucketId, EventStoreCommitListener listener);  }### Answer:
@Test public void test_notification() { this.clear(); EventStoreCommitNotifier instance = this.instance(); instance.addListener(DEFAULT_BUCKET, this); String id = UUID.randomUUID().toString(); ChangeSet cs = changeSet(id); instance.notifyListeners(cs); sleep(WAIT_TIME * 2); assertTrue(caught); assertNotNull(caughtCS); assertEquals(caughtCS.streamId(), id); }
@Test public void test_multiple_add_fails() { this.clear(); EventStoreCommitNotifier instance = this.instance(); instance.addListener(DEFAULT_BUCKET, this); try { instance.addListener(DEFAULT_BUCKET, this); fail("Should have failed by now"); } catch (Exception e) { } }
@Test public void test_different_buckets() { TestListener[] l = new TestListener[3]; for (int i = 0; i < 3; i++) l[i] = new TestListener(); EventStoreCommitNotifier instance = this.instance(); instance.addListener("BUCKET1", l[0]); instance.addListener("BUCKET1", l[2]); instance.addListener("BUCKET2", l[1]); instance.addListener("BUCKET2", l[2]); ChangeSet cs1 = changeSet("BUCKET1", UUID.randomUUID().toString()); ChangeSet cs2 = changeSet("BUCKET2", UUID.randomUUID().toString()); instance.notifyListeners(cs1); this.sleep(WAIT_TIME * 2); assertNotNull(l[0].notification); assertEquals(l[0].notification.changes(), cs1); assertTrue(l[1].notification == null); assertNotNull(l[2].notification); assertEquals(l[2].notification.changes(), cs1); for (int i = 0; i < 3; i++) l[0].notification = null; instance.notifyListeners(cs2); this.sleep(WAIT_TIME * 2); assertTrue(l[0].notification == null); assertNotNull(l[1].notification); assertEquals(l[1].notification.changes(), cs2); assertNotNull(l[2].notification); assertEquals(l[2].notification.changes(), cs2); }