Skip to content

DATAKV - 186 : Incorrect behavior of SimpleKeyValueRepository.existsById(…) due to changes with Optional #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public Optional<T> findById(ID id) {
*/
@Override
public boolean existsById(ID id) {
return findById(id) != null;
return findById(id).isPresent();
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.springframework.data.keyvalue.repository;

import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;

Expand Down Expand Up @@ -124,6 +125,17 @@ public void findAllIds() {
verify(opsMock, times(3)).findById(anyString(), eq(Foo.class));
}

@Test // DATAKV-186
public void existsById() {
when(opsMock.findById(any(Serializable.class), any(Class.class))).thenReturn(Optional.empty());
assertFalse(repo.existsById("one"));

when(opsMock.findById(any(Serializable.class), any(Class.class))).thenReturn(Optional.of(new Foo()));
assertTrue(repo.existsById("one"));

verify(opsMock, times(2)).findById(anyString(), eq(Foo.class));
}

@Test // DATACMNS-525
public void findAllWithPageableShouldDelegateToOperationsCorrectlyWhenPageableDoesNotContainSort() {

Expand Down