EndpointPromiseImpl implements EndpointPromise { @Override public void setWait(long delay) throws IllegalStateException { final String methodName = "setWait"; logger.entry(this, methodName, delay); if (complete.getAndSet(true)) { final IllegalStateException exception = new IllegalStateException("Promise already completed"); logger.throwing(this, methodName, exception); throw exception; } else { component.tell(new ExhaustedResponse(delay), 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 setWait() { MockComponent component = new MockComponent(); EndpointPromise promise = new EndpointPromiseImpl(component); long waitValue = 12345; promise.setWait(waitValue); 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", ExhaustedResponse.class, component.messages.getFirst().getClass()); ExhaustedResponse resp = (ExhaustedResponse)component.messages.getFirst(); assertEquals("wrong delay value in message", waitValue, resp.delay); testPromiseThrowsIllegalStateException(promise); }