DATAKV-271 - Migrate tests to AssertJ.
This commit is contained in:
@@ -15,15 +15,13 @@
|
||||
*/
|
||||
package org.springframework.data.keyvalue.core;
|
||||
|
||||
import static org.hamcrest.core.Is.*;
|
||||
import static org.hamcrest.core.IsInstanceOf.*;
|
||||
import static org.hamcrest.core.IsNull.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
|
||||
@@ -34,9 +32,10 @@ public class DefaultIdentifierGeneratorUnitTests {
|
||||
|
||||
DefaultIdentifierGenerator generator = DefaultIdentifierGenerator.INSTANCE;
|
||||
|
||||
@Test(expected = InvalidDataAccessApiUsageException.class)
|
||||
@Test
|
||||
public void shouldThrowExceptionForUnsupportedType() {
|
||||
generator.generateIdentifierOfType(ClassTypeInformation.from(Date.class));
|
||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
|
||||
.isThrownBy(() -> generator.generateIdentifierOfType(ClassTypeInformation.from(Date.class)));
|
||||
}
|
||||
|
||||
@Test // DATAKV-136
|
||||
@@ -44,8 +43,8 @@ public class DefaultIdentifierGeneratorUnitTests {
|
||||
|
||||
Object value = generator.generateIdentifierOfType(ClassTypeInformation.from(UUID.class));
|
||||
|
||||
assertThat(value, is(notNullValue()));
|
||||
assertThat(value, instanceOf(UUID.class));
|
||||
assertThat(value).isNotNull();
|
||||
assertThat(value).isInstanceOf(UUID.class);
|
||||
}
|
||||
|
||||
@Test // DATAKV-136
|
||||
@@ -53,8 +52,8 @@ public class DefaultIdentifierGeneratorUnitTests {
|
||||
|
||||
Object value = generator.generateIdentifierOfType(ClassTypeInformation.from(String.class));
|
||||
|
||||
assertThat(value, is(notNullValue()));
|
||||
assertThat(value, instanceOf(String.class));
|
||||
assertThat(value).isNotNull();
|
||||
assertThat(value).isInstanceOf(String.class);
|
||||
}
|
||||
|
||||
@Test // DATAKV-136
|
||||
@@ -62,8 +61,8 @@ public class DefaultIdentifierGeneratorUnitTests {
|
||||
|
||||
Object value = generator.generateIdentifierOfType(ClassTypeInformation.from(Long.class));
|
||||
|
||||
assertThat(value, is(notNullValue()));
|
||||
assertThat(value, instanceOf(Long.class));
|
||||
assertThat(value).isNotNull();
|
||||
assertThat(value).isInstanceOf(Long.class);
|
||||
}
|
||||
|
||||
@Test // DATAKV-136
|
||||
@@ -71,7 +70,7 @@ public class DefaultIdentifierGeneratorUnitTests {
|
||||
|
||||
Object value = generator.generateIdentifierOfType(ClassTypeInformation.from(Integer.class));
|
||||
|
||||
assertThat(value, is(notNullValue()));
|
||||
assertThat(value, instanceOf(Integer.class));
|
||||
assertThat(value).isNotNull();
|
||||
assertThat(value).isInstanceOf(Integer.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.keyvalue.core;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Iterator;
|
||||
@@ -49,7 +48,7 @@ public class ForwardingCloseableIteratorUnitTests<K, V> {
|
||||
CloseableIterator<Entry<K, V>> iterator = new ForwardingCloseableIterator<>(iteratorMock);
|
||||
|
||||
try {
|
||||
assertThat(iterator.hasNext(), is(true));
|
||||
assertThat(iterator.hasNext()).isTrue();
|
||||
verify(iteratorMock, times(1)).hasNext();
|
||||
} finally {
|
||||
iterator.close();
|
||||
@@ -65,14 +64,14 @@ public class ForwardingCloseableIteratorUnitTests<K, V> {
|
||||
CloseableIterator<Entry<K, V>> iterator = new ForwardingCloseableIterator<>(iteratorMock);
|
||||
|
||||
try {
|
||||
assertThat(iterator.next(), notNullValue());
|
||||
assertThat(iterator.next()).isNotNull();
|
||||
verify(iteratorMock, times(1)).next();
|
||||
} finally {
|
||||
iterator.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = NoSuchElementException.class) // DATAKV-99
|
||||
@Test // DATAKV-99
|
||||
public void nextShouldThrowErrorWhenWrappedIteratorHasNoMoreElements() {
|
||||
|
||||
when(iteratorMock.next()).thenThrow(new NoSuchElementException());
|
||||
@@ -80,7 +79,7 @@ public class ForwardingCloseableIteratorUnitTests<K, V> {
|
||||
CloseableIterator<Entry<K, V>> iterator = new ForwardingCloseableIterator<>(iteratorMock);
|
||||
|
||||
try {
|
||||
iterator.next();
|
||||
assertThatExceptionOfType(NoSuchElementException.class).isThrownBy(iterator::next);
|
||||
} finally {
|
||||
iterator.close();
|
||||
}
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.keyvalue.core;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.keyvalue.core.IterableConverter.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -36,7 +35,7 @@ public class IterableConverterUnitTests {
|
||||
|
||||
@Test // DATAKV-101
|
||||
public void toListShouldReturnEmptyListWhenSourceEmpty() {
|
||||
assertThat(toList(Collections.emptySet()), empty());
|
||||
assertThat(toList(Collections.emptySet())).isEmpty();
|
||||
}
|
||||
|
||||
@Test // DATAKV-101
|
||||
@@ -44,7 +43,7 @@ public class IterableConverterUnitTests {
|
||||
|
||||
List<String> source = new ArrayList<>();
|
||||
|
||||
assertThat(toList(source), sameInstance(source));
|
||||
assertThat(toList(source)).isSameAs(source);
|
||||
}
|
||||
|
||||
@Test // DATAKV-101
|
||||
@@ -53,7 +52,7 @@ public class IterableConverterUnitTests {
|
||||
Set<String> source = new HashSet<>();
|
||||
source.add("tyrion");
|
||||
|
||||
assertThat(toList(source), instanceOf(List.class));
|
||||
assertThat(toList(source)).isInstanceOf(List.class);
|
||||
}
|
||||
|
||||
@Test // DATAKV-101
|
||||
@@ -63,7 +62,7 @@ public class IterableConverterUnitTests {
|
||||
source.add("tyrion");
|
||||
source.add("jaime");
|
||||
|
||||
assertThat(toList(source), contains(source.toArray(new String[2])));
|
||||
assertThat(toList(source)).containsExactly(source.toArray(new String[2]));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,13 +15,12 @@
|
||||
*/
|
||||
package org.springframework.data.keyvalue.core;
|
||||
|
||||
import static org.hamcrest.core.IsInstanceOf.*;
|
||||
import static org.hamcrest.core.IsNull.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.dao.DataRetrievalFailureException;
|
||||
|
||||
@@ -34,42 +33,43 @@ public class KeyValuePersistenceExceptionTranslatorUnitTests {
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void translateExeptionShouldReturnDataAccessExceptionWhenGivenOne() {
|
||||
assertThat(translator.translateExceptionIfPossible(new DataRetrievalFailureException("booh")),
|
||||
instanceOf(DataRetrievalFailureException.class));
|
||||
assertThat(translator.translateExceptionIfPossible(new DataRetrievalFailureException("booh")))
|
||||
.isInstanceOf(DataRetrievalFailureException.class);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-525, DATAKV-192
|
||||
@Test // DATACMNS-525, DATAKV-192
|
||||
public void translateExeptionShouldReturnNullWhenGivenNull() {
|
||||
assertThat(translator.translateExceptionIfPossible(null), nullValue());
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> assertThat(translator.translateExceptionIfPossible(null)).isNull());
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void translateExeptionShouldTranslateNoSuchElementExceptionToDataRetrievalFailureException() {
|
||||
assertThat(translator.translateExceptionIfPossible(new NoSuchElementException("")),
|
||||
instanceOf(DataRetrievalFailureException.class));
|
||||
assertThat(translator.translateExceptionIfPossible(new NoSuchElementException("")))
|
||||
.isInstanceOf(DataRetrievalFailureException.class);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void translateExeptionShouldTranslateIndexOutOfBoundsExceptionToDataRetrievalFailureException() {
|
||||
assertThat(translator.translateExceptionIfPossible(new IndexOutOfBoundsException("")),
|
||||
instanceOf(DataRetrievalFailureException.class));
|
||||
assertThat(translator.translateExceptionIfPossible(new IndexOutOfBoundsException("")))
|
||||
.isInstanceOf(DataRetrievalFailureException.class);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void translateExeptionShouldTranslateIllegalStateExceptionToDataRetrievalFailureException() {
|
||||
assertThat(translator.translateExceptionIfPossible(new IllegalStateException("")),
|
||||
instanceOf(DataRetrievalFailureException.class));
|
||||
assertThat(translator.translateExceptionIfPossible(new IllegalStateException("")))
|
||||
.isInstanceOf(DataRetrievalFailureException.class);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void translateExeptionShouldTranslateAnyJavaExceptionToUncategorizedKeyValueException() {
|
||||
assertThat(translator.translateExceptionIfPossible(new UnsupportedOperationException("")),
|
||||
instanceOf(UncategorizedKeyValueException.class));
|
||||
assertThat(translator.translateExceptionIfPossible(new UnsupportedOperationException("")))
|
||||
.isInstanceOf(UncategorizedKeyValueException.class);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void translateExeptionShouldReturnNullForNonJavaExceptions() {
|
||||
assertThat(translator.translateExceptionIfPossible(new NoSuchBeanDefinitionException("")), nullValue());
|
||||
assertThat(translator.translateExceptionIfPossible(new NoSuchBeanDefinitionException(""))).isNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.keyvalue.core;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
@@ -32,6 +31,7 @@ import java.util.Optional;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.data.annotation.Id;
|
||||
@@ -72,21 +72,22 @@ public class KeyValueTemplateTests {
|
||||
operations.insert("1", FOO_ONE);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-525
|
||||
@Test // DATACMNS-525
|
||||
public void insertShouldThrowExceptionForNullId() {
|
||||
operations.insert(null, FOO_ONE);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> operations.insert(null, FOO_ONE));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-525
|
||||
@Test // DATACMNS-525
|
||||
public void insertShouldThrowExceptionForNullObject() {
|
||||
operations.insert("some-id", null);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> operations.insert("some-id", null));
|
||||
}
|
||||
|
||||
@Test(expected = DuplicateKeyException.class) // DATACMNS-525
|
||||
@Test // DATACMNS-525
|
||||
public void insertShouldThrowExecptionWhenObjectOfSameTypeAlreadyExists() {
|
||||
|
||||
operations.insert("1", FOO_ONE);
|
||||
operations.insert("1", FOO_TWO);
|
||||
|
||||
assertThatExceptionOfType(DuplicateKeyException.class).isThrownBy(() -> operations.insert("1", FOO_TWO));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@@ -102,7 +103,7 @@ public class KeyValueTemplateTests {
|
||||
ClassWithStringId source = new ClassWithStringId();
|
||||
ClassWithStringId target = operations.insert(source);
|
||||
|
||||
assertThat(target, sameInstance(source));
|
||||
assertThat(target).isSameAs(source);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@@ -113,28 +114,28 @@ public class KeyValueTemplateTests {
|
||||
|
||||
operations.insert(source);
|
||||
|
||||
assertThat(operations.findById("one", ClassWithStringId.class), is(Optional.of(source)));
|
||||
assertThat(operations.findById("one", ClassWithStringId.class)).isEqualTo(Optional.of(source));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void findByIdShouldReturnObjectWithMatchingIdAndType() {
|
||||
|
||||
operations.insert("1", FOO_ONE);
|
||||
assertThat(operations.findById("1", Foo.class), is(Optional.of(FOO_ONE)));
|
||||
assertThat(operations.findById("1", Foo.class)).isEqualTo(Optional.of(FOO_ONE));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void findByIdSouldReturnOptionalEmptyIfNoMatchingIdFound() {
|
||||
|
||||
operations.insert("1", FOO_ONE);
|
||||
assertThat(operations.findById("2", Foo.class), is(Optional.empty()));
|
||||
assertThat(operations.findById("2", Foo.class)).isEmpty();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void findByIdShouldReturnOptionalEmptyIfNoMatchingTypeFound() {
|
||||
|
||||
operations.insert("1", FOO_ONE);
|
||||
assertThat(operations.findById("1", Bar.class), is(Optional.empty()));
|
||||
assertThat(operations.findById("1", Bar.class)).isEmpty();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@@ -144,8 +145,8 @@ public class KeyValueTemplateTests {
|
||||
operations.insert("2", FOO_TWO);
|
||||
|
||||
List<Foo> result = (List<Foo>) operations.find(STRING_QUERY, Foo.class);
|
||||
assertThat(result, hasSize(1));
|
||||
assertThat(result.get(0), is(FOO_TWO));
|
||||
assertThat(result).hasSize(1);
|
||||
assertThat(result.get(0)).isEqualTo(FOO_TWO);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@@ -155,7 +156,7 @@ public class KeyValueTemplateTests {
|
||||
operations.insert("2", FOO_TWO);
|
||||
operations.insert("3", FOO_THREE);
|
||||
|
||||
assertThat(operations.findInRange(5, 5, Foo.class), emptyIterable());
|
||||
assertThat(operations.findInRange(5, 5, Foo.class)).isEmpty();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@@ -163,7 +164,7 @@ public class KeyValueTemplateTests {
|
||||
|
||||
operations.insert("1", FOO_ONE);
|
||||
operations.update("1", FOO_TWO);
|
||||
assertThat(operations.findById("1", Foo.class), is(Optional.of(FOO_TWO)));
|
||||
assertThat(operations.findById("1", Foo.class)).isEqualTo(Optional.of(FOO_TWO));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@@ -172,7 +173,7 @@ public class KeyValueTemplateTests {
|
||||
operations.insert("1", FOO_ONE);
|
||||
operations.update("1", BAR_ONE);
|
||||
|
||||
assertThat(operations.findById("1", Foo.class), is(Optional.of(FOO_ONE)));
|
||||
assertThat(operations.findById("1", Foo.class)).isEqualTo(Optional.of(FOO_ONE));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@@ -180,31 +181,31 @@ public class KeyValueTemplateTests {
|
||||
|
||||
operations.insert("1", FOO_ONE);
|
||||
operations.delete("1", Foo.class);
|
||||
assertThat(operations.findById("1", Foo.class), is(Optional.empty()));
|
||||
assertThat(operations.findById("1", Foo.class)).isEmpty();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void deleteReturnsNullWhenNotExisting() {
|
||||
|
||||
operations.insert("1", FOO_ONE);
|
||||
assertThat(operations.delete("2", Foo.class), nullValue());
|
||||
assertThat(operations.delete("2", Foo.class)).isNull();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void deleteReturnsRemovedObject() {
|
||||
|
||||
operations.insert("1", FOO_ONE);
|
||||
assertThat(operations.delete("1", Foo.class), is(FOO_ONE));
|
||||
assertThat(operations.delete("1", Foo.class)).isEqualTo(FOO_ONE);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-525
|
||||
@Test // DATACMNS-525
|
||||
public void deleteThrowsExceptionWhenIdCannotBeExctracted() {
|
||||
operations.delete(FOO_ONE);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> operations.delete(FOO_ONE));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void countShouldReturnZeroWhenNoElementsPresent() {
|
||||
assertThat(operations.count(Foo.class), is(0L));
|
||||
assertThat(operations.count(Foo.class)).isEqualTo(0L);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@@ -213,7 +214,7 @@ public class KeyValueTemplateTests {
|
||||
operations.insert("1", ALIASED);
|
||||
operations.insert("2", SUBCLASS_OF_ALIASED);
|
||||
|
||||
assertThat(operations.findAll(ALIASED.getClass()), containsInAnyOrder(ALIASED, SUBCLASS_OF_ALIASED));
|
||||
assertThat((List) operations.findAll(ALIASED.getClass())).contains(ALIASED, SUBCLASS_OF_ALIASED);
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -15,10 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.keyvalue.core;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Mockito.any;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
@@ -27,16 +25,14 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.dao.DuplicateKeyException;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
@@ -64,8 +60,6 @@ import org.springframework.data.keyvalue.core.query.KeyValueQuery;
|
||||
@RunWith(MockitoJUnitRunner.Silent.class)
|
||||
public class KeyValueTemplateUnitTests {
|
||||
|
||||
public @Rule ExpectedException exception = ExpectedException.none();
|
||||
|
||||
private static final Foo FOO_ONE = new Foo("one");
|
||||
private static final Foo FOO_TWO = new Foo("two");
|
||||
private static final TypeWithCustomComposedKeySpaceAnnotationUsingAliasFor ALIASED_USING_ALIAS_FOR = new TypeWithCustomComposedKeySpaceAnnotationUsingAliasFor(
|
||||
@@ -79,19 +73,19 @@ public class KeyValueTemplateUnitTests {
|
||||
private @Mock ApplicationEventPublisher publisherMock;
|
||||
|
||||
@Before
|
||||
public void setUp() throws InstantiationException, IllegalAccessException {
|
||||
public void setUp() {
|
||||
this.template = new KeyValueTemplate(adapterMock);
|
||||
this.template.setApplicationEventPublisher(publisherMock);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-525
|
||||
@Test // DATACMNS-525
|
||||
public void shouldThrowExceptionWhenCreatingNewTempateWithNullAdapter() {
|
||||
new KeyValueTemplate(null);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new KeyValueTemplate(null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-525
|
||||
@Test // DATACMNS-525
|
||||
public void shouldThrowExceptionWhenCreatingNewTempateWithNullMappingContext() {
|
||||
new KeyValueTemplate(adapterMock, null);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new KeyValueTemplate(adapterMock, null));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@@ -115,29 +109,26 @@ public class KeyValueTemplateUnitTests {
|
||||
|
||||
ClassWithStringId object = new ClassWithStringId();
|
||||
|
||||
assertThat(template.insert(object), is(object));
|
||||
assertThat(template.insert("1", object), is(object));
|
||||
assertThat(template.insert(object)).isEqualTo(object);
|
||||
assertThat(template.insert("1", object)).isEqualTo(object);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void insertShouldThrowExceptionWhenObectWithIdAlreadyExists() {
|
||||
|
||||
exception.expect(DuplicateKeyException.class);
|
||||
exception.expectMessage("id 1");
|
||||
|
||||
when(adapterMock.contains(anyString(), anyString())).thenReturn(true);
|
||||
|
||||
template.insert("1", FOO_ONE);
|
||||
assertThatExceptionOfType(DuplicateKeyException.class).isThrownBy(() -> template.insert("1", FOO_ONE));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-525
|
||||
@Test // DATACMNS-525
|
||||
public void insertShouldThrowExceptionForNullId() {
|
||||
template.insert(null, FOO_ONE);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> template.insert(null, FOO_ONE));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-525
|
||||
@Test // DATACMNS-525
|
||||
public void insertShouldThrowExceptionForNullObject() {
|
||||
template.insert("some-id", null);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> template.insert("some-id", null));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@@ -145,12 +136,12 @@ public class KeyValueTemplateUnitTests {
|
||||
|
||||
ClassWithStringId target = template.insert(new ClassWithStringId());
|
||||
|
||||
assertThat(target.id, notNullValue());
|
||||
assertThat(target.id).isNotNull();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-525
|
||||
@Test // DATACMNS-525
|
||||
public void insertShouldThrowErrorWhenIdCannotBeResolved() {
|
||||
template.insert(FOO_ONE);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> template.insert(FOO_ONE));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@@ -159,7 +150,7 @@ public class KeyValueTemplateUnitTests {
|
||||
ClassWithStringId source = new ClassWithStringId();
|
||||
ClassWithStringId target = template.insert(source);
|
||||
|
||||
assertThat(target, sameInstance(source));
|
||||
assertThat(target).isSameAs(source);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@@ -175,7 +166,7 @@ public class KeyValueTemplateUnitTests {
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void findByIdShouldReturnOptionalEmptyWhenNoElementsPresent() {
|
||||
assertThat(template.findById("1", Foo.class), is(Optional.empty()));
|
||||
assertThat(template.findById("1", Foo.class)).isEmpty();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@@ -186,9 +177,9 @@ public class KeyValueTemplateUnitTests {
|
||||
verify(adapterMock, times(1)).get("1", Foo.class.getName(), Foo.class);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-525, DATAKV-187
|
||||
@Test // DATACMNS-525, DATAKV-187
|
||||
public void findByIdShouldThrowExceptionWhenGivenNullId() {
|
||||
template.findById(null, Foo.class);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> template.findById(null, Foo.class));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@@ -199,9 +190,9 @@ public class KeyValueTemplateUnitTests {
|
||||
verify(adapterMock, times(1)).getAllOf(Foo.class.getName());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-525
|
||||
@Test // DATACMNS-525
|
||||
public void findAllOfShouldThrowExceptionWhenGivenNullType() {
|
||||
template.findAll(null);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> template.findAll(null));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@@ -221,9 +212,9 @@ public class KeyValueTemplateUnitTests {
|
||||
template.findInRange(1, 5, Foo.class);
|
||||
|
||||
verify(adapterMock, times(1)).find(captor.capture(), eq(Foo.class.getName()), eq(Foo.class));
|
||||
assertThat(captor.getValue().getOffset(), is(1L));
|
||||
assertThat(captor.getValue().getRows(), is(5));
|
||||
assertThat(captor.getValue().getCriteria(), nullValue());
|
||||
assertThat(captor.getValue().getOffset()).isEqualTo(1L);
|
||||
assertThat(captor.getValue().getRows()).isEqualTo(5);
|
||||
assertThat(captor.getValue().getCriteria()).isNull();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@@ -240,18 +231,18 @@ public class KeyValueTemplateUnitTests {
|
||||
ClassWithStringId object = new ClassWithStringId();
|
||||
object.id = "foo";
|
||||
|
||||
assertThat(template.update(object), is(object));
|
||||
assertThat(template.update("1", object), is(object));
|
||||
assertThat(template.update(object)).isEqualTo(object);
|
||||
assertThat(template.update("1", object)).isEqualTo(object);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-525
|
||||
@Test // DATACMNS-525
|
||||
public void updateShouldThrowExceptionWhenGivenNullId() {
|
||||
template.update(null, FOO_ONE);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> template.update(null, FOO_ONE));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-525
|
||||
@Test // DATACMNS-525
|
||||
public void updateShouldThrowExceptionWhenGivenNullObject() {
|
||||
template.update("1", null);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> template.update("1", null));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@@ -265,9 +256,9 @@ public class KeyValueTemplateUnitTests {
|
||||
verify(adapterMock, times(1)).put(source.id, source, ClassWithStringId.class.getName());
|
||||
}
|
||||
|
||||
@Test(expected = InvalidDataAccessApiUsageException.class) // DATACMNS-525
|
||||
@Test // DATACMNS-525
|
||||
public void updateShouldThrowErrorWhenIdInformationCannotBeExtracted() {
|
||||
template.update(FOO_ONE);
|
||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() -> template.update(FOO_ONE));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@@ -289,9 +280,9 @@ public class KeyValueTemplateUnitTests {
|
||||
verify(adapterMock, times(1)).delete("some-id", ClassWithStringId.class.getName(), ClassWithStringId.class);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-525
|
||||
@Test // DATACMNS-525
|
||||
public void deleteThrowsExceptionWhenIdCannotBeExctracted() {
|
||||
template.delete(FOO_ONE);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> template.delete(FOO_ONE));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@@ -304,12 +295,12 @@ public class KeyValueTemplateUnitTests {
|
||||
|
||||
when(adapterMock.count(Foo.class.getName())).thenReturn(2L);
|
||||
|
||||
assertThat(template.count(Foo.class), is(2L));
|
||||
assertThat(template.count(Foo.class)).isEqualTo(2L);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-525
|
||||
@Test // DATACMNS-525
|
||||
public void countShouldThrowErrorOnNullType() {
|
||||
template.count(null);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> template.count(null));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@@ -335,20 +326,20 @@ public class KeyValueTemplateUnitTests {
|
||||
Collection foo = Arrays.asList(ALIASED_USING_ALIAS_FOR, SUBCLASS_OF_ALIASED_USING_ALIAS_FOR);
|
||||
when(adapterMock.getAllOf("aliased")).thenReturn(foo);
|
||||
|
||||
assertThat(template.findAll(SUBCLASS_OF_ALIASED_USING_ALIAS_FOR.getClass()),
|
||||
containsInAnyOrder(SUBCLASS_OF_ALIASED_USING_ALIAS_FOR));
|
||||
assertThat((Iterable) template.findAll(SUBCLASS_OF_ALIASED_USING_ALIAS_FOR.getClass()))
|
||||
.contains(SUBCLASS_OF_ALIASED_USING_ALIAS_FOR);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void insertSouldRespectTypeAliasAndFilterNonMatching() {
|
||||
|
||||
template.insert("1", ALIASED_USING_ALIAS_FOR);
|
||||
assertThat(template.findById("1", SUBCLASS_OF_ALIASED_USING_ALIAS_FOR.getClass()), is(Optional.empty()));
|
||||
assertThat(template.findById("1", SUBCLASS_OF_ALIASED_USING_ALIAS_FOR.getClass())).isEmpty();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-525
|
||||
@Test // DATACMNS-525
|
||||
public void setttingNullPersistenceExceptionTranslatorShouldThrowException() {
|
||||
template.setExceptionTranslator(null);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> template.setExceptionTranslator(null));
|
||||
}
|
||||
|
||||
@Test // DATAKV-91
|
||||
@@ -414,9 +405,9 @@ public class KeyValueTemplateUnitTests {
|
||||
verify(publisherMock, times(1)).publishEvent(captor.capture());
|
||||
verifyNoMoreInteractions(publisherMock);
|
||||
|
||||
assertThat(captor.getValue().getKey(), is("1"));
|
||||
assertThat(captor.getValue().getKeyspace(), is(Foo.class.getName()));
|
||||
assertThat(captor.getValue().getPayload(), is(FOO_ONE));
|
||||
assertThat(captor.getValue().getKey()).isEqualTo("1");
|
||||
assertThat(captor.getValue().getKeyspace()).isEqualTo(Foo.class.getName());
|
||||
assertThat(captor.getValue().getPayload()).isEqualTo(FOO_ONE);
|
||||
}
|
||||
|
||||
@Test // DATAKV-91, DATAKV-104, DATAKV-187
|
||||
@@ -432,9 +423,9 @@ public class KeyValueTemplateUnitTests {
|
||||
verify(publisherMock, times(1)).publishEvent(captor.capture());
|
||||
verifyNoMoreInteractions(publisherMock);
|
||||
|
||||
assertThat(captor.getValue().getKey(), is("1"));
|
||||
assertThat(captor.getValue().getKeyspace(), is(Foo.class.getName()));
|
||||
assertThat(captor.getValue().getPayload(), is(FOO_ONE));
|
||||
assertThat(captor.getValue().getKey()).isEqualTo("1");
|
||||
assertThat(captor.getValue().getKeyspace()).isEqualTo(Foo.class.getName());
|
||||
assertThat(captor.getValue().getPayload()).isEqualTo(FOO_ONE);
|
||||
}
|
||||
|
||||
@Test // DATAKV-91, DATAKV-104, DATAKV-187
|
||||
@@ -450,9 +441,9 @@ public class KeyValueTemplateUnitTests {
|
||||
verify(publisherMock, times(1)).publishEvent(captor.capture());
|
||||
verifyNoMoreInteractions(publisherMock);
|
||||
|
||||
assertThat(captor.getValue().getKey(), is("1"));
|
||||
assertThat(captor.getValue().getKeyspace(), is(Foo.class.getName()));
|
||||
assertThat(captor.getValue().getPayload(), is(FOO_ONE));
|
||||
assertThat(captor.getValue().getKey()).isEqualTo("1");
|
||||
assertThat(captor.getValue().getKeyspace()).isEqualTo(Foo.class.getName());
|
||||
assertThat(captor.getValue().getPayload()).isEqualTo(FOO_ONE);
|
||||
}
|
||||
|
||||
@Test // DATAKV-91, DATAKV-104, DATAKV-187
|
||||
@@ -468,9 +459,9 @@ public class KeyValueTemplateUnitTests {
|
||||
verify(publisherMock, times(1)).publishEvent(captor.capture());
|
||||
verifyNoMoreInteractions(publisherMock);
|
||||
|
||||
assertThat(captor.getValue().getKey(), is("1"));
|
||||
assertThat(captor.getValue().getKeyspace(), is(Foo.class.getName()));
|
||||
assertThat(captor.getValue().getPayload(), is(FOO_ONE));
|
||||
assertThat(captor.getValue().getKey()).isEqualTo("1");
|
||||
assertThat(captor.getValue().getKeyspace()).isEqualTo(Foo.class.getName());
|
||||
assertThat(captor.getValue().getPayload()).isEqualTo(FOO_ONE);
|
||||
}
|
||||
|
||||
@Test // DATAKV-91, DATAKV-104, DATAKV-187
|
||||
@@ -486,8 +477,8 @@ public class KeyValueTemplateUnitTests {
|
||||
verify(publisherMock, times(1)).publishEvent(captor.capture());
|
||||
verifyNoMoreInteractions(publisherMock);
|
||||
|
||||
assertThat(captor.getValue().getKey(), is("1"));
|
||||
assertThat(captor.getValue().getKeyspace(), is(Foo.class.getName()));
|
||||
assertThat(captor.getValue().getKey()).isEqualTo("1");
|
||||
assertThat(captor.getValue().getKeyspace()).isEqualTo(Foo.class.getName());
|
||||
}
|
||||
|
||||
@Test // DATAKV-91, DATAKV-104, DATAKV-187
|
||||
@@ -504,9 +495,9 @@ public class KeyValueTemplateUnitTests {
|
||||
verify(publisherMock, times(1)).publishEvent(captor.capture());
|
||||
verifyNoMoreInteractions(publisherMock);
|
||||
|
||||
assertThat(captor.getValue().getKey(), is("1"));
|
||||
assertThat(captor.getValue().getKeyspace(), is(Foo.class.getName()));
|
||||
assertThat(captor.getValue().getPayload(), is(FOO_ONE));
|
||||
assertThat(captor.getValue().getKey()).isEqualTo("1");
|
||||
assertThat(captor.getValue().getKeyspace()).isEqualTo(Foo.class.getName());
|
||||
assertThat(captor.getValue().getPayload()).isEqualTo(FOO_ONE);
|
||||
}
|
||||
|
||||
@Test // DATAKV-91, DATAKV-104, DATAKV-187
|
||||
@@ -524,8 +515,8 @@ public class KeyValueTemplateUnitTests {
|
||||
verify(publisherMock, times(1)).publishEvent(captor.capture());
|
||||
verifyNoMoreInteractions(publisherMock);
|
||||
|
||||
assertThat(captor.getValue().getKey(), is("1"));
|
||||
assertThat(captor.getValue().getKeyspace(), is(Foo.class.getName()));
|
||||
assertThat(captor.getValue().getKey()).isEqualTo("1");
|
||||
assertThat(captor.getValue().getKeyspace()).isEqualTo(Foo.class.getName());
|
||||
}
|
||||
|
||||
@Test // DATAKV-91, DATAKV-104
|
||||
@@ -543,9 +534,9 @@ public class KeyValueTemplateUnitTests {
|
||||
verify(publisherMock, times(1)).publishEvent(captor.capture());
|
||||
verifyNoMoreInteractions(publisherMock);
|
||||
|
||||
assertThat(captor.getValue().getKey(), is("1"));
|
||||
assertThat(captor.getValue().getKeyspace(), is(Foo.class.getName()));
|
||||
assertThat(captor.getValue().getPayload(), is(FOO_ONE));
|
||||
assertThat(captor.getValue().getKey()).isEqualTo("1");
|
||||
assertThat(captor.getValue().getKeyspace()).isEqualTo(Foo.class.getName());
|
||||
assertThat(captor.getValue().getPayload()).isEqualTo(FOO_ONE);
|
||||
}
|
||||
|
||||
@Test // DATAKV-91, DATAKV-104, DATAKV-187
|
||||
@@ -561,7 +552,7 @@ public class KeyValueTemplateUnitTests {
|
||||
verify(publisherMock, times(1)).publishEvent(captor.capture());
|
||||
verifyNoMoreInteractions(publisherMock);
|
||||
|
||||
assertThat(captor.getValue().getKeyspace(), is(Foo.class.getName()));
|
||||
assertThat(captor.getValue().getKeyspace()).isEqualTo(Foo.class.getName());
|
||||
}
|
||||
|
||||
@Test // DATAKV-129
|
||||
|
||||
@@ -16,13 +16,12 @@
|
||||
package org.springframework.data.keyvalue.core;
|
||||
|
||||
import static java.lang.Integer.*;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.hamcrest.number.OrderingComparison.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
|
||||
/**
|
||||
@@ -44,79 +43,79 @@ public class SpelPropertyComperatorUnitTests {
|
||||
public void shouldCompareStringAscCorrectly() {
|
||||
|
||||
Comparator<SomeType> comparator = new SpelPropertyComparator<>("stringProperty", PARSER);
|
||||
assertThat(comparator.compare(ONE, TWO), is(ONE.getStringProperty().compareTo(TWO.getStringProperty())));
|
||||
assertThat(comparator.compare(ONE, TWO)).isEqualTo(ONE.getStringProperty().compareTo(TWO.getStringProperty()));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void shouldCompareStringDescCorrectly() {
|
||||
|
||||
Comparator<SomeType> comparator = new SpelPropertyComparator<SomeType>("stringProperty", PARSER).desc();
|
||||
assertThat(comparator.compare(ONE, TWO), is(TWO.getStringProperty().compareTo(ONE.getStringProperty())));
|
||||
assertThat(comparator.compare(ONE, TWO)).isEqualTo(TWO.getStringProperty().compareTo(ONE.getStringProperty()));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void shouldCompareIntegerAscCorrectly() {
|
||||
|
||||
Comparator<SomeType> comparator = new SpelPropertyComparator<>("integerProperty", PARSER);
|
||||
assertThat(comparator.compare(ONE, TWO), is(ONE.getIntegerProperty().compareTo(TWO.getIntegerProperty())));
|
||||
assertThat(comparator.compare(ONE, TWO)).isEqualTo(ONE.getIntegerProperty().compareTo(TWO.getIntegerProperty()));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void shouldCompareIntegerDescCorrectly() {
|
||||
|
||||
Comparator<SomeType> comparator = new SpelPropertyComparator<SomeType>("integerProperty", PARSER).desc();
|
||||
assertThat(comparator.compare(ONE, TWO), is(TWO.getIntegerProperty().compareTo(ONE.getIntegerProperty())));
|
||||
assertThat(comparator.compare(ONE, TWO)).isEqualTo(TWO.getIntegerProperty().compareTo(ONE.getIntegerProperty()));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void shouldComparePrimitiveIntegerAscCorrectly() {
|
||||
|
||||
Comparator<SomeType> comparator = new SpelPropertyComparator<>("primitiveProperty", PARSER);
|
||||
assertThat(comparator.compare(ONE, TWO),
|
||||
is(valueOf(ONE.getPrimitiveProperty()).compareTo(valueOf(TWO.getPrimitiveProperty()))));
|
||||
assertThat(comparator.compare(ONE, TWO))
|
||||
.isEqualTo(valueOf(ONE.getPrimitiveProperty()).compareTo(valueOf(TWO.getPrimitiveProperty())));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void shouldNotFailOnNullValues() {
|
||||
|
||||
Comparator<SomeType> comparator = new SpelPropertyComparator<>("stringProperty", PARSER);
|
||||
assertThat(comparator.compare(ONE, new SomeType(null, null, 2)), is(1));
|
||||
assertThat(comparator.compare(ONE, new SomeType(null, null, 2))).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void shouldComparePrimitiveIntegerDescCorrectly() {
|
||||
|
||||
Comparator<SomeType> comparator = new SpelPropertyComparator<SomeType>("primitiveProperty", PARSER).desc();
|
||||
assertThat(comparator.compare(ONE, TWO),
|
||||
is(valueOf(TWO.getPrimitiveProperty()).compareTo(valueOf(ONE.getPrimitiveProperty()))));
|
||||
assertThat(comparator.compare(ONE, TWO))
|
||||
.isEqualTo(valueOf(TWO.getPrimitiveProperty()).compareTo(valueOf(ONE.getPrimitiveProperty())));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void shouldSortNullsFirstCorrectly() {
|
||||
Comparator<SomeType> comparator = new SpelPropertyComparator<SomeType>("stringProperty", PARSER).nullsFirst();
|
||||
assertThat(comparator.compare(ONE, new SomeType(null, null, 2)), equalTo(1));
|
||||
assertThat(comparator.compare(ONE, new SomeType(null, null, 2))).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void shouldSortNullsLastCorrectly() {
|
||||
|
||||
Comparator<SomeType> comparator = new SpelPropertyComparator<SomeType>("stringProperty", PARSER).nullsLast();
|
||||
assertThat(comparator.compare(ONE, new SomeType(null, null, 2)), equalTo(-1));
|
||||
assertThat(comparator.compare(ONE, new SomeType(null, null, 2))).isEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void shouldCompareNestedTypesCorrectly() {
|
||||
|
||||
Comparator<WrapperType> comparator = new SpelPropertyComparator<>("nestedType.stringProperty", PARSER);
|
||||
assertThat(comparator.compare(WRAPPER_ONE, WRAPPER_TWO),
|
||||
is(WRAPPER_ONE.getNestedType().getStringProperty().compareTo(WRAPPER_TWO.getNestedType().getStringProperty())));
|
||||
assertThat(comparator.compare(WRAPPER_ONE, WRAPPER_TWO)).isEqualTo(
|
||||
WRAPPER_ONE.getNestedType().getStringProperty().compareTo(WRAPPER_TWO.getNestedType().getStringProperty()));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void shouldCompareNestedTypesCorrectlyWhenOneOfThemHasNullValue() {
|
||||
|
||||
SpelPropertyComparator<WrapperType> comparator = new SpelPropertyComparator<>("nestedType.stringProperty", PARSER);
|
||||
assertThat(comparator.compare(WRAPPER_ONE, new WrapperType("two", null)), is(greaterThanOrEqualTo(1)));
|
||||
assertThat(comparator.compare(WRAPPER_ONE, new WrapperType("two", null))).isGreaterThanOrEqualTo(1);
|
||||
}
|
||||
|
||||
static class WrapperType {
|
||||
|
||||
@@ -15,9 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.keyvalue.core;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
@@ -30,6 +28,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.keyvalue.repository.query.SpelQueryCreator;
|
||||
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
|
||||
@@ -71,8 +70,8 @@ public class SpelQueryEngineUnitTests {
|
||||
|
||||
doReturn(people).when(adapter).getAllOf(anyString());
|
||||
|
||||
assertThat(engine.execute(createQueryForMethodWithArgs("findByFirstname", "bob"), null, -1, -1, anyString()),
|
||||
contains(BOB_WITH_FIRSTNAME));
|
||||
assertThat(engine.execute(createQueryForMethodWithArgs("findByFirstname", "bob"), null, -1, -1, anyString()))
|
||||
.containsExactly(BOB_WITH_FIRSTNAME);
|
||||
}
|
||||
|
||||
@Test // DATAKV-114
|
||||
@@ -80,7 +79,7 @@ public class SpelQueryEngineUnitTests {
|
||||
|
||||
doReturn(people).when(adapter).getAllOf(anyString());
|
||||
|
||||
assertThat(engine.count(createQueryForMethodWithArgs("findByFirstname", "bob"), anyString()), is(1L));
|
||||
assertThat(engine.count(createQueryForMethodWithArgs("findByFirstname", "bob"), anyString())).isEqualTo(1L);
|
||||
}
|
||||
|
||||
private static SpelCriteria createQueryForMethodWithArgs(String methodName, Object... args) throws Exception {
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.keyvalue.core.mapping;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
@@ -25,6 +24,7 @@ import java.lang.annotation.Target;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
import org.springframework.data.annotation.Persistent;
|
||||
import org.springframework.data.keyvalue.TypeWithDirectKeySpaceAnnotation;
|
||||
@@ -49,42 +49,42 @@ public class AnnotationBasedKeySpaceResolverUnitTests {
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void shouldResolveKeySpaceDefaultValueCorrectly() {
|
||||
assertThat(resolver.resolveKeySpace(EntityWithDefaultKeySpace.class), is("daenerys"));
|
||||
assertThat(resolver.resolveKeySpace(EntityWithDefaultKeySpace.class)).isEqualTo("daenerys");
|
||||
}
|
||||
|
||||
@Test // DATAKV-105
|
||||
public void shouldReturnNullWhenNoKeySpaceFoundOnComposedPersistentAnnotation() {
|
||||
assertThat(resolver.resolveKeySpace(TypeWithInhteritedPersistentAnnotationNotHavingKeySpace.class), nullValue());
|
||||
assertThat(resolver.resolveKeySpace(TypeWithInhteritedPersistentAnnotationNotHavingKeySpace.class)).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAKV-105
|
||||
public void shouldReturnNullWhenPersistentIsFoundOnNonComposedAnnotation() {
|
||||
assertThat(resolver.resolveKeySpace(TypeWithPersistentAnnotationNotHavingKeySpace.class), nullValue());
|
||||
assertThat(resolver.resolveKeySpace(TypeWithPersistentAnnotationNotHavingKeySpace.class)).isNull();
|
||||
}
|
||||
|
||||
@Test // DATAKV-105
|
||||
public void shouldReturnNullWhenPersistentIsNotFound() {
|
||||
assertThat(resolver.resolveKeySpace(TypeWithoutKeySpace.class), nullValue());
|
||||
assertThat(resolver.resolveKeySpace(TypeWithoutKeySpace.class)).isNull();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void shouldResolveInheritedKeySpaceCorrectly() {
|
||||
assertThat(resolver.resolveKeySpace(EntityWithInheritedKeySpace.class), is("viserys"));
|
||||
assertThat(resolver.resolveKeySpace(EntityWithInheritedKeySpace.class)).isEqualTo("viserys");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void shouldResolveDirectKeySpaceAnnotationCorrectly() {
|
||||
assertThat(resolver.resolveKeySpace(TypeWithDirectKeySpaceAnnotation.class), is("rhaegar"));
|
||||
assertThat(resolver.resolveKeySpace(TypeWithDirectKeySpaceAnnotation.class)).isEqualTo("rhaegar");
|
||||
}
|
||||
|
||||
@Test // DATAKV-129
|
||||
public void shouldResolveKeySpaceUsingAliasForCorrectly() {
|
||||
assertThat(resolver.resolveKeySpace(EntityWithSetKeySpaceUsingAliasFor.class), is("viserys"));
|
||||
assertThat(resolver.resolveKeySpace(EntityWithSetKeySpaceUsingAliasFor.class)).isEqualTo("viserys");
|
||||
}
|
||||
|
||||
@Test // DATAKV-129
|
||||
public void shouldResolveKeySpaceUsingAliasForCorrectlyOnSubClass() {
|
||||
assertThat(resolver.resolveKeySpace(EntityWithInheritedKeySpaceUsingAliasFor.class), is("viserys"));
|
||||
assertThat(resolver.resolveKeySpace(EntityWithInheritedKeySpaceUsingAliasFor.class)).isEqualTo("viserys");
|
||||
}
|
||||
|
||||
@PersistentAnnotationWithExplicitKeySpaceUsingAliasFor
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.keyvalue.repository;
|
||||
|
||||
import static org.hamcrest.core.Is.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@@ -31,6 +30,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Persistent;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
@@ -141,7 +141,7 @@ public class SimpleKeyValueRepositoryUnitTests {
|
||||
public void existsByIdReturnsFalseForEmptyOptional() {
|
||||
|
||||
when(opsMock.findById(any(), any(Class.class))).thenReturn(Optional.empty());
|
||||
assertThat(repo.existsById("one"), is(false));
|
||||
assertThat(repo.existsById("one")).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATAKV-186
|
||||
@@ -149,7 +149,7 @@ public class SimpleKeyValueRepositoryUnitTests {
|
||||
public void existsByIdReturnsTrueWhenOptionalValuePresent() {
|
||||
|
||||
when(opsMock.findById(any(), any(Class.class))).thenReturn(Optional.of(new Foo()));
|
||||
assertTrue(repo.existsById("one"));
|
||||
assertThat(repo.existsById("one")).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
|
||||
@@ -15,9 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.keyvalue.repository.query;
|
||||
|
||||
import static org.hamcrest.core.IsNot.*;
|
||||
import static org.hamcrest.core.IsSame.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@@ -29,6 +27,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.data.keyvalue.Person;
|
||||
import org.springframework.data.keyvalue.core.KeyValueOperations;
|
||||
import org.springframework.data.keyvalue.core.SpelCriteria;
|
||||
@@ -71,8 +70,8 @@ public class CachingKeyValuePartTreeQueryUnitTests {
|
||||
SpelCriteria first = (SpelCriteria) query.prepareQuery(args).getCriteria();
|
||||
SpelCriteria second = (SpelCriteria) query.prepareQuery(args).getCriteria();
|
||||
|
||||
assertThat(first.getExpression(), sameInstance(second.getExpression()));
|
||||
assertThat(first.getContext(), not(sameInstance(second.getContext())));
|
||||
assertThat(first.getExpression()).isSameAs(second.getExpression());
|
||||
assertThat(first.getContext()).isNotSameAs(second.getContext());
|
||||
}
|
||||
|
||||
static interface Repo {
|
||||
|
||||
@@ -15,19 +15,18 @@
|
||||
*/
|
||||
package org.springframework.data.keyvalue.repository.query;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
import org.hamcrest.core.IsInstanceOf;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.keyvalue.Person;
|
||||
@@ -67,7 +66,7 @@ public class KeyValuePartTreeQueryUnitTests {
|
||||
Object first = query.prepareQuery(args).getCriteria();
|
||||
Object second = query.prepareQuery(args).getCriteria();
|
||||
|
||||
assertThat(first, not(sameInstance(second)));
|
||||
assertThat(first).isNotSameAs(second);
|
||||
}
|
||||
|
||||
@Test // DATAKV-142
|
||||
@@ -85,8 +84,8 @@ public class KeyValuePartTreeQueryUnitTests {
|
||||
|
||||
KeyValueQuery<?> query = partTreeQuery.prepareQuery(new Object[] { PageRequest.of(2, 3) });
|
||||
|
||||
assertThat(query.getOffset(), is(6L));
|
||||
assertThat(query.getRows(), is(3));
|
||||
assertThat(query.getOffset()).isEqualTo(6L);
|
||||
assertThat(query.getRows()).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test // DATAKV-142
|
||||
@@ -103,7 +102,7 @@ public class KeyValuePartTreeQueryUnitTests {
|
||||
|
||||
KeyValueQuery<?> query = partTreeQuery.prepareQuery(new Object[] {});
|
||||
|
||||
assertThat(query.getRows(), is(3));
|
||||
assertThat(query.getRows()).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test // DATAKV-142
|
||||
@@ -121,11 +120,10 @@ public class KeyValuePartTreeQueryUnitTests {
|
||||
|
||||
KeyValueQuery<?> query = partTreeQuery.prepareQuery(new Object[] { "firstname" });
|
||||
|
||||
assertThat(query.getCriteria(), is(notNullValue()));
|
||||
assertThat(query.getCriteria(), IsInstanceOf.instanceOf(SpelCriteria.class));
|
||||
assertThat(((SpelCriteria) query.getCriteria()).getExpression().getExpressionString(),
|
||||
is("#it?.firstname?.equals([0])"));
|
||||
assertThat(query.getRows(), is(3));
|
||||
assertThat(query.getCriteria()).isInstanceOf(SpelCriteria.class);
|
||||
assertThat(((SpelCriteria) query.getCriteria()).getExpression().getExpressionString())
|
||||
.isEqualTo("#it?.firstname?.equals([0])");
|
||||
assertThat(query.getRows()).isEqualTo(3);
|
||||
}
|
||||
|
||||
interface Repo {
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
*/
|
||||
package org.springframework.data.keyvalue.repository.query;
|
||||
|
||||
import static org.hamcrest.core.Is.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
@@ -31,6 +31,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.keyvalue.core.query.KeyValueQuery;
|
||||
@@ -65,258 +66,260 @@ public class SpelQueryCreatorUnitTests {
|
||||
@Mock RepositoryMetadata metadataMock;
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void equalsReturnsTrueWhenMatching() throws Exception {
|
||||
assertThat(evaluate("findByFirstname", BRAN.firstname).against(BRAN), is(true));
|
||||
public void equalsReturnsTrueWhenMatching() {
|
||||
assertThat(evaluate("findByFirstname", BRAN.firstname).against(BRAN)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void equalsReturnsFalseWhenNotMatching() throws Exception {
|
||||
assertThat(evaluate("findByFirstname", BRAN.firstname).against(RICKON), is(false));
|
||||
public void equalsReturnsFalseWhenNotMatching() {
|
||||
assertThat(evaluate("findByFirstname", BRAN.firstname).against(RICKON)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void isTrueAssertedProperlyWhenTrue() throws Exception {
|
||||
assertThat(evaluate("findBySkinChangerIsTrue").against(BRAN), is(true));
|
||||
public void isTrueAssertedProperlyWhenTrue() {
|
||||
assertThat(evaluate("findBySkinChangerIsTrue").against(BRAN)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void isTrueAssertedProperlyWhenFalse() throws Exception {
|
||||
assertThat(evaluate("findBySkinChangerIsTrue").against(RICKON), is(false));
|
||||
public void isTrueAssertedProperlyWhenFalse() {
|
||||
assertThat(evaluate("findBySkinChangerIsTrue").against(RICKON)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void isFalseAssertedProperlyWhenTrue() throws Exception {
|
||||
assertThat(evaluate("findBySkinChangerIsFalse").against(BRAN), is(false));
|
||||
public void isFalseAssertedProperlyWhenTrue() {
|
||||
assertThat(evaluate("findBySkinChangerIsFalse").against(BRAN)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void isFalseAssertedProperlyWhenFalse() throws Exception {
|
||||
assertThat(evaluate("findBySkinChangerIsFalse").against(RICKON), is(true));
|
||||
public void isFalseAssertedProperlyWhenFalse() {
|
||||
assertThat(evaluate("findBySkinChangerIsFalse").against(RICKON)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void isNullAssertedProperlyWhenAttributeIsNull() throws Exception {
|
||||
assertThat(evaluate("findByLastnameIsNull").against(BRAN), is(true));
|
||||
public void isNullAssertedProperlyWhenAttributeIsNull() {
|
||||
assertThat(evaluate("findByLastnameIsNull").against(BRAN)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void isNullAssertedProperlyWhenAttributeIsNotNull() throws Exception {
|
||||
assertThat(evaluate("findByLastnameIsNull").against(ROBB), is(false));
|
||||
public void isNullAssertedProperlyWhenAttributeIsNotNull() {
|
||||
assertThat(evaluate("findByLastnameIsNull").against(ROBB)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void isNotNullFalseTrueWhenAttributeIsNull() throws Exception {
|
||||
assertThat(evaluate("findByLastnameIsNotNull").against(BRAN), is(false));
|
||||
public void isNotNullFalseTrueWhenAttributeIsNull() {
|
||||
assertThat(evaluate("findByLastnameIsNotNull").against(BRAN)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void isNotNullReturnsTrueAttributeIsNotNull() throws Exception {
|
||||
assertThat(evaluate("findByLastnameIsNotNull").against(ROBB), is(true));
|
||||
public void isNotNullReturnsTrueAttributeIsNotNull() {
|
||||
assertThat(evaluate("findByLastnameIsNotNull").against(ROBB)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void startsWithReturnsTrueWhenMatching() throws Exception {
|
||||
assertThat(evaluate("findByFirstnameStartingWith", "r").against(ROBB), is(true));
|
||||
public void startsWithReturnsTrueWhenMatching() {
|
||||
assertThat(evaluate("findByFirstnameStartingWith", "r").against(ROBB)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void startsWithReturnsFalseWhenNotMatching() throws Exception {
|
||||
assertThat(evaluate("findByFirstnameStartingWith", "r").against(BRAN), is(false));
|
||||
public void startsWithReturnsFalseWhenNotMatching() {
|
||||
assertThat(evaluate("findByFirstnameStartingWith", "r").against(BRAN)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void likeReturnsTrueWhenMatching() throws Exception {
|
||||
assertThat(evaluate("findByFirstnameLike", "ob").against(ROBB), is(true));
|
||||
public void likeReturnsTrueWhenMatching() {
|
||||
assertThat(evaluate("findByFirstnameLike", "ob").against(ROBB)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void likeReturnsFalseWhenNotMatching() throws Exception {
|
||||
assertThat(evaluate("findByFirstnameLike", "ra").against(ROBB), is(false));
|
||||
public void likeReturnsFalseWhenNotMatching() {
|
||||
assertThat(evaluate("findByFirstnameLike", "ra").against(ROBB)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void endsWithReturnsTrueWhenMatching() throws Exception {
|
||||
assertThat(evaluate("findByFirstnameEndingWith", "bb").against(ROBB), is(true));
|
||||
public void endsWithReturnsTrueWhenMatching() {
|
||||
assertThat(evaluate("findByFirstnameEndingWith", "bb").against(ROBB)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void endsWithReturnsFalseWhenNotMatching() throws Exception {
|
||||
assertThat(evaluate("findByFirstnameEndingWith", "an").against(ROBB), is(false));
|
||||
}
|
||||
|
||||
@Test(expected = InvalidDataAccessApiUsageException.class) // DATACMNS-525
|
||||
public void startsWithIgnoreCaseReturnsTrueWhenMatching() throws Exception {
|
||||
assertThat(evaluate("findByFirstnameIgnoreCase", "R").against(ROBB), is(true));
|
||||
public void endsWithReturnsFalseWhenNotMatching() {
|
||||
assertThat(evaluate("findByFirstnameEndingWith", "an").against(ROBB)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void greaterThanReturnsTrueForHigherValues() throws Exception {
|
||||
assertThat(evaluate("findByAgeGreaterThan", BRAN.age).against(ROBB), is(true));
|
||||
public void startsWithIgnoreCaseReturnsTrueWhenMatching() {
|
||||
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
|
||||
.isThrownBy(() -> evaluate("findByFirstnameIgnoreCase", "R").against(ROBB));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void greaterThanReturnsFalseForLowerValues() throws Exception {
|
||||
assertThat(evaluate("findByAgeGreaterThan", BRAN.age).against(RICKON), is(false));
|
||||
public void greaterThanReturnsTrueForHigherValues() {
|
||||
assertThat(evaluate("findByAgeGreaterThan", BRAN.age).against(ROBB)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void afterReturnsTrueForHigherValues() throws Exception {
|
||||
assertThat(evaluate("findByBirthdayAfter", ROBB.birthday).against(BRAN), is(true));
|
||||
public void greaterThanReturnsFalseForLowerValues() {
|
||||
assertThat(evaluate("findByAgeGreaterThan", BRAN.age).against(RICKON)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void afterReturnsFalseForLowerValues() throws Exception {
|
||||
assertThat(evaluate("findByBirthdayAfter", BRAN.birthday).against(ROBB), is(false));
|
||||
public void afterReturnsTrueForHigherValues() {
|
||||
assertThat(evaluate("findByBirthdayAfter", ROBB.birthday).against(BRAN)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void greaterThanEaualsReturnsTrueForHigherValues() throws Exception {
|
||||
assertThat(evaluate("findByAgeGreaterThanEqual", BRAN.age).against(ROBB), is(true));
|
||||
public void afterReturnsFalseForLowerValues() {
|
||||
assertThat(evaluate("findByBirthdayAfter", BRAN.birthday).against(ROBB)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void greaterThanEqualsReturnsTrueForEqualValues() throws Exception {
|
||||
assertThat(evaluate("findByAgeGreaterThanEqual", BRAN.age).against(BRAN), is(true));
|
||||
public void greaterThanEaualsReturnsTrueForHigherValues() {
|
||||
assertThat(evaluate("findByAgeGreaterThanEqual", BRAN.age).against(ROBB)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void greaterThanEqualsReturnsFalseForLowerValues() throws Exception {
|
||||
assertThat(evaluate("findByAgeGreaterThanEqual", BRAN.age).against(RICKON), is(false));
|
||||
public void greaterThanEqualsReturnsTrueForEqualValues() {
|
||||
assertThat(evaluate("findByAgeGreaterThanEqual", BRAN.age).against(BRAN)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void lessThanReturnsTrueForHigherValues() throws Exception {
|
||||
assertThat(evaluate("findByAgeLessThan", BRAN.age).against(ROBB), is(false));
|
||||
public void greaterThanEqualsReturnsFalseForLowerValues() {
|
||||
assertThat(evaluate("findByAgeGreaterThanEqual", BRAN.age).against(RICKON)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void lessThanReturnsFalseForLowerValues() throws Exception {
|
||||
assertThat(evaluate("findByAgeLessThan", BRAN.age).against(RICKON), is(true));
|
||||
public void lessThanReturnsTrueForHigherValues() {
|
||||
assertThat(evaluate("findByAgeLessThan", BRAN.age).against(ROBB)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void beforeReturnsTrueForLowerValues() throws Exception {
|
||||
assertThat(evaluate("findByBirthdayBefore", BRAN.birthday).against(ROBB), is(true));
|
||||
public void lessThanReturnsFalseForLowerValues() {
|
||||
assertThat(evaluate("findByAgeLessThan", BRAN.age).against(RICKON)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void beforeReturnsFalseForHigherValues() throws Exception {
|
||||
assertThat(evaluate("findByBirthdayBefore", ROBB.birthday).against(BRAN), is(false));
|
||||
public void beforeReturnsTrueForLowerValues() {
|
||||
assertThat(evaluate("findByBirthdayBefore", BRAN.birthday).against(ROBB)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void lessThanEaualsReturnsTrueForHigherValues() throws Exception {
|
||||
assertThat(evaluate("findByAgeLessThanEqual", BRAN.age).against(ROBB), is(false));
|
||||
public void beforeReturnsFalseForHigherValues() {
|
||||
assertThat(evaluate("findByBirthdayBefore", ROBB.birthday).against(BRAN)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void lessThanEaualsReturnsTrueForEqualValues() throws Exception {
|
||||
assertThat(evaluate("findByAgeLessThanEqual", BRAN.age).against(BRAN), is(true));
|
||||
public void lessThanEaualsReturnsTrueForHigherValues() {
|
||||
assertThat(evaluate("findByAgeLessThanEqual", BRAN.age).against(ROBB)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void lessThanEqualsReturnsFalseForLowerValues() throws Exception {
|
||||
assertThat(evaluate("findByAgeLessThanEqual", BRAN.age).against(RICKON), is(true));
|
||||
public void lessThanEaualsReturnsTrueForEqualValues() {
|
||||
assertThat(evaluate("findByAgeLessThanEqual", BRAN.age).against(BRAN)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void betweenEqualsReturnsTrueForValuesInBetween() throws Exception {
|
||||
assertThat(evaluate("findByAgeBetween", BRAN.age, ROBB.age).against(ARYA), is(true));
|
||||
public void lessThanEqualsReturnsFalseForLowerValues() {
|
||||
assertThat(evaluate("findByAgeLessThanEqual", BRAN.age).against(RICKON)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void betweenEqualsReturnsFalseForHigherValues() throws Exception {
|
||||
assertThat(evaluate("findByAgeBetween", BRAN.age, ROBB.age).against(JON), is(false));
|
||||
public void betweenEqualsReturnsTrueForValuesInBetween() {
|
||||
assertThat(evaluate("findByAgeBetween", BRAN.age, ROBB.age).against(ARYA)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void betweenEqualsReturnsFalseForLowerValues() throws Exception {
|
||||
assertThat(evaluate("findByAgeBetween", BRAN.age, ROBB.age).against(RICKON), is(false));
|
||||
public void betweenEqualsReturnsFalseForHigherValues() {
|
||||
assertThat(evaluate("findByAgeBetween", BRAN.age, ROBB.age).against(JON)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void connectByAndReturnsTrueWhenAllPropertiesMatching() throws Exception {
|
||||
assertThat(evaluate("findByAgeGreaterThanAndLastname", BRAN.age, JON.lastname).against(JON), is(true));
|
||||
public void betweenEqualsReturnsFalseForLowerValues() {
|
||||
assertThat(evaluate("findByAgeBetween", BRAN.age, ROBB.age).against(RICKON)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void connectByAndReturnsFalseWhenOnlyFewPropertiesMatch() throws Exception {
|
||||
assertThat(evaluate("findByAgeGreaterThanAndLastname", BRAN.age, JON.lastname).against(ROBB), is(false));
|
||||
public void connectByAndReturnsTrueWhenAllPropertiesMatching() {
|
||||
assertThat(evaluate("findByAgeGreaterThanAndLastname", BRAN.age, JON.lastname).against(JON)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void connectByOrReturnsTrueWhenOnlyFewPropertiesMatch() throws Exception {
|
||||
assertThat(evaluate("findByAgeGreaterThanOrLastname", BRAN.age, JON.lastname).against(ROBB), is(true));
|
||||
public void connectByAndReturnsFalseWhenOnlyFewPropertiesMatch() {
|
||||
assertThat(evaluate("findByAgeGreaterThanAndLastname", BRAN.age, JON.lastname).against(ROBB)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void connectByOrReturnsTrueWhenAllPropertiesMatch() throws Exception {
|
||||
assertThat(evaluate("findByAgeGreaterThanOrLastname", BRAN.age, JON.lastname).against(JON), is(true));
|
||||
public void connectByOrReturnsTrueWhenOnlyFewPropertiesMatch() {
|
||||
assertThat(evaluate("findByAgeGreaterThanOrLastname", BRAN.age, JON.lastname).against(ROBB)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void regexReturnsTrueWhenMatching() throws Exception {
|
||||
assertThat(evaluate("findByLastnameMatches", "^s.*w$").against(JON), is(true));
|
||||
public void connectByOrReturnsTrueWhenAllPropertiesMatch() {
|
||||
assertThat(evaluate("findByAgeGreaterThanOrLastname", BRAN.age, JON.lastname).against(JON)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void regexReturnsFalseWhenNotMatching() throws Exception {
|
||||
assertThat(evaluate("findByLastnameMatches", "^s.*w$").against(ROBB), is(false));
|
||||
public void regexReturnsTrueWhenMatching() {
|
||||
assertThat(evaluate("findByLastnameMatches", "^s.*w$").against(JON)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void regexReturnsFalseWhenNotMatching() {
|
||||
assertThat(evaluate("findByLastnameMatches", "^s.*w$").against(ROBB)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATAKV-169
|
||||
public void inReturnsMatchCorrectly() throws Exception {
|
||||
public void inReturnsMatchCorrectly() {
|
||||
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
list.add(ROBB.firstname);
|
||||
|
||||
assertThat(evaluate("findByFirstnameIn", list).against(ROBB), is(true));
|
||||
assertThat(evaluate("findByFirstnameIn", list).against(ROBB)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATAKV-169
|
||||
public void inNotMatchingReturnsCorrectly() throws Exception {
|
||||
public void inNotMatchingReturnsCorrectly() {
|
||||
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
list.add(ROBB.firstname);
|
||||
|
||||
assertThat(evaluate("findByFirstnameIn", list).against(JON), is(false));
|
||||
assertThat(evaluate("findByFirstnameIn", list).against(JON)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATAKV-169
|
||||
public void inWithNullCompareValuesCorrectly() throws Exception {
|
||||
public void inWithNullCompareValuesCorrectly() {
|
||||
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
list.add(null);
|
||||
|
||||
assertThat(evaluate("findByFirstnameIn", list).against(JON), is(false));
|
||||
assertThat(evaluate("findByFirstnameIn", list).against(JON)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATAKV-169
|
||||
public void inWithNullSourceValuesMatchesCorrectly() throws Exception {
|
||||
public void inWithNullSourceValuesMatchesCorrectly() {
|
||||
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
list.add(ROBB.firstname);
|
||||
|
||||
assertThat(evaluate("findByFirstnameIn", list).against(new Person(null, 10)), is(false));
|
||||
assertThat(evaluate("findByFirstnameIn", list).against(new Person(null, 10))).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATAKV-169
|
||||
public void inMatchesNullValuesCorrectly() throws Exception {
|
||||
public void inMatchesNullValuesCorrectly() {
|
||||
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
list.add(null);
|
||||
|
||||
assertThat(evaluate("findByFirstnameIn", list).against(new Person(null, 10)), is(true));
|
||||
assertThat(evaluate("findByFirstnameIn", list).against(new Person(null, 10))).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATAKV-185
|
||||
public void noDerivedQueryArgumentsMatchesAlways() throws Exception {
|
||||
public void noDerivedQueryArgumentsMatchesAlways() {
|
||||
|
||||
assertThat(evaluate("findBy").against(JON), is(true));
|
||||
assertThat(evaluate("findBy").against(null), is(true));
|
||||
assertThat(evaluate("findBy").against(JON)).isTrue();
|
||||
assertThat(evaluate("findBy").against(null)).isTrue();
|
||||
}
|
||||
|
||||
private Evaluation evaluate(String methodName, Object... args) throws Exception {
|
||||
@SneakyThrows
|
||||
private Evaluation evaluate(String methodName, Object... args) {
|
||||
return new Evaluation(createQueryForMethodWithArgs(methodName, args).getCriteria());
|
||||
}
|
||||
|
||||
|
||||
@@ -15,11 +15,9 @@
|
||||
*/
|
||||
package org.springframework.data.keyvalue.repository.support;
|
||||
|
||||
import static org.hamcrest.collection.IsArrayWithSize.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.keyvalue.repository.support.KeyValueQuerydslUtils.*;
|
||||
|
||||
import org.hamcrest.collection.IsArrayContainingInOrder;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.domain.Sort;
|
||||
@@ -53,14 +51,14 @@ public class KeyValueQuerydslUtilsUnitTests {
|
||||
this.builder = new PathBuilder<>(path.getType(), path.getMetadata());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-525
|
||||
@Test // DATACMNS-525
|
||||
public void toOrderSpecifierThrowsExceptioOnNullPathBuilder() {
|
||||
toOrderSpecifier(Sort.by("firstname"), null);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> toOrderSpecifier(Sort.by("firstname"), null));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525, DATAKV-197
|
||||
public void toOrderSpecifierReturnsEmptyArrayWhenSortIsUnsorted() {
|
||||
assertThat(toOrderSpecifier(Sort.unsorted(), builder), arrayWithSize(0));
|
||||
assertThat(toOrderSpecifier(Sort.unsorted(), builder)).hasSize(0);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@@ -70,8 +68,7 @@ public class KeyValueQuerydslUtilsUnitTests {
|
||||
|
||||
OrderSpecifier<?>[] specifiers = toOrderSpecifier(sort, builder);
|
||||
|
||||
assertThat(specifiers,
|
||||
IsArrayContainingInOrder.arrayContaining(QPerson.person.firstname.asc()));
|
||||
assertThat(specifiers).containsExactly(QPerson.person.firstname.asc());
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@@ -81,8 +78,7 @@ public class KeyValueQuerydslUtilsUnitTests {
|
||||
|
||||
OrderSpecifier<?>[] specifiers = toOrderSpecifier(sort, builder);
|
||||
|
||||
assertThat(specifiers,
|
||||
IsArrayContainingInOrder.arrayContaining(QPerson.person.firstname.desc()));
|
||||
assertThat(specifiers).containsExactly(QPerson.person.firstname.desc());
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@@ -92,8 +88,7 @@ public class KeyValueQuerydslUtilsUnitTests {
|
||||
|
||||
OrderSpecifier<?>[] specifiers = toOrderSpecifier(sort, builder);
|
||||
|
||||
assertThat(specifiers, IsArrayContainingInOrder.arrayContaining(QPerson.person.firstname.desc(),
|
||||
QPerson.person.age.asc()));
|
||||
assertThat(specifiers).containsExactly(QPerson.person.firstname.desc(), QPerson.person.age.asc());
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@@ -103,7 +98,6 @@ public class KeyValueQuerydslUtilsUnitTests {
|
||||
|
||||
OrderSpecifier<?>[] specifiers = toOrderSpecifier(sort, builder);
|
||||
|
||||
assertThat(specifiers,
|
||||
IsArrayContainingInOrder.arrayContaining(QPerson.person.firstname.desc().nullsLast()));
|
||||
assertThat(specifiers).containsExactly(QPerson.person.firstname.desc().nullsLast());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,14 +15,12 @@
|
||||
*/
|
||||
package org.springframework.data.keyvalue.repository.support;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.data.keyvalue.core.KeyValueOperations;
|
||||
import org.springframework.data.keyvalue.repository.query.KeyValuePartTreeQuery;
|
||||
import org.springframework.data.repository.Repository;
|
||||
@@ -37,8 +35,6 @@ import org.springframework.data.repository.query.parser.AbstractQueryCreator;
|
||||
*/
|
||||
public class KeyValueRepositoryFactoryBeanUnitTests {
|
||||
|
||||
public @Rule ExpectedException exception = ExpectedException.none();
|
||||
|
||||
KeyValueRepositoryFactoryBean<?, ?, ?> factoryBean;
|
||||
|
||||
@Before
|
||||
@@ -47,37 +43,38 @@ public class KeyValueRepositoryFactoryBeanUnitTests {
|
||||
SampleRepository.class);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATAKV-123
|
||||
@Test // DATAKV-123
|
||||
public void rejectsNullKeyValueOperations() {
|
||||
factoryBean.setKeyValueOperations(null);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> factoryBean.setKeyValueOperations(null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATAKV-123
|
||||
@Test // DATAKV-123
|
||||
public void rejectsNullQueryCreator() {
|
||||
factoryBean.setQueryCreator(null);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> factoryBean.setQueryCreator(null));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATAKV-123
|
||||
@Test // DATAKV-123
|
||||
public void rejectsUninitializedInstance() {
|
||||
factoryBean.afterPropertiesSet();
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> factoryBean.afterPropertiesSet());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test(expected = IllegalArgumentException.class) // DATAKV-123
|
||||
@Test // DATAKV-123
|
||||
public void rejectsInstanceWithoutKeyValueOperations() {
|
||||
|
||||
Class<? extends AbstractQueryCreator<?, ?>> creatorType = (Class<? extends AbstractQueryCreator<?, ?>>) mock(
|
||||
AbstractQueryCreator.class).getClass();
|
||||
|
||||
factoryBean.setQueryCreator(creatorType);
|
||||
factoryBean.afterPropertiesSet();
|
||||
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> factoryBean.afterPropertiesSet());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATAKV-123
|
||||
@Test // DATAKV-123
|
||||
public void rejectsInstanceWithoutQueryCreator() {
|
||||
|
||||
factoryBean.setKeyValueOperations(mock(KeyValueOperations.class));
|
||||
factoryBean.afterPropertiesSet();
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> factoryBean.afterPropertiesSet());
|
||||
}
|
||||
|
||||
@Test // DATAKV-123
|
||||
@@ -92,12 +89,12 @@ public class KeyValueRepositoryFactoryBeanUnitTests {
|
||||
factoryBean.setKeyValueOperations(mock(KeyValueOperations.class));
|
||||
factoryBean.setQueryType(queryType);
|
||||
|
||||
assertThat(factoryBean.createRepositoryFactory(), is(notNullValue()));
|
||||
assertThat(factoryBean.createRepositoryFactory()).isNotNull();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATAKV-112
|
||||
@Test // DATAKV-112
|
||||
public void rejectsNullQueryType() {
|
||||
factoryBean.setQueryType(null);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> factoryBean.setQueryType(null));
|
||||
}
|
||||
|
||||
interface SampleRepository extends Repository<Object, Object> {}
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.keyvalue.test.util;
|
||||
|
||||
import java.util.AbstractMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hamcrest.CustomMatcher;
|
||||
import org.hamcrest.core.IsEqual;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
* @author Thomas Darimont
|
||||
*/
|
||||
public class IsEntry extends CustomMatcher<Map.Entry<?, ?>> {
|
||||
|
||||
private final Map.Entry<?, ?> expected;
|
||||
|
||||
private IsEntry(Map.Entry<?, ?> entry) {
|
||||
super(String.format("an entry %s=%s.", entry != null ? entry.getKey() : "null", entry != null ? entry.getValue()
|
||||
: "null"));
|
||||
this.expected = entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Object item) {
|
||||
|
||||
if (item == null && expected == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(item instanceof Map.Entry)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Map.Entry<?, ?> actual = (Map.Entry<?, ?>) item;
|
||||
|
||||
return new IsEqual<Object>(expected.getKey()).matches(actual.getKey())
|
||||
&& new IsEqual<Object>(expected.getValue()).matches(actual.getValue());
|
||||
}
|
||||
|
||||
public static IsEntry isEntry(Object key, Object value) {
|
||||
return isEntry(new EntryImpl(key, value));
|
||||
}
|
||||
|
||||
public static IsEntry isEntry(Map.Entry<?, ?> entry) {
|
||||
return new IsEntry(entry);
|
||||
}
|
||||
|
||||
private static class EntryImpl extends AbstractMap.SimpleEntry<Object, Object> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private EntryImpl(Object key, Object value) {
|
||||
super(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object setValue(Object value) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,15 +15,14 @@
|
||||
*/
|
||||
package org.springframework.data.map;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.hamcrest.collection.IsCollectionWithSize;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
@@ -71,7 +70,7 @@ public abstract class AbstractRepositoryUnitTests<T extends AbstractRepositoryUn
|
||||
|
||||
repository.saveAll(LENNISTERS);
|
||||
|
||||
assertThat(repository.findByAge(19), hasItems(CERSEI, JAIME));
|
||||
assertThat(repository.findByAge(19)).contains(CERSEI, JAIME);
|
||||
}
|
||||
|
||||
@Test // DATAKV-137
|
||||
@@ -79,8 +78,8 @@ public abstract class AbstractRepositoryUnitTests<T extends AbstractRepositoryUn
|
||||
|
||||
repository.saveAll(LENNISTERS);
|
||||
|
||||
assertThat(repository.findByFirstname(CERSEI.getFirstname()), hasItems(CERSEI));
|
||||
assertThat(repository.findByFirstname(JAIME.getFirstname()), hasItems(JAIME));
|
||||
assertThat(repository.findByFirstname(CERSEI.getFirstname())).contains(CERSEI);
|
||||
assertThat(repository.findByFirstname(JAIME.getFirstname())).contains(JAIME);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525, DATAKV-137
|
||||
@@ -88,8 +87,8 @@ public abstract class AbstractRepositoryUnitTests<T extends AbstractRepositoryUn
|
||||
|
||||
repository.saveAll(LENNISTERS);
|
||||
|
||||
assertThat(repository.findByFirstnameAndAge(JAIME.getFirstname(), 19), hasItem(JAIME));
|
||||
assertThat(repository.findByFirstnameAndAge(TYRION.getFirstname(), 17), hasItem(TYRION));
|
||||
assertThat(repository.findByFirstnameAndAge(JAIME.getFirstname(), 19)).contains(JAIME);
|
||||
assertThat(repository.findByFirstnameAndAge(TYRION.getFirstname(), 17)).contains(TYRION);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@@ -98,14 +97,14 @@ public abstract class AbstractRepositoryUnitTests<T extends AbstractRepositoryUn
|
||||
repository.saveAll(LENNISTERS);
|
||||
|
||||
Page<Person> page = repository.findByAge(19, PageRequest.of(0, 1));
|
||||
assertThat(page.hasNext(), is(true));
|
||||
assertThat(page.getTotalElements(), is(2L));
|
||||
assertThat(page.getContent(), IsCollectionWithSize.hasSize(1));
|
||||
assertThat(page.hasNext()).isTrue();
|
||||
assertThat(page.getTotalElements()).isEqualTo(2L);
|
||||
assertThat(page.getContent()).hasSize(1);
|
||||
|
||||
Page<Person> next = repository.findByAge(19, page.nextPageable());
|
||||
assertThat(next.hasNext(), is(false));
|
||||
assertThat(next.getTotalElements(), is(2L));
|
||||
assertThat(next.getContent(), IsCollectionWithSize.hasSize(1));
|
||||
assertThat(next.hasNext()).isFalse();
|
||||
assertThat(next.getTotalElements()).isEqualTo(2L);
|
||||
assertThat(next.getContent()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@@ -113,7 +112,7 @@ public abstract class AbstractRepositoryUnitTests<T extends AbstractRepositoryUn
|
||||
|
||||
repository.saveAll(LENNISTERS);
|
||||
|
||||
assertThat(repository.findByAgeOrFirstname(19, TYRION.getFirstname()), hasItems(CERSEI, JAIME, TYRION));
|
||||
assertThat(repository.findByAgeOrFirstname(19, TYRION.getFirstname())).contains(CERSEI, JAIME, TYRION);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525, DATAKV-137
|
||||
@@ -121,8 +120,8 @@ public abstract class AbstractRepositoryUnitTests<T extends AbstractRepositoryUn
|
||||
|
||||
repository.saveAll(LENNISTERS);
|
||||
|
||||
assertThat(repository.findByAgeAndFirstname(TYRION.getAge(), TYRION.getFirstname()), is(TYRION));
|
||||
assertThat(repository.findByAgeAndFirstname(CERSEI.getAge(), CERSEI.getFirstname()), is(CERSEI));
|
||||
assertThat(repository.findByAgeAndFirstname(TYRION.getAge(), TYRION.getFirstname())).isEqualTo(TYRION);
|
||||
assertThat(repository.findByAgeAndFirstname(CERSEI.getAge(), CERSEI.getFirstname())).isEqualTo(CERSEI);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@@ -131,8 +130,8 @@ public abstract class AbstractRepositoryUnitTests<T extends AbstractRepositoryUn
|
||||
repository.saveAll(LENNISTERS);
|
||||
|
||||
assertThat(
|
||||
repository.findAll(Sort.by(new Sort.Order(Direction.ASC, "age"), new Sort.Order(Direction.DESC, "firstname"))),
|
||||
contains(TYRION, JAIME, CERSEI));
|
||||
repository.findAll(Sort.by(new Sort.Order(Direction.ASC, "age"), new Sort.Order(Direction.DESC, "firstname"))))
|
||||
.containsExactly(TYRION, JAIME, CERSEI);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@@ -142,7 +141,7 @@ public abstract class AbstractRepositoryUnitTests<T extends AbstractRepositoryUn
|
||||
|
||||
List<Person> result = repository.findByAgeGreaterThanOrderByAgeAscFirstnameDesc(2);
|
||||
|
||||
assertThat(result, contains(TYRION, JAIME, CERSEI));
|
||||
assertThat(result).containsExactly(TYRION, JAIME, CERSEI);
|
||||
}
|
||||
|
||||
@Test // DATAKV-121
|
||||
@@ -152,8 +151,8 @@ public abstract class AbstractRepositoryUnitTests<T extends AbstractRepositoryUn
|
||||
|
||||
List<PersonSummary> result = repository.findByAgeGreaterThan(0, Sort.by("firstname"));
|
||||
|
||||
assertThat(result, hasSize(3));
|
||||
assertThat(result.get(0).getFirstname(), is(CERSEI.getFirstname()));
|
||||
assertThat(result).hasSize(3);
|
||||
assertThat(result.get(0).getFirstname()).isEqualTo(CERSEI.getFirstname());
|
||||
}
|
||||
|
||||
@Test // DATAKV-121
|
||||
@@ -163,8 +162,8 @@ public abstract class AbstractRepositoryUnitTests<T extends AbstractRepositoryUn
|
||||
|
||||
List<PersonSummary> result = repository.findByAgeGreaterThan(0, Sort.by("firstname"), PersonSummary.class);
|
||||
|
||||
assertThat(result, hasSize(3));
|
||||
assertThat(result.get(0).getFirstname(), is(CERSEI.getFirstname()));
|
||||
assertThat(result).hasSize(3);
|
||||
assertThat(result.get(0).getFirstname()).isEqualTo(CERSEI.getFirstname());
|
||||
}
|
||||
|
||||
@Test // DATAKV-169
|
||||
@@ -174,8 +173,8 @@ public abstract class AbstractRepositoryUnitTests<T extends AbstractRepositoryUn
|
||||
|
||||
List<Person> result = repository.findByFirstnameIn(Arrays.asList(CERSEI.getFirstname(), JAIME.getFirstname()));
|
||||
|
||||
assertThat(result, hasSize(2));
|
||||
assertThat(result, is(containsInAnyOrder(CERSEI, JAIME)));
|
||||
assertThat(result).hasSize(2);
|
||||
assertThat(result).contains(CERSEI, JAIME);
|
||||
}
|
||||
|
||||
@Test // DATAKV-169
|
||||
@@ -186,8 +185,8 @@ public abstract class AbstractRepositoryUnitTests<T extends AbstractRepositoryUn
|
||||
|
||||
List<Person> result = repository.findByFirstnameIn(Arrays.asList(CERSEI.getFirstname(), JAIME.getFirstname()));
|
||||
|
||||
assertThat(result, hasSize(2));
|
||||
assertThat(result, is(containsInAnyOrder(CERSEI, JAIME)));
|
||||
assertThat(result).hasSize(2);
|
||||
assertThat(result).contains(CERSEI, JAIME);
|
||||
}
|
||||
|
||||
@Test // DATAKV-169
|
||||
@@ -201,8 +200,8 @@ public abstract class AbstractRepositoryUnitTests<T extends AbstractRepositoryUn
|
||||
List<Person> result = repository
|
||||
.findByFirstnameIn(Arrays.asList(CERSEI.getFirstname(), JAIME.getFirstname(), null));
|
||||
|
||||
assertThat(result, hasSize(3));
|
||||
assertThat(result, is(containsInAnyOrder(CERSEI, JAIME, personWithNullAsFirstname)));
|
||||
assertThat(result).hasSize(3);
|
||||
assertThat(result).contains(CERSEI, JAIME, personWithNullAsFirstname);
|
||||
}
|
||||
|
||||
protected KeyValueRepositoryFactory createKeyValueRepositoryFactory(KeyValueOperations operations) {
|
||||
|
||||
@@ -15,19 +15,16 @@
|
||||
*/
|
||||
package org.springframework.data.map;
|
||||
|
||||
import static org.hamcrest.collection.IsIterableContainingInAnyOrder.*;
|
||||
import static org.hamcrest.core.Is.*;
|
||||
import static org.hamcrest.core.IsEqual.*;
|
||||
import static org.hamcrest.core.IsNull.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.data.keyvalue.test.util.IsEntry.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.AbstractMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.data.util.CloseableIterator;
|
||||
|
||||
/**
|
||||
@@ -49,70 +46,70 @@ public class MapKeyValueAdapterUnitTests {
|
||||
this.adapter = new MapKeyValueAdapter();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-525
|
||||
@Test // DATACMNS-525
|
||||
public void putShouldThrowExceptionWhenAddingNullId() {
|
||||
adapter.put(null, object1, COLLECTION_1);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> adapter.put(null, object1, COLLECTION_1));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-525
|
||||
@Test // DATACMNS-525
|
||||
public void putShouldThrowExceptionWhenCollectionIsNullValue() {
|
||||
adapter.put("1", object1, null);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> adapter.put("1", object1, null));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void putReturnsNullWhenNoObjectForIdPresent() {
|
||||
assertThat(adapter.put("1", object1, COLLECTION_1), nullValue());
|
||||
assertThat(adapter.put("1", object1, COLLECTION_1)).isNull();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void putShouldReturnPreviousObjectForIdWhenAddingNewOneWithSameIdPresent() {
|
||||
|
||||
adapter.put("1", object1, COLLECTION_1);
|
||||
assertThat(adapter.put("1", object2, COLLECTION_1), equalTo(object1));
|
||||
assertThat(adapter.put("1", object2, COLLECTION_1)).isEqualTo(object1);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-525
|
||||
@Test // DATACMNS-525
|
||||
public void containsShouldThrowExceptionWhenIdIsNull() {
|
||||
adapter.contains(null, COLLECTION_1);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> adapter.contains(null, COLLECTION_1));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-525
|
||||
@Test // DATACMNS-525
|
||||
public void containsShouldThrowExceptionWhenTypeIsNull() {
|
||||
adapter.contains("", null);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> adapter.contains("", null));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void containsShouldReturnFalseWhenNoElementsPresent() {
|
||||
assertThat(adapter.contains("1", COLLECTION_1), is(false));
|
||||
assertThat(adapter.contains("1", COLLECTION_1)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void containShouldReturnTrueWhenElementWithIdPresent() {
|
||||
|
||||
adapter.put("1", object1, COLLECTION_1);
|
||||
assertThat(adapter.contains("1", COLLECTION_1), is(true));
|
||||
assertThat(adapter.contains("1", COLLECTION_1)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void getShouldReturnNullWhenNoElementWithIdPresent() {
|
||||
assertThat(adapter.get("1", COLLECTION_1), nullValue());
|
||||
assertThat(adapter.get("1", COLLECTION_1)).isNull();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void getShouldReturnElementWhenMatchingIdPresent() {
|
||||
|
||||
adapter.put("1", object1, COLLECTION_1);
|
||||
assertThat(adapter.get("1", COLLECTION_1), is(object1));
|
||||
assertThat(adapter.get("1", COLLECTION_1)).isEqualTo(object1);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-525
|
||||
@Test // DATACMNS-525
|
||||
public void getShouldThrowExceptionWhenIdIsNull() {
|
||||
adapter.get(null, COLLECTION_1);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> adapter.get(null, COLLECTION_1));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-525
|
||||
@Test // DATACMNS-525
|
||||
public void getShouldThrowExceptionWhenTypeIsNull() {
|
||||
adapter.get("1", null);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> adapter.get("1", null));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@@ -122,24 +119,24 @@ public class MapKeyValueAdapterUnitTests {
|
||||
adapter.put("2", object2, COLLECTION_1);
|
||||
adapter.put("3", STRING_1, COLLECTION_2);
|
||||
|
||||
assertThat(adapter.getAllOf(COLLECTION_1), containsInAnyOrder(object1, object2));
|
||||
assertThat((Iterable) adapter.getAllOf(COLLECTION_1)).contains(object1, object2);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-525
|
||||
@Test // DATACMNS-525
|
||||
public void getAllOfShouldThrowExceptionWhenTypeIsNull() {
|
||||
adapter.getAllOf(null);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> adapter.getAllOf(null));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void deleteShouldReturnNullWhenGivenIdThatDoesNotExist() {
|
||||
assertThat(adapter.delete("1", COLLECTION_1), nullValue());
|
||||
assertThat(adapter.delete("1", COLLECTION_1)).isNull();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void deleteShouldReturnDeletedObject() {
|
||||
|
||||
adapter.put("1", object1, COLLECTION_1);
|
||||
assertThat(adapter.delete("1", COLLECTION_1), is(object1));
|
||||
assertThat(adapter.delete("1", COLLECTION_1)).isEqualTo(object1);
|
||||
}
|
||||
|
||||
@Test // DATAKV-99
|
||||
@@ -150,14 +147,14 @@ public class MapKeyValueAdapterUnitTests {
|
||||
|
||||
CloseableIterator<Map.Entry<Object, Object>> iterator = adapter.entries(COLLECTION_1);
|
||||
|
||||
assertThat(iterator.next(), isEntry("1", object1));
|
||||
assertThat(iterator.next(), isEntry("2", object2));
|
||||
assertThat(iterator.hasNext(), is(false));
|
||||
assertThat(iterator.next()).isEqualTo(new AbstractMap.SimpleEntry<>("1", object1));
|
||||
assertThat(iterator.next()).isEqualTo(new AbstractMap.SimpleEntry<>("2", object2));
|
||||
assertThat(iterator.hasNext()).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATAKV-99
|
||||
public void scanShouldReturnEmptyIteratorWhenNoElementsAvailable() {
|
||||
assertThat(adapter.entries(COLLECTION_1).hasNext(), is(false));
|
||||
assertThat(adapter.entries(COLLECTION_1).hasNext()).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATAKV-99
|
||||
@@ -168,8 +165,8 @@ public class MapKeyValueAdapterUnitTests {
|
||||
|
||||
CloseableIterator<Map.Entry<Object, Object>> iterator = adapter.entries(COLLECTION_1);
|
||||
|
||||
assertThat(iterator.next(), isEntry("1", object1));
|
||||
assertThat(iterator.hasNext(), is(false));
|
||||
assertThat(iterator.next()).isEqualTo(new AbstractMap.SimpleEntry<>("1", object1));
|
||||
assertThat(iterator.hasNext()).isFalse();
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -16,14 +16,12 @@
|
||||
package org.springframework.data.map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.dao.IncorrectResultSizeDataAccessException;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
@@ -64,7 +62,7 @@ public class QuerydslKeyValueRepositoryUnitTests extends AbstractRepositoryUnitT
|
||||
repository.saveAll(LENNISTERS);
|
||||
|
||||
Iterable<Person> result = repository.findAll(QPerson.person.age.eq(CERSEI.getAge()));
|
||||
assertThat(result, containsInAnyOrder(CERSEI, JAIME));
|
||||
assertThat(result).contains(CERSEI, JAIME);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@@ -73,15 +71,15 @@ public class QuerydslKeyValueRepositoryUnitTests extends AbstractRepositoryUnitT
|
||||
repository.saveAll(LENNISTERS);
|
||||
Page<Person> page1 = repository.findAll(QPerson.person.age.eq(CERSEI.getAge()), PageRequest.of(0, 1));
|
||||
|
||||
assertThat(page1.getTotalElements(), is(2L));
|
||||
assertThat(page1.getContent(), hasSize(1));
|
||||
assertThat(page1.hasNext(), is(true));
|
||||
assertThat(page1.getTotalElements()).isEqualTo(2L);
|
||||
assertThat(page1.getContent()).hasSize(1);
|
||||
assertThat(page1.hasNext()).isTrue();
|
||||
|
||||
Page<Person> page2 = repository.findAll(QPerson.person.age.eq(CERSEI.getAge()), page1.nextPageable());
|
||||
|
||||
assertThat(page2.getTotalElements(), is(2L));
|
||||
assertThat(page2.getContent(), hasSize(1));
|
||||
assertThat(page2.hasNext(), is(false));
|
||||
assertThat(page2.getTotalElements()).isEqualTo(2L);
|
||||
assertThat(page2.getContent()).hasSize(1);
|
||||
assertThat(page2.hasNext()).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@@ -92,7 +90,7 @@ public class QuerydslKeyValueRepositoryUnitTests extends AbstractRepositoryUnitT
|
||||
Iterable<Person> result = repository.findAll(QPerson.person.age.eq(CERSEI.getAge()),
|
||||
QPerson.person.firstname.desc());
|
||||
|
||||
assertThat(result, contains(JAIME, CERSEI));
|
||||
assertThat(result).containsExactly(JAIME, CERSEI);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@@ -103,7 +101,7 @@ public class QuerydslKeyValueRepositoryUnitTests extends AbstractRepositoryUnitT
|
||||
Iterable<Person> result = repository.findAll(QPerson.person.age.eq(CERSEI.getAge()),
|
||||
PageRequest.of(0, 10, Direction.DESC, "firstname"));
|
||||
|
||||
assertThat(result, contains(JAIME, CERSEI));
|
||||
assertThat(result).containsExactly(JAIME, CERSEI);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-525
|
||||
@@ -114,7 +112,7 @@ public class QuerydslKeyValueRepositoryUnitTests extends AbstractRepositoryUnitT
|
||||
Iterable<Person> result = repository.findAll(QPerson.person.age.eq(CERSEI.getAge()),
|
||||
PageRequest.of(0, 10, new QSort(QPerson.person.firstname.desc())));
|
||||
|
||||
assertThat(result, contains(JAIME, CERSEI));
|
||||
assertThat(result).containsExactly(JAIME, CERSEI);
|
||||
}
|
||||
|
||||
@Test // DATAKV-90
|
||||
@@ -124,12 +122,12 @@ public class QuerydslKeyValueRepositoryUnitTests extends AbstractRepositoryUnitT
|
||||
|
||||
Iterable<Person> result = repository.findAll(new QSort(QPerson.person.firstname.desc()));
|
||||
|
||||
assertThat(result, contains(TYRION, JAIME, CERSEI));
|
||||
assertThat(result).containsExactly(TYRION, JAIME, CERSEI);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATAKV-90, DATAKV-197
|
||||
@Test // DATAKV-90, DATAKV-197
|
||||
public void findAllShouldRequireSort() {
|
||||
repository.findAll((QSort) null);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> repository.findAll((QSort) null));
|
||||
}
|
||||
|
||||
@Test // DATAKV-90, DATAKV-197
|
||||
@@ -139,7 +137,7 @@ public class QuerydslKeyValueRepositoryUnitTests extends AbstractRepositoryUnitT
|
||||
|
||||
Iterable<Person> result = repository.findAll(Sort.unsorted());
|
||||
|
||||
assertThat(result, containsInAnyOrder(TYRION, JAIME, CERSEI));
|
||||
assertThat(result).contains(TYRION, JAIME, CERSEI);
|
||||
}
|
||||
|
||||
@Test // DATAKV-95
|
||||
@@ -147,7 +145,7 @@ public class QuerydslKeyValueRepositoryUnitTests extends AbstractRepositoryUnitT
|
||||
|
||||
repository.saveAll(LENNISTERS);
|
||||
|
||||
assertThat(repository.exists(QPerson.person.age.eq(CERSEI.getAge())), is(true));
|
||||
assertThat(repository.exists(QPerson.person.age.eq(CERSEI.getAge()))).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATAKV-96
|
||||
@@ -157,10 +155,10 @@ public class QuerydslKeyValueRepositoryUnitTests extends AbstractRepositoryUnitT
|
||||
|
||||
List<Person> users = Lists.newArrayList(repository.findAll(person.age.gt(0), Sort.by(Direction.ASC, "firstname")));
|
||||
|
||||
assertThat(users, hasSize(3));
|
||||
assertThat(users.get(0).getFirstname(), is(CERSEI.getFirstname()));
|
||||
assertThat(users.get(2).getFirstname(), is(TYRION.getFirstname()));
|
||||
assertThat(users, hasItems(CERSEI, JAIME, TYRION));
|
||||
assertThat(users).hasSize(3);
|
||||
assertThat(users.get(0).getFirstname()).isEqualTo(CERSEI.getFirstname());
|
||||
assertThat(users.get(2).getFirstname()).isEqualTo(TYRION.getFirstname());
|
||||
assertThat(users).contains(CERSEI, JAIME, TYRION);
|
||||
}
|
||||
|
||||
@Test // DATAKV-179
|
||||
|
||||
@@ -15,14 +15,14 @@
|
||||
*/
|
||||
package org.springframework.data.map.repository.config;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentSkipListMap;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
@@ -45,7 +45,7 @@ public class MapRepositoriesConfigurationExtensionIntegrationTests {
|
||||
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
|
||||
|
||||
assertThat(Arrays.asList(context.getBeanDefinitionNames()), hasItem("mapKeyValueTemplate"));
|
||||
assertThat(Arrays.asList(context.getBeanDefinitionNames())).contains("mapKeyValueTemplate");
|
||||
|
||||
context.close();
|
||||
}
|
||||
@@ -56,15 +56,15 @@ public class MapRepositoriesConfigurationExtensionIntegrationTests {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
|
||||
ConfigWithCustomTemplateReference.class);
|
||||
|
||||
assertThat(Arrays.asList(context.getBeanDefinitionNames()), not(hasItem("mapKeyValueTemplate")));
|
||||
assertThat(context.getBeanDefinitionNames()).doesNotContain("mapKeyValueTemplate");
|
||||
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test // DATAKV-87
|
||||
public void considersMapTypeConfiguredOnAnnotation() {
|
||||
assertKeyValueTemplateWithAdapterFor(ConcurrentSkipListMap.class, new AnnotationConfigApplicationContext(
|
||||
ConfigWithCustomizedMapType.class));
|
||||
assertKeyValueTemplateWithAdapterFor(ConcurrentSkipListMap.class,
|
||||
new AnnotationConfigApplicationContext(ConfigWithCustomizedMapType.class));
|
||||
}
|
||||
|
||||
@Test // DATAKV-87
|
||||
@@ -78,8 +78,8 @@ public class MapRepositoriesConfigurationExtensionIntegrationTests {
|
||||
KeyValueTemplate template = context.getBean(KeyValueTemplate.class);
|
||||
Object adapter = ReflectionTestUtils.getField(template, "adapter");
|
||||
|
||||
assertThat(adapter, is(instanceOf(MapKeyValueAdapter.class)));
|
||||
assertThat(ReflectionTestUtils.getField(adapter, "store"), is(instanceOf(mapType)));
|
||||
assertThat(adapter).isInstanceOf(MapKeyValueAdapter.class);
|
||||
assertThat(ReflectionTestUtils.getField(adapter, "store")).isInstanceOf(mapType);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.map.repository.config;
|
||||
|
||||
import static org.hamcrest.core.IsNull.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@@ -24,6 +23,7 @@ import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.annotation.Id;
|
||||
@@ -51,7 +51,7 @@ public class MapRepositoryRegistrarWithFullDefaultingIntegrationTests {
|
||||
|
||||
@Test // DATAKV-86
|
||||
public void shouldEnableMapRepositoryCorrectly() {
|
||||
assertThat(repo, notNullValue());
|
||||
assertThat(repo).isNotNull();
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.map.repository.config;
|
||||
|
||||
import static org.hamcrest.core.IsNull.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@@ -24,6 +23,7 @@ import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -59,7 +59,7 @@ public class MapRepositoryRegistrarWithTemplateDefinitionIntegrationTests {
|
||||
|
||||
@Test // DATACMNS-525
|
||||
public void shouldEnableMapRepositoryCorrectly() {
|
||||
assertThat(repo, notNullValue());
|
||||
assertThat(repo).isNotNull();
|
||||
}
|
||||
|
||||
@Data
|
||||
|
||||
Reference in New Issue
Block a user