### Question:
DefaultEntityView implements EntityView { @Override public CompletableFuture<Void> load(@NonNull EntityViewListener listener) { var future = new CompletableFuture<Void>(); receiver.receive(new ReceiverListener(listener, future)); return future; } DefaultEntityView(EventReceiver receiver, Map<Entity.Key<?>, Entity<?, ?>> entities);  DefaultEntityView(EventReceiver receiver); @Override CompletableFuture<Void> load(@NonNull EntityViewListener listener); @Override CompletableFuture<Void> load(); @Override Optional<Entity<K, S>> get(K key); @Override Stream<Entity<K, S>> all(Class<K> keyClass);  }### Answer:
@Test public void load() { var future = underTest.load(listener); var captor = ArgumentCaptor.forClass(ReceiverListener.class); verify(receiver).receive(captor.capture()); var receiverListener = captor.getValue(); assertThat(receiverListener.getListener(), is(listener)); assertThat(receiverListener.getFuture(), is(future)); }
@Test public void loadNoArgs() { var future = underTest.load(); var captor = ArgumentCaptor.forClass(ReceiverListener.class); verify(receiver).receive(captor.capture()); var receiverListener = captor.getValue(); assertThat(receiverListener.getListener(), is(EntityViewListener.NULL)); assertThat(receiverListener.getFuture(), is(future)); }
@Test public void updateNotLoaded() { var future = underTest.load(listener); var captor = ArgumentCaptor.forClass(ReceiverListener.class); verify(receiver).receive(captor.capture()); var receiverListener = captor.getValue(); receiverListener.onEvent(specificationEvent); verify(updater).update(specificationEvent); assertThat(future.isDone(), is(false)); verify(listener, never()).onEvent(null, specificationEvent); }
@Test public void updateLoaded() { var future = underTest.load(listener); var captor = ArgumentCaptor.forClass(ReceiverListener.class); verify(receiver).receive(captor.capture()); var receiverListener = captor.getValue(); receiverListener.onEvent(LOAD_COMPLETE); verify(updater, never()).update(any()); assertThat(future.isDone(), is(true)); verify(listener, never()).onEvent(null, specificationEvent); }
@Test public void updateLoadedListenerInvoked() { underTest.load(listener); var captor = ArgumentCaptor.forClass(ReceiverListener.class); verify(receiver).receive(captor.capture()); var receiverListener = captor.getValue(); receiverListener.onEvent(LOAD_COMPLETE); receiverListener.onEvent(specificationEvent); verify(updater).update(specificationEvent); verify(listener).onEvent(null, specificationEvent); }