MessageImpl implements Message { @Override public Serializable getPayload() { return payload; } MessageImpl(CloudType cloudType, Serializable payload, int ttl); @Override String getId(); @Override CloudType getCloudType(); @Override Serializable getPayload(); @Override Optional<T> getPayload(Class<T> cls); @Override int getTtl(); @Override boolean equals(Object another); @Override String toString();  }
@Test public void testGetPayloadAs() throws Exception { Optional<Number> numberPayload = getMessage().getPayload(Number.class); assertThat(numberPayload.isPresent(), is(true)); assertThat(numberPayload.get(), equalTo(1)); }
@Test(expected = IllegalArgumentException.class) public void testGetPayloadInvalid() throws Exception { getMessage().getPayload(String.class); }
@Test public void testGetPayloadEmpty() throws Exception { assertThat(new MessageImpl(CloudType.MOCK, null, 1).getPayload(String.class).isPresent(), is(false)); }