SimpleMatcherType implements MatcherType<Object> { @Override public Object decode(String value, Type<?> type, Matcher matcher) { if (value != null && value.equals("*")) { return Star.star(); } if (type != null) { return type.decode(value).getValue(); } if (value != null && value.isEmpty()) { return null; } return value; }  @Override Object decode(String value, Type<?> type, Matcher matcher); @Override @SuppressWarnings("unchecked") String encode(Object object, Type type, Matcher matcher);  }
@Test public void shouldDecodeValueAsStarWhenEqualsStarSymbol() { Object decoded = type.decode("*", null, null); assertThat(decoded).isInstanceOf(Star.class); }
@Test public void shouldDecodeValueAsRawStringValueWhenNoTypeDeclared() { Object decoded = type.decode("value", null, null); assertThat(decoded).isEqualTo("value"); }
@Test public void shouldDecodeEmptyStringAsNullWhenNoTypeDeclared() { Object decoded = type.decode("", null, null); assertThat(decoded).isNull(); }
@Test public void shouldDecodeUsingTypeWhenProvided() { String valueToDecode = "value"; Type<?> anyType = mock(Type.class); when(anyType.decode(valueToDecode)).thenReturn(new ObjectHolder("hello")); Object decoded = type.decode("value", anyType, null); assertThat(decoded).isEqualTo("hello"); }