MessageHeadersBuilder extends AbstractDittoHeadersBuilder<MessageHeadersBuilder, MessageHeaders> { public MessageHeadersBuilder statusCode(@Nullable final HttpStatusCode statusCode) { final MessageHeaderDefinition definition = MessageHeaderDefinition.STATUS_CODE; if (null != statusCode) { putCharSequence(definition, String.valueOf(statusCode.toInt())); } else { removeHeader(definition.getKey()); } return myself; } 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 tryToSetUnknownStatusCode() { final int unknownCode = 42; assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> underTest.statusCode(unknownCode)) .withMessage("HTTP status code <%s> is unknown!", unknownCode) .withNoCause(); }
@Test public void setStatusCodeAsIntWorksAsExpected() { final int knownCode = 404; final MessageHeaders messageHeaders = underTest.statusCode(knownCode).build(); assertThat(messageHeaders.getStatusCode()).contains(HttpStatusCode.NOT_FOUND); }