MappingArgument { public static ImmutableMap<String, String> parse(String mapping) throws MessagingException { Preconditions.checkArgument(mapping != null, "mapping should not be null"); if (mapping.trim().isEmpty()) { return ImmutableMap.of(); } return Splitter.on(',') .omitEmptyStrings() .splitToList(mapping) .stream() .map(MappingArgument::parseKeyValue) .collect(Guavate.toImmutableMap(Pair::getLeft, Pair::getRight)); }  static ImmutableMap<String, String> parse(String mapping); static String CONFIGURATION_ERROR_MESSAGE; }
@Test void parseShouldFailIfCalledWithNull() { assertThatThrownBy(() -> MappingArgument.parse(null)) .isInstanceOf(IllegalArgumentException.class); }
@Test void parseShouldFailIfCalledWhenMissingMappingParts() { assertThatThrownBy(() -> MappingArgument.parse("key1;value1,key2")) .isInstanceOf(IllegalArgumentException.class); }
@Test void parseShouldFailIfCalledWhenExtraMappingParts() { assertThatThrownBy(() -> MappingArgument.parse("key1;value1,key2;value1;value3")) .isInstanceOf(IllegalArgumentException.class); }
@Test void parseShouldWorkForEmptyMapping() throws MessagingException { assertThat(MappingArgument.parse("")) .isEmpty(); }
@Test void parseShouldWorkForEmptyMappingWithSpace() throws MessagingException { assertThat(MappingArgument.parse(" ")) .isEmpty(); }
@Test void parseShouldWorkForValidParsingWithOnlyOneKey() throws MessagingException { assertThat(MappingArgument.parse("key1;value1")) .containsExactly(MapEntry.entry("key1", "value1")); }
@Test void parseShouldWorkForValidParsingWithMoreThanOneKey() throws MessagingException { assertThat(MappingArgument.parse("key1;value1,key2;value2")) .containsExactly(MapEntry.entry("key1", "value1"), MapEntry.entry("key2", "value2")); }
@Test void parserShouldTrimSpacesAroundSemiColon() throws MessagingException { assertThat(MappingArgument.parse("key1; value1")) .containsExactly(MapEntry.entry("key1", "value1")); }
@Test void parserShouldTrimSpacesAroundComa() throws MessagingException { assertThat(MappingArgument.parse("key1;value1, key2;value2")) .containsExactly(MapEntry.entry("key1", "value1"), MapEntry.entry("key2", "value2")); }
@Test void parserShouldNotFailWhenExtraComa() throws MessagingException { assertThat(MappingArgument.parse("key1;value1,")) .containsExactly(MapEntry.entry("key1", "value1")); }