DATAKV-186 - SimpleKeyValueRepository.existsById(…) now evaluates findById(…) results properly.

ExistsById now evaluates Optional.isPresent() instead of comparing findById result to null.

Original Pull Request: #24
This commit is contained in:
EugeneNik
2017-07-19 23:49:12 +04:00
committed by Christoph Strobl
parent 256bb16dba
commit c5e0d1a26c
2 changed files with 13 additions and 1 deletions

View File

@@ -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.*;
@@ -124,6 +125,17 @@ public class SimpleKeyValueRepositoryUnitTests {
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() {