BetweenMatcherType implements MatcherType<Range<C>> { @Override public Range<C> decode(String value, Type<?> type, Matcher matcher) { BetweenMatcher betweenMatcher = (BetweenMatcher) matcher; char separator = findSeparator(value, betweenMatcher.separators()); String[] values = EngineUtil.split2(value, separator); String from = values[0].trim(); String to = values[1].trim(); return new Range<C>(decodeValue(from, type), decodeValue(to, type)); }  @Override Range<C> decode(String value, Type<?> type, Matcher matcher); @Override String encode(Range<C> object, Type<?> type, Matcher matcher);  }
@Test public void shouldDecodeValueAsRangeObjectUsingFirstSeparatorFromMatcherFoundInValue() { BetweenMatcher matcher = new BetweenMatcher(true, true, "~#"); Range<String> decoded = type.decode("A#B", null, matcher); assertThat(decoded.from()).isEqualTo("A"); assertThat(decoded.to()).isEqualTo("B"); }
@Test public void shouldDecodeValueAsRangeWithBeginningOnlyWhenItsImpossibleToSplitValueUsingSeparators() { BetweenMatcher matcher = new BetweenMatcher(true, true, "~#"); Range<String> decoded = type.decode("A:B", null, matcher); assertThat(decoded.from()).isEqualTo("A:B"); assertThat(decoded.to()).isEqualTo(null); }
@Test public void shouldTrimAllWhitespacesFromRangeBeginningAndEndBeforePassingToTypeDecoding() { BetweenMatcher matcher = new BetweenMatcher(true, true, "~"); Range<String> decoded = type.decode(" A ~ B ", null, matcher); assertThat(decoded.from()).isEqualTo("A"); assertThat(decoded.to()).isEqualTo("B"); }