### Question:
BlockchainEvents { public ListenerRegistration addAccountCreationListener(final EventListener<Void> listener) { checkNotNull(listener, "listener"); ServerSentEvent serverSentEvent = server.transactions() .forAccount(accountKeyPair) .stream(new org.stellar.sdk.requests.EventListener<TransactionResponse>() { private boolean eventOccurred = false; @Override public void onEvent(TransactionResponse transactionResponse) { if (!eventOccurred) { eventOccurred = true; listener.onEvent(null); } } }); return new ListenerRegistration(serverSentEvent); } BlockchainEvents(Server server, String accountId, KinAsset kinAsset); ListenerRegistration addBalanceListener(@NonNull final EventListener<Balance> listener); ListenerRegistration addPaymentListener(@NonNull final EventListener<PaymentInfo> listener); ListenerRegistration addAccountCreationListener(final EventListener<Void> listener);  }### Answer:
@Test public void addAccountCreationListener() throws Exception { enqueueCreateAccountResponses(); final CountDownLatch latch = new CountDownLatch(1); final boolean[] eventFired = {false}; blockchainEvents.addAccountCreationListener(new EventListener<Void>() { @Override public void onEvent(Void data) { eventFired[0] = true; latch.countDown(); } }); latch.await(1, TimeUnit.SECONDS); assertThat(eventFired[0], equalTo(true)); }
@Test public void addAccountCreationListener_StopListener_NoEvents() throws Exception { final int[] eventsCount = {0}; ListenerRegistration listenerRegistration = blockchainEvents .addAccountCreationListener(new EventListener<Void>() { @Override public void onEvent(Void data) { eventsCount[0]++; } }); listenerRegistration.remove(); enqueueCreateAccountResponses(); Thread.sleep(500); assertThat(eventsCount[0], equalTo(0)); }
@Test public void addAccountCreationListener_MultipleTransactions_SingleEvent() throws Exception { enqueueCreateAccountResponses(); enqueueTransactionsResponses(); final int[] eventsCount = {0}; blockchainEvents.addAccountCreationListener(new EventListener<Void>() { @Override public void onEvent(Void data) { eventsCount[0]++; } }); Thread.sleep(500); assertThat(eventsCount[0], equalTo(1)); }
@SuppressWarnings("ConstantConditions") @Test public void addAccountCreationListener_NullListener_IllegalArgumentException() throws Exception { expectedEx.expect(IllegalArgumentException.class); expectedEx.expectMessage("listener"); blockchainEvents.addAccountCreationListener(null); }