DATAES-363 - Fixed CrudRepository.existsById(…) implementation.

Properly use Optional.isPresent() over a null check.

Original pull request: #183.
This commit is contained in:
Michael Wirth 2017-06-24 01:08:38 +02:00 committed by Oliver Gierke
parent b8400d8d4d
commit 512e9eacad
3 changed files with 28 additions and 1 deletions

View File

@ -55,6 +55,7 @@ import org.springframework.util.Assert;
* @author Kevin Leturc
* @author Mark Paluch
* @author Christoph Strobl
* @author Michael Wirth
*/
public abstract class AbstractElasticsearchRepository<T, ID extends Serializable>
implements ElasticsearchRepository<T, ID> {
@ -188,7 +189,7 @@ public abstract class AbstractElasticsearchRepository<T, ID extends Serializable
@Override
public boolean existsById(ID id) {
return findById(id) != null;
return findById(id).isPresent();
}
@Override

View File

@ -47,6 +47,7 @@ import static org.springframework.data.domain.Sort.Direction.*;
* @author Mohsin Husen
* @author Mark Paluch
* @author Christoph Strobl
* @author Michael Wirth
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:/simple-repository-test.xml")
@ -274,6 +275,18 @@ public class SimpleElasticsearchRepositoryTests {
assertEquals(exist, true);
}
@Test // DATAES-363
public void shouldReturnFalseGivenDocumentWithIdDoesNotExist() {
// given
String documentId = randomNumeric(5);
// when
boolean exist = repository.existsById(documentId);
// then
assertEquals(exist, false);
}
@Test
public void shouldReturnResultsForGivenSearchQuery() {
// given

View File

@ -45,6 +45,7 @@ import static org.junit.Assert.*;
* @author Mohsin Husen
* @author Mark Paluch
* @author Christoph Strobl
* @author Michael Wirth
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:/simple-repository-test.xml")
@ -262,6 +263,18 @@ public class UUIDElasticsearchRepositoryTests {
assertEquals(exist, true);
}
@Test // DATAES-363
public void shouldReturnFalseGivenDocumentWithIdDoesNotExist() {
// given
UUID documentId = UUID.randomUUID();
// when
boolean exist = repository.existsById(documentId);
// then
assertEquals(exist, false);
}
@Test
public void shouldDeleteAll() {
// when