MessageImpl implements Message { @Override public void setSender( final String sender ) { Preconditions.checkArgument( StringUtils.length( sender ) <= MAX_SENDER_LEN, String.format( "Max sender length must be %d", MAX_SENDER_LEN ) ); this.sender = sender; } 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( expected = IllegalArgumentException.class ) public void testLongSender() throws Exception { MessageImpl message = new MessageImpl( SOURCE_PEER_ID, PAYLOAD ); message.setSender( StringUtils.repeat( "s", MessageImpl.MAX_SENDER_LEN + 1 ) ); }