MessageImpl implements Message { @Override public <T> T getPayload( Class<T> clazz ) { T result = JsonUtil.fromJson( payloadString, clazz ); LOG.debug( String.format( "Unmarshalled object: %s", result ) ); return result; } MessageImpl( Message message );  MessageImpl( String sourcePeerId, Object payload ); @Override String getSourcePeerId(); @Override UUID getId(); @Override T getPayload( Class<T> clazz ); @Override String getSender(); @Override void setSender( final String sender ); @Override String getPayload(); @Override String toString(); static final int MAX_SENDER_LEN; }
@Test public void testGetPayload() throws Exception { CustomObject customObject = new CustomObject( 123, "hello" ); MessageImpl message = new MessageImpl( UUID.randomUUID().toString(), customObject ); assertEquals( customObject, message.getPayload( CustomObject.class ) ); }