HeaderBasedPlaceholderSubstitutionAlgorithm { public String substitute(final String input, final WithDittoHeaders withDittoHeaders) { requireNonNull(input); requireNonNull(withDittoHeaders); return substitute(input, withDittoHeaders.getDittoHeaders()); } private  HeaderBasedPlaceholderSubstitutionAlgorithm(
            final Map<String, Function<DittoHeaders, String>> replacementDefinitions); static HeaderBasedPlaceholderSubstitutionAlgorithm newInstance(
            final Map<String, Function<DittoHeaders, String>> replacementDefinitions); String substitute(final String input, final WithDittoHeaders withDittoHeaders); String substitute(final String input, final DittoHeaders dittoHeaders);  }
@Test public void substituteFailsWithNullInput() { assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> underTest.substitute(null, DITTO_HEADERS)); }
@Test public void substituteFailsWithNullHeaders() { assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> underTest.substitute("doesNotMatter", (DittoHeaders) null)); }
@Test public void substituteFailsWithNullWithDittoHeaders() { assertThatExceptionOfType(NullPointerException.class) .isThrownBy(() -> underTest.substitute("doesNotMatter", (WithDittoHeaders) null)); }
@Test public void substituteReturnsInputWhenInputDoesNotContainReplacers() { final String input = "withoutReplacers"; final String substituted = underTest.substitute(input, DITTO_HEADERS); assertThat(substituted).isEqualTo(input); }
@Test public void substituteReturnsReplacedWhenInputContainsPlaceholder() { final String substituted = underTest.substitute(REPLACER_1, DITTO_HEADERS); assertThat(substituted).isEqualTo(REPLACED_1); }
@Test public void substituteReturnsReplacedWhenInputContainsLegacyPlaceholder() { final String substituted = underTest.substitute(LEGACY_REPLACER, DITTO_HEADERS); assertThat(substituted).isEqualTo(REPLACED_1); }
@Test public void substituteThrowsUnknownPlaceholderExceptionWhenInputContainsUnknownPlaceholder() { assertUnknownPlaceholderExceptionIsThrown(UNKNOWN_REPLACER_KEY, () -> underTest.substitute(UNKNOWN_REPLACER, DITTO_HEADERS)); }
@Test public void partialPlaceholdersRemain() { final String notResolvableInput = "{{"; assertThat(underTest.substitute(notResolvableInput, DITTO_HEADERS)).isEqualTo(notResolvableInput); }
@Test public void unknownLegacyPlaceholderThrowsException() { assertThatExceptionOfType(GatewayPlaceholderNotResolvableException.class) .isThrownBy(() -> underTest.substitute(UNKNOWN_LEGACY_REPLACER, DITTO_HEADERS)); }
@Test public void inputContainsNestedLegacyPlaceholderThrowsException() { final String nestedPlaceholder = "${" + LEGACY_REPLACER + "}"; assertThatExceptionOfType(GatewayPlaceholderNotResolvableException.class) .isThrownBy(() -> underTest.substitute(nestedPlaceholder, DITTO_HEADERS)); }