DefaultCrudRepository extends CrudRepositorySupport { public Iterable findAllById(Iterable ids) { final List entities = new LinkedList(); log.info("Looking for multiple entities for a number of ids"); log.debug(ids); for (Object id : ids) { final Optional<Object> found = findById(id); if (found.isPresent()) { log.trace("Entity found for key " + id + ", adding the found entity to the list of returned entity"); entities.add(found.get()); } } return entities; }  Iterable<Object> saveAll(Iterable entities); Optional<Object> findById(Object key); boolean existsById(Object key); Iterable findAllById(Iterable ids); Object delete(Object id); Object deleteById(Object entity); Iterable delete(Iterable entities); Iterable deleteAll();  }
@Test public void testFindAllById() { dataStore.save("1", new Person()); dataStore.save("2", new Person()); dataStore.save("3", new Person()); dataStore.save("4", new Person()); final List<String> existingIds = Arrays.asList("2", "3"); final List<String> missingIds = Arrays.asList("5", "6"); final List<String> request = new ArrayList<>(); request.addAll(existingIds); request.addAll(missingIds); final List<Person> expected = new ArrayList<>(); for (String id : existingIds) { expected.add(dataStore.retrieve(id)); } final List<?> list = iterableToList(repository.findAllById(request)); assertThat(list, hasSize(existingIds.size())); for (Object found : list) { assertThat(found, is(instanceOf(Person.class))); assertThat((Person) found, isIn(expected)); } }