MessageHeadersBuilder extends AbstractDittoHeadersBuilder<MessageHeadersBuilder, MessageHeaders> { public static MessageHeadersBuilder of(final Map<String, String> headers) { if (headers instanceof MessageHeaders) { return new MessageHeadersBuilder((MessageHeaders) headers); } validateMandatoryHeaders(headers); return new MessageHeadersBuilder(headers); } private  MessageHeadersBuilder(final Map<String, String> headers); private  MessageHeadersBuilder(final MessageHeaders dittoHeaders); @Deprecated static MessageHeadersBuilder newInstance(final MessageDirection direction, final CharSequence thingId,
            final CharSequence subject); static MessageHeadersBuilder newInstance(final MessageDirection direction, final ThingId thingId,
            final CharSequence subject); static MessageHeadersBuilder of(final Map<String, String> headers); static MessageHeadersBuilder of(final JsonObject jsonObject); MessageHeadersBuilder featureId(@Nullable final CharSequence featureId); @Override MessageHeadersBuilder contentType(@Nullable final CharSequence contentType); @Override MessageHeadersBuilder timeout(final Duration timeout); @Deprecated MessageHeadersBuilder timeout(final long timeoutInSeconds); MessageHeadersBuilder timestamp(@Nullable final OffsetDateTime timestamp); @Override MessageHeadersBuilder removeHeader(final CharSequence key); MessageHeadersBuilder timestamp(@Nullable final CharSequence timestampISO8601); MessageHeadersBuilder statusCode(@Nullable final HttpStatusCode statusCode); MessageHeadersBuilder statusCode(final int statusCode);  }
@Test public void createInstanceFromMinimalMap() { final Map<String, String> validHeaders = new HashMap<>(); validHeaders.put(MessageHeaderDefinition.DIRECTION.getKey(), MessageDirection.TO.toString()); validHeaders.put(MessageHeaderDefinition.SUBJECT.getKey(), SUBJECT); validHeaders.put(MessageHeaderDefinition.THING_ID.getKey(), THING_ID.toString()); final MessageHeaders messageHeaders = MessageHeadersBuilder.of(validHeaders).build(); assertThat(messageHeaders).containsAllEntriesOf(validHeaders); }
@Test public void tryToCreateInstanceFromMapWithoutThingId() { final Map<String, String> insufficientHeaders = new HashMap<>(); insufficientHeaders.put(MessageHeaderDefinition.DIRECTION.getKey(), MessageDirection.TO.toString()); insufficientHeaders.put(MessageHeaderDefinition.SUBJECT.getKey(), SUBJECT); assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> MessageHeadersBuilder.of(insufficientHeaders)) .withMessage("The headers did not contain a value for mandatory header with key <%s>!", MessageHeaderDefinition.THING_ID.getKey()) .withNoCause(); }
@Test public void tryToCreateInstanceFromEmptyJsonObject() { assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> MessageHeadersBuilder.of(JsonFactory.newObject())) .withMessage("The headers did not contain a value for mandatory header with key <%s>!", MessageHeaderDefinition.DIRECTION.getKey()) .withNoCause(); }