NullToCollectionResultAdapter extends AbstractResultAdapter<Collection> { @Override public Collection adapt(Invocation invocation, Object originalValue) { return CollectionInstanceUtils.getCollection(invocation.getMethod().getReturnType()); } NullToCollectionResultAdapter(); @Override boolean accepts(Invocation invocation, Object originalValue); @Override Collection adapt(Invocation invocation, Object originalValue);  }
@Test public void testAdaptingList() throws Exception { final ResultAdapter<Collection> adapter = new NullToCollectionResultAdapter(); final Collection<?> collection = adapter.adapt( new ImmutableInvocation(ReturnTypeSampleRepository.class.getMethod("findList"), new Object[]{}), null); assertThat(collection, is(notNullValue())); assertThat(collection, hasSize(0)); assertThat(collection, is(instanceOf(List.class))); }
@Test public void testAdaptingSet() throws Exception { final ResultAdapter<Collection> adapter = new NullToCollectionResultAdapter(); final Collection<?> collection = adapter.adapt( new ImmutableInvocation(ReturnTypeSampleRepository.class.getMethod("findSet"), new Object[]{}), null); assertThat(collection, is(notNullValue())); assertThat(collection, hasSize(0)); assertThat(collection, is(instanceOf(Set.class))); }
@Test public void testAdaptingQueue() throws Exception { final ResultAdapter<Collection> adapter = new NullToCollectionResultAdapter(); final Collection<?> collection = adapter.adapt( new ImmutableInvocation(ReturnTypeSampleRepository.class.getMethod("findQueue"), new Object[]{}), null); assertThat(collection, is(notNullValue())); assertThat(collection, hasSize(0)); assertThat(collection, is(instanceOf(Queue.class))); }
@Test public void testAdaptingConcreteCollection() throws Exception { final ResultAdapter<Collection> adapter = new NullToCollectionResultAdapter(); final Collection<?> collection = adapter.adapt( new ImmutableInvocation(ReturnTypeSampleRepository.class.getMethod("findLinkedList"), new Object[]{}), null); assertThat(collection, is(notNullValue())); assertThat(collection, hasSize(0)); assertThat(collection, is(instanceOf(LinkedList.class))); }