EndpointPromiseImpl implements EndpointPromise { @Override public void setSuccess(Endpoint endpoint) throws IllegalStateException { final String methodName = "setSuccess"; logger.entry(this, methodName, endpoint); if (complete.getAndSet(true)) { final IllegalStateException exception = new IllegalStateException("Promise already completed"); logger.throwing(this, methodName, exception); throw exception; } else { component.tell(new EndpointResponse(endpoint, null), ComponentImpl.NOBODY); } logger.exit(this, methodName); } EndpointPromiseImpl(Component component); @Override boolean isComplete(); @Override void setSuccess(Endpoint endpoint); @Override void setWait(long delay); @Override void setFailure(Exception exception);  }
@Test public void setSuccess() { MockComponent component = new MockComponent(); EndpointPromise promise = new EndpointPromiseImpl(component); Endpoint endpoint = new StubEndpoint(); promise.setSuccess(endpoint); assertTrue("future should have been marked as done", promise.isComplete()); assertEquals("one message should have been delivered to the component", 1, component.messages.size()); assertEquals("wrong type for message delivered to component", EndpointResponse.class, component.messages.getFirst().getClass()); EndpointResponse resp = (EndpointResponse)component.messages.getFirst(); assertSame("wrong value in message", endpoint, resp.endpoint); testPromiseThrowsIllegalStateException(promise); }