HeaderEntryFilters { static HeaderEntryFilter toExternalHeadersFilter(final Map<String, HeaderDefinition> headerDefinitionMap) { final HeaderEntryFilter headerEntryFilter = shouldWriteToExternal(headerDefinitionMap); if (headerDefinitionMap.isEmpty()) { return headerEntryFilter; } else { return headerEntryFilter.andThen(discardDittoAckRequests()); } } private  HeaderEntryFilters();   }
@Test public void toExternalHeadersFilterDiscardsDittoInternalAckRequests() { final DittoHeaderDefinition headerDefinition = DittoHeaderDefinition.REQUESTED_ACKS; final Map<String, HeaderDefinition> headerDefinitions = Maps.newHashMap(headerDefinition.getKey(), headerDefinition); final List<AcknowledgementRequest> allAcknowledgementRequests = Lists.list( AcknowledgementRequest.of(AcknowledgementLabel.of("foo")), AcknowledgementRequest.of(DittoAcknowledgementLabel.TWIN_PERSISTED), AcknowledgementRequest.of(AcknowledgementLabel.of("bar"))); final JsonArray allAcknowledgementRequestsJsonArray = allAcknowledgementRequests.stream() .map(AcknowledgementRequest::toString) .map(JsonValue::of) .collect(JsonCollectors.valuesToArray()); final String value = allAcknowledgementRequestsJsonArray.toString(); final JsonArray externalAcknowledgementRequests = allAcknowledgementRequestsJsonArray.toBuilder() .remove(1) .build(); final String expected = externalAcknowledgementRequests.toString(); final HeaderEntryFilter underTest = HeaderEntryFilters.toExternalHeadersFilter(headerDefinitions); assertThat(underTest.apply(headerDefinition.getKey(), value)).isEqualTo(expected); }