DefaultCrudRepository extends CrudRepositorySupport { public Object delete(Object id) { Object retrieved = getDataStore().retrieve(id); log.info("Attempting to delete the entity with key " + id); if (retrieved == null) { log.info("Object not found with key " + id + ", try to find by identifier property"); try { id = PropertyUtils.getPropertyValue(id, getRepositoryMetadata().getIdentifierProperty()); retrieved = getDataStore().retrieve(id); } catch (IllegalStateException exception) { log.info("Serialized id doesn't have a identifier property"); } } getDataStore().delete(id); return retrieved; }  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 testDeleteByKey() { final Object deleted = repository.delete("1"); assertThat(deleted, is(nullValue())); }
@Test public void testDeleteMany() { 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<Person> request = new ArrayList<>(); for (String id : existingIds) { request.add(new Person().setId(id)); } for (String id : missingIds) { request.add(new Person().setId(id)); } final List<Person> expected = new ArrayList<>(); for (String id : existingIds) { expected.add(dataStore.retrieve(id)); } for (String existingId : existingIds) { assertThat(dataStore.hasKey(existingId), is(true)); } final List<?> deleted = iterableToList(repository.delete(request)); assertThat(deleted, hasSize(existingIds.size())); for (Object item : deleted) { assertThat(item, is(instanceOf(Person.class))); assertThat((Person) item, isIn(expected)); } }