From 80757fd3cd869f329d9f733eeb328f3450d54e2a Mon Sep 17 00:00:00 2001 From: jloisel Date: Thu, 28 Jan 2016 11:10:50 +0100 Subject: [PATCH] fix: saveAll fails when input list is empty --- .../repository/elasticsearch/ElasticSearchRepository.java | 4 ++++ .../repository/elasticsearch/RepositoryIntegrationTest.java | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/db-repository-elasticsearch/src/main/java/com/jeromeloisel/db/repository/elasticsearch/ElasticSearchRepository.java b/db-repository-elasticsearch/src/main/java/com/jeromeloisel/db/repository/elasticsearch/ElasticSearchRepository.java index 9b03823..3456b63 100644 --- a/db-repository-elasticsearch/src/main/java/com/jeromeloisel/db/repository/elasticsearch/ElasticSearchRepository.java +++ b/db-repository-elasticsearch/src/main/java/com/jeromeloisel/db/repository/elasticsearch/ElasticSearchRepository.java @@ -98,6 +98,10 @@ public T save(final T entity) { @Override public List saveAll(final List entities) { + if(entities.isEmpty()) { + return entities; + } + final BulkRequestBuilder bulk = client .prepareBulk() .setRefresh(true); diff --git a/db-repository-elasticsearch/src/test/java/com/jeromeloisel/db/repository/elasticsearch/RepositoryIntegrationTest.java b/db-repository-elasticsearch/src/test/java/com/jeromeloisel/db/repository/elasticsearch/RepositoryIntegrationTest.java index b1c2e38..468ebfd 100644 --- a/db-repository-elasticsearch/src/test/java/com/jeromeloisel/db/repository/elasticsearch/RepositoryIntegrationTest.java +++ b/db-repository-elasticsearch/src/test/java/com/jeromeloisel/db/repository/elasticsearch/RepositoryIntegrationTest.java @@ -120,6 +120,12 @@ public void shouldSaveAll() { assertEquals(1, saved.size()); repository.delete(saved.get(0)); } + + @Test + public void shouldNotSaveAll() { + final List saved = repository.saveAll(ImmutableList.of()); + assertEquals(0, saved.size()); + } @Test public void shouldFindByFirstname() {