MessageHeadersBuilder extends AbstractDittoHeadersBuilder<MessageHeadersBuilder, MessageHeaders> { @Override public MessageHeadersBuilder removeHeader(final CharSequence key) { MessageHeaderDefinition.forKey(key).ifPresent(definition -> { if (MANDATORY_HEADERS.contains(definition)) { final String msgTemplate = "Mandatory header with key <{0}> cannot be removed!"; throw new IllegalArgumentException(MessageFormat.format(msgTemplate, key)); } }); return super.removeHeader(key); } 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 tryToRemoveMandatoryHeader() { final SoftAssertions softly = new SoftAssertions(); for(MessageHeaderDefinition mandatoryHeaderDefinition : MessageHeadersBuilder.MANDATORY_HEADERS) { final String key = mandatoryHeaderDefinition.getKey(); softly.assertThatThrownBy(() -> underTest.removeHeader(key)) .isInstanceOf(IllegalArgumentException.class) .withFailMessage("Mandatory header with key <%s> cannot be removed!", key) .hasNoCause(); } softly.assertAll(); }