ReplyByReturnValueConsumer implements Consumer<Object> { @SuppressWarnings("unchecked") @VisibleForTesting static List<Message> checkListContents(final List<?> list) { for (int i = 0; i < list.size(); ++i) { final Object item = list.get(i); Preconditions.checkNotNull(item, "item is null. index = {} in {}", i, list); Preconditions.checkArgument(item instanceof Message, "List contains not Message type object. type = {}", item.getClass()); } return (List<Message>) list; }  @Override void accept(final Object returnValue);  }
@Test public void checkListContentsNullTest() throws Exception { assertThatThrownBy(() -> ReplyByReturnValueConsumer.checkListContents(singletonList(null))) .isInstanceOf(NullPointerException.class); }
@Test public void checkListContentsIllegalTypeTest() throws Exception { assertThatThrownBy(() -> ReplyByReturnValueConsumer.checkListContents(singletonList(new Object()))) .isInstanceOf(IllegalArgumentException.class); }