AbstractResultConverter implements ResultConverter { @Override public Object convert(Invocation invocation, Object original) { if (original == null || invocation.getMethod().getReturnType().equals(void.class)) { return null; } if (invocation.getMethod().getReturnType().isInstance(original)) { return original; } return doConvert(invocation, original); }  @Override Object convert(Invocation invocation, Object original);  }
@Test public void testConversionWhenInputIsNull() { final Object converted = new NoOpResultConverter().convert(null, null); assertThat(converted, is(nullValue())); }
@Test public void testConversionWhenTargetReturnsVoid() throws Exception { final Object converted = new NoOpResultConverter().convert( new ImmutableInvocation(ReturnTypeSampleRepository.class.getMethod("doSomething"), null), new Object()); assertThat(converted, is(nullValue())); }
@Test public void testWhenTypeMatchesTheReturnType() throws Exception { final Person original = new Person(); final Object converted = new NoOpResultConverter().convert( new ImmutableInvocation(ReturnTypeSampleRepository.class.getMethod("findPerson"), null), original); assertThat(converted, is(notNullValue())); assertThat(converted, is(instanceOf(Person.class))); assertThat(converted, is(original)); }
@Test public void testThatPassesToSubClassOtherwise() throws Exception { final Object original = new Object(); final NoOpResultConverter converter = new NoOpResultConverter(); final Object converted = converter.convert( new ImmutableInvocation(ReturnTypeSampleRepository.class.getMethod("findPerson"), null), original); assertThat(converted, is(notNullValue())); assertThat(converted, is(original)); assertThat(converter.getOriginal(), is(original)); }