### Question:
PahoRxMqttToken implements RxMqttToken { @Override public RxMqttMessage getMessage() { return Optional.of(token) .filter(t -> IMqttDeliveryToken.class.isAssignableFrom(t.getClass())) .map(t -> { try { return IMqttDeliveryToken.class.cast(t).getMessage(); } catch (MqttException me) { throw new PahoRxMqttException(me, t); } }) .map(PahoRxMqttMessage::create) .orElse(null); } PahoRxMqttToken(IMqttToken token); @Override String getClientId(); @Override boolean isComplete(); @Override String[] getTopics(); @Override int getMessageId(); @Override int[] getGrantedQos(); @Override boolean getSessionPresent(); @Override RxMqttMessage getMessage(); @Override RxMqttException getException();  }### Answer:
@Test public void whenAMqttDeliveryTokenIsSuppliedThenGetMessageFails() throws MqttException { IMqttDeliveryToken mqttToken = mock(IMqttDeliveryToken.class); assertThat(mqttToken).isNotNull(); doThrow(new MqttException(MqttException.REASON_CODE_UNEXPECTED_ERROR)).when(mqttToken).getMessage(); PahoRxMqttToken rxMqttToken = new PahoRxMqttToken(mqttToken); assertThat(rxMqttToken).isNotNull(); try { rxMqttToken.getMessage(); } catch (Exception e) { assertThat(e).isExactlyInstanceOf(PahoRxMqttException.class); assertThat(e).hasCauseExactlyInstanceOf(MqttException.class); } verify(mqttToken).getMessage(); }