Message implements BodyContent, JsonSerializable { @Override public Object asJson() { Map<String, Object> message = new HashMap<>(); if (this.metadata != null) { message.putAll(this.metadata); } message.put("body", this.body); return message; } private  Message(Builder builder); String getBody(); Map<String, Object> getMetadata(); @Override String getKeyName(); @Override Object asJson(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }
@Test public void shouldAllowMetadata() { Map<String, Object> metadataMap = new HashMap<>(); metadataMap.put("a", "b"); metadataMap.put("num", 42); metadataMap.put("body", "should not show up"); Message message = new Message.Builder() .body("hello world") .metadata(metadataMap) .build(); Map<String, Object> expected = new HashMap<>(); expected.put("a", "b"); expected.put("num", 42); expected.put("body", "hello world"); assertThat(message.asJson(), is(expected)); }