EndpointPromiseImpl implements EndpointPromise { @Override public void setFailure(Exception exception) throws IllegalStateException { final String methodName = "setFailure"; logger.entry(this, methodName, exception); if (complete.getAndSet(true)) { final IllegalStateException ex = new IllegalStateException("Promise already completed"); logger.throwing(this, methodName, ex); throw ex; } else { ClientException clientException; if (exception instanceof ClientException) { clientException = (ClientException)exception; } else { clientException = new ClientException( "A problem occurred when trying to locate an instance of the MQ Light server. See linked exception for more details", exception); logger.data(this, methodName, clientException); } component.tell(new EndpointResponse(null, clientException), 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 setFailure() { MockComponent component = new MockComponent(); EndpointPromise promise = new EndpointPromiseImpl(component); promise.setFailure(new Exception()); 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", null, resp.endpoint); testPromiseThrowsIllegalStateException(promise); }