mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-29 15:22:11 +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 Kevin Leturc
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
|
* @author Michael Wirth
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractElasticsearchRepository<T, ID extends Serializable>
|
public abstract class AbstractElasticsearchRepository<T, ID extends Serializable>
|
||||||
implements ElasticsearchRepository<T, ID> {
|
implements ElasticsearchRepository<T, ID> {
|
||||||
@ -188,7 +189,7 @@ public abstract class AbstractElasticsearchRepository<T, ID extends Serializable
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean existsById(ID id) {
|
public boolean existsById(ID id) {
|
||||||
return findById(id) != null;
|
return findById(id).isPresent();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -47,6 +47,7 @@ import static org.springframework.data.domain.Sort.Direction.*;
|
|||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
|
* @author Michael Wirth
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration("classpath:/simple-repository-test.xml")
|
@ContextConfiguration("classpath:/simple-repository-test.xml")
|
||||||
@ -274,6 +275,18 @@ public class SimpleElasticsearchRepositoryTests {
|
|||||||
assertEquals(exist, true);
|
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
|
@Test
|
||||||
public void shouldReturnResultsForGivenSearchQuery() {
|
public void shouldReturnResultsForGivenSearchQuery() {
|
||||||
// given
|
// given
|
||||||
|
@ -45,6 +45,7 @@ import static org.junit.Assert.*;
|
|||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
|
* @author Michael Wirth
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration("classpath:/simple-repository-test.xml")
|
@ContextConfiguration("classpath:/simple-repository-test.xml")
|
||||||
@ -262,6 +263,18 @@ public class UUIDElasticsearchRepositoryTests {
|
|||||||
assertEquals(exist, true);
|
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
|
@Test
|
||||||
public void shouldDeleteAll() {
|
public void shouldDeleteAll() {
|
||||||
// when
|
// when
|
||||||
|
Loading…
x
Reference in New Issue
Block a user