SimpleMatcherType implements MatcherType<Object> { @Override @SuppressWarnings("unchecked") public String encode(Object object, Type type, Matcher matcher) { if (object instanceof Star) { return "*"; } String value; if (type != null) { value = type.encode(type.convert(object)); } else { value = object == null ? "" : object.toString(); } return value == null ? "*" : value; }  @Override Object decode(String value, Type<?> type, Matcher matcher); @Override @SuppressWarnings("unchecked") String encode(Object object, Type type, Matcher matcher);  }
@Test public void shouldEncodeStarObjectAsStar() { String encoded = type.encode(Star.star(), null, null); assertThat(encoded).isEqualTo("*"); }
@Test public void shouldEncodeValueAsEmptyStringWhenNoTypeAndValueIsNull() { String encoded = type.encode(null, null, null); assertThat(encoded).isEqualTo(""); }
@Test public void shouldEncodeValueUsingToStringWhenNoTypeProvied() { String encoded = type.encode("value", null, null); assertThat(encoded).isEqualTo("value"); }
@Test public void shouldEncodeValueusingTypeWhenTypeProvided() { StringType stringType = new StringType(); String encoded = type.encode(new SimpleObject(), stringType, null); assertThat(encoded).isEqualTo("simpleObject"); }