mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-29 07:12:26 +00:00
DATAES-363 - Fixed CrudRepository.existsById(…) implementation.
Properly use Optional.isPresent() over a null check. Original pull request: #183.
This commit is contained in:
parent
b8400d8d4d
commit
512e9eacad
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user