NumberIterableResultAdapter extends AbstractIterableResultAdapter<Object> { @Override public boolean accepts(Invocation invocation, Object originalValue) { if (originalValue == null) { return false; } if (!Number.class.isAssignableFrom(PropertyUtils.getTypeOf(invocation.getMethod().getReturnType()))) { return false; } if (originalValue instanceof Iterable) { Iterable iterable = (Iterable) originalValue; final Iterator iterator = iterable.iterator(); if (iterator.hasNext()) { final Object value = iterator.next(); return value instanceof Number && !iterator.hasNext(); } } return false; } NumberIterableResultAdapter(); @Override boolean accepts(Invocation invocation, Object originalValue);  }
@Test public void testAccepting() throws Exception { final NumberIterableResultAdapter adapter = new NumberIterableResultAdapter(); assertThat(adapter.accepts(null, null), is(false)); assertThat(adapter.accepts( new ImmutableInvocation(ReturnTypeSampleRepository.class.getMethod("findOther"), new Object[]{}), new Object()), is(false)); assertThat(adapter.accepts( new ImmutableInvocation(ReturnTypeSampleRepository.class.getMethod("findInt"), new Object[]{}), new Object()), is(false)); assertThat(adapter.accepts( new ImmutableInvocation(ReturnTypeSampleRepository.class.getMethod("findInt"), new Object[]{}), Arrays.asList("", 1)), is(false)); assertThat(adapter.accepts( new ImmutableInvocation(ReturnTypeSampleRepository.class.getMethod("findInt"), new Object[]{}), Arrays.asList(1, 2)), is(false)); assertThat(adapter.accepts( new ImmutableInvocation(ReturnTypeSampleRepository.class.getMethod("findInt"), new Object[]{}), Collections.singletonList(1)), is(true)); assertThat(adapter.accepts( new ImmutableInvocation(ReturnTypeSampleRepository.class.getMethod("findInteger"), new Object[]{}), Collections.singletonList(1)), is(true)); }