NullSimpleResultAdapter extends AbstractResultAdapter<Object> { @Override public Object adapt(Invocation invocation, Object originalValue) { if (invocation.getMethod().getReturnType().isPrimitive()) { throw new ResultAdapterFailureException(null, invocation.getMethod().getReturnType()); } return null; } NullSimpleResultAdapter(); @Override boolean accepts(Invocation invocation, Object originalValue); @Override Object adapt(Invocation invocation, Object originalValue);  }
@Test public void testAdaptingNull() throws Exception { final NullSimpleResultAdapter adapter = new NullSimpleResultAdapter(); final Object value = adapter.adapt( new ImmutableInvocation(ReturnTypeSampleRepository.class.getMethod("findOther"), new Object[]{}), null); assertThat(value, is(nullValue())); }
@Test(expectedExceptions = ResultAdapterFailureException.class) public void testAdaptingPrimitiveToNull() throws Exception { final NullSimpleResultAdapter adapter = new NullSimpleResultAdapter(); adapter.adapt( new ImmutableInvocation(ReturnTypeSampleRepository.class.getMethod("findPrimitive"), new Object[]{}), null); }