DATAKV-192 - Polishing.
Reduce member visibility according type visibility. Adapt to required argument in KeyValueRepository.findAll(Pageable). Replace cast with type to Class.cast(…). Use lombok for for getters/setters in test code. Suppress warnings, formatting. Original pull request: #26.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2015 the original author or authors.
|
||||
* Copyright 2014-2017 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.
|
||||
@@ -15,15 +15,18 @@
|
||||
*/
|
||||
package org.springframework.data.keyvalue;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import com.querydsl.core.annotations.QueryEntity;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@QueryEntity
|
||||
@Data
|
||||
public class Person {
|
||||
|
||||
private @Id String id;
|
||||
@@ -35,68 +38,4 @@ public class Person {
|
||||
this.firstname = firstname;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public String getFirstname() {
|
||||
return firstname;
|
||||
}
|
||||
|
||||
public void setFirstname(String firstname) {
|
||||
this.firstname = firstname;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Person [id=" + id + ", firstname=" + firstname + ", age=" + age + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + age;
|
||||
result = prime * result + ObjectUtils.nullSafeHashCode(this.firstname);
|
||||
result = prime * result + ObjectUtils.nullSafeHashCode(this.id);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof Person)) {
|
||||
return false;
|
||||
}
|
||||
Person other = (Person) obj;
|
||||
if (!ObjectUtils.nullSafeEquals(this.id, other.id)) {
|
||||
return false;
|
||||
}
|
||||
if (!ObjectUtils.nullSafeEquals(this.firstname, other.firstname)) {
|
||||
return false;
|
||||
}
|
||||
if (!ObjectUtils.nullSafeEquals(this.age, other.age)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2017 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.
|
||||
@@ -15,16 +15,19 @@
|
||||
*/
|
||||
package org.springframework.data.keyvalue;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Persistent;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* A {@link Persistent} type with {@link CustomKeySpaceAnnotationWithAliasFor}.
|
||||
*
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@CustomKeySpaceAnnotationWithAliasFor(name = "aliased")
|
||||
@Data
|
||||
public class TypeWithCustomComposedKeySpaceAnnotationUsingAliasFor {
|
||||
|
||||
@Id String id;
|
||||
@@ -33,51 +36,4 @@ public class TypeWithCustomComposedKeySpaceAnnotationUsingAliasFor {
|
||||
public TypeWithCustomComposedKeySpaceAnnotationUsingAliasFor(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ObjectUtils.nullSafeHashCode(this.id);
|
||||
result = prime * result + ObjectUtils.nullSafeHashCode(this.name);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof TypeWithCustomComposedKeySpaceAnnotationUsingAliasFor)) {
|
||||
return false;
|
||||
}
|
||||
TypeWithCustomComposedKeySpaceAnnotationUsingAliasFor other = (TypeWithCustomComposedKeySpaceAnnotationUsingAliasFor) obj;
|
||||
if (!ObjectUtils.nullSafeEquals(this.id, other.id)) {
|
||||
return false;
|
||||
}
|
||||
if (!ObjectUtils.nullSafeEquals(this.name, other.name)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class ForwardingCloseableIteratorUnitTests<K, V> {
|
||||
@Mock Runnable closeActionMock;
|
||||
|
||||
@Test // DATAKV-99
|
||||
public void hasNextShoudDelegateToWrappedIterator() {
|
||||
public void hasNextShouldDelegateToWrappedIterator() {
|
||||
|
||||
when(iteratorMock.hasNext()).thenReturn(true);
|
||||
|
||||
@@ -58,7 +58,7 @@ public class ForwardingCloseableIteratorUnitTests<K, V> {
|
||||
|
||||
@Test // DATAKV-99
|
||||
@SuppressWarnings("unchecked")
|
||||
public void nextShoudDelegateToWrappedIterator() {
|
||||
public void nextShouldDelegateToWrappedIterator() {
|
||||
|
||||
when(iteratorMock.next()).thenReturn((Entry<K, V>) mock(Map.Entry.class));
|
||||
|
||||
@@ -73,7 +73,7 @@ public class ForwardingCloseableIteratorUnitTests<K, V> {
|
||||
}
|
||||
|
||||
@Test(expected = NoSuchElementException.class) // DATAKV-99
|
||||
public void nextShoudThrowErrorWhenWrappedIteratorHasNoMoreElements() {
|
||||
public void nextShouldThrowErrorWhenWrappedIteratorHasNoMoreElements() {
|
||||
|
||||
when(iteratorMock.next()).thenThrow(new NoSuchElementException());
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.data.keyvalue.core;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.Mockito.any;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
@@ -414,7 +415,7 @@ public class KeyValueTemplateUnitTests {
|
||||
|
||||
assertThat(captor.getValue().getKey(), is("1"));
|
||||
assertThat(captor.getValue().getKeyspace(), is(Foo.class.getName()));
|
||||
assertThat(captor.getValue().getPayload(), is((Object) FOO_ONE));
|
||||
assertThat(captor.getValue().getPayload(), is(FOO_ONE));
|
||||
}
|
||||
|
||||
@Test // DATAKV-91, DATAKV-104, DATAKV-187
|
||||
@@ -432,7 +433,7 @@ public class KeyValueTemplateUnitTests {
|
||||
|
||||
assertThat(captor.getValue().getKey(), is("1"));
|
||||
assertThat(captor.getValue().getKeyspace(), is(Foo.class.getName()));
|
||||
assertThat(captor.getValue().getPayload(), is((Object) FOO_ONE));
|
||||
assertThat(captor.getValue().getPayload(), is(FOO_ONE));
|
||||
}
|
||||
|
||||
@Test // DATAKV-91, DATAKV-104, DATAKV-187
|
||||
@@ -450,7 +451,7 @@ public class KeyValueTemplateUnitTests {
|
||||
|
||||
assertThat(captor.getValue().getKey(), is("1"));
|
||||
assertThat(captor.getValue().getKeyspace(), is(Foo.class.getName()));
|
||||
assertThat(captor.getValue().getPayload(), is((Object) FOO_ONE));
|
||||
assertThat(captor.getValue().getPayload(), is(FOO_ONE));
|
||||
}
|
||||
|
||||
@Test // DATAKV-91, DATAKV-104, DATAKV-187
|
||||
@@ -486,7 +487,7 @@ public class KeyValueTemplateUnitTests {
|
||||
|
||||
assertThat(captor.getValue().getKey(), is("1"));
|
||||
assertThat(captor.getValue().getKeyspace(), is(Foo.class.getName()));
|
||||
assertThat(captor.getValue().getPayload(), is((Object) FOO_ONE));
|
||||
assertThat(captor.getValue().getPayload(), is(FOO_ONE));
|
||||
}
|
||||
|
||||
@Test // DATAKV-91, DATAKV-104, DATAKV-187
|
||||
@@ -525,7 +526,7 @@ public class KeyValueTemplateUnitTests {
|
||||
|
||||
assertThat(captor.getValue().getKey(), is("1"));
|
||||
assertThat(captor.getValue().getKeyspace(), is(Foo.class.getName()));
|
||||
assertThat(captor.getValue().getPayload(), is((Object) FOO_ONE));
|
||||
assertThat(captor.getValue().getPayload(), is(FOO_ONE));
|
||||
}
|
||||
|
||||
@Test // DATAKV-91, DATAKV-104, DATAKV-187
|
||||
@@ -552,8 +553,9 @@ public class KeyValueTemplateUnitTests {
|
||||
verify(adapterMock, times(1)).put("1", ALIASED_USING_ALIAS_FOR, "aliased");
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
@SuppressWarnings("rawtypes")
|
||||
private void setEventsToPublish(Class<? extends KeyValueEvent>... events) {
|
||||
private final void setEventsToPublish(Class<? extends KeyValueEvent>... events) {
|
||||
template.setEventTypesToPublish(new HashSet<>(Arrays.asList(events)));
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.springframework.data.keyvalue.annotation.KeySpace;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link AnnotationBasedKeySpaceResolver}.
|
||||
*
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@@ -114,7 +114,7 @@ public class AnnotationBasedKeySpaceResolverUnitTests {
|
||||
@AliasFor(annotation = KeySpace.class, attribute = "value")
|
||||
String firstname() default "daenerys";
|
||||
|
||||
String lastnamne() default "targaryen";
|
||||
String lastname() default "targaryen";
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -165,7 +165,7 @@ public class SimpleKeyValueRepositoryUnitTests {
|
||||
@Test // DATACMNS-525
|
||||
public void findAllShouldFallbackToFindAllOfWhenGivenNullPageable() {
|
||||
|
||||
repo.findAll((Pageable) null);
|
||||
repo.findAll(Pageable.unpaged());
|
||||
|
||||
verify(opsMock, times(1)).findAll(eq(Foo.class));
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ public class KeyValuePartTreeQueryUnitTests {
|
||||
assertThat(query.getRows(), is(3));
|
||||
}
|
||||
|
||||
static interface Repo {
|
||||
interface Repo {
|
||||
|
||||
List<Person> findByFirstname(String firstname);
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@ import static org.hamcrest.core.Is.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
@@ -43,6 +45,7 @@ import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class SpelQueryCreatorUnitTests {
|
||||
@@ -341,7 +344,8 @@ public class SpelQueryCreatorUnitTests {
|
||||
return q;
|
||||
}
|
||||
|
||||
static interface PersonRepository {
|
||||
@SuppressWarnings("unused")
|
||||
interface PersonRepository {
|
||||
|
||||
// No arguments
|
||||
Person findBy();
|
||||
@@ -423,9 +427,9 @@ public class SpelQueryCreatorUnitTests {
|
||||
expression.getEvaluationContext().setVariable("it", candidate);
|
||||
return expression.getValue(Boolean.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Data
|
||||
static class Person {
|
||||
|
||||
private @Id String id;
|
||||
@@ -442,54 +446,6 @@ public class SpelQueryCreatorUnitTests {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getFirstname() {
|
||||
return firstname;
|
||||
}
|
||||
|
||||
public void setFirstname(String firstname) {
|
||||
this.firstname = firstname;
|
||||
}
|
||||
|
||||
public String getLastname() {
|
||||
return lastname;
|
||||
}
|
||||
|
||||
public void setLastname(String lastname) {
|
||||
this.lastname = lastname;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public Date getBirthday() {
|
||||
return birthday;
|
||||
}
|
||||
|
||||
public void setBirthday(Date birthday) {
|
||||
this.birthday = birthday;
|
||||
}
|
||||
|
||||
public boolean isSkinChanger() {
|
||||
return isSkinChanger;
|
||||
}
|
||||
|
||||
public void setSkinChanger(boolean isSkinChanger) {
|
||||
this.isSkinChanger = isSkinChanger;
|
||||
}
|
||||
|
||||
public Person skinChanger(boolean isSkinChanger) {
|
||||
this.isSkinChanger = isSkinChanger;
|
||||
return this;
|
||||
|
||||
@@ -56,7 +56,6 @@ public abstract class AbstractRepositoryUnitTests<T extends AbstractRepositoryUn
|
||||
protected final QPerson person = QPerson.person;
|
||||
|
||||
protected T repository;
|
||||
protected KeyValueRepositoryFactory factory;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
|
||||
@@ -22,12 +22,13 @@ import static org.hamcrest.core.IsNull.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.data.keyvalue.test.util.IsEntry.*;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.util.CloseableIterator;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
@@ -171,6 +172,7 @@ public class MapKeyValueAdapterUnitTests {
|
||||
assertThat(iterator.hasNext(), is(false));
|
||||
}
|
||||
|
||||
@Data
|
||||
static class SimpleObject {
|
||||
|
||||
protected String stringValue;
|
||||
@@ -180,29 +182,6 @@ public class MapKeyValueAdapterUnitTests {
|
||||
SimpleObject(String value) {
|
||||
this.stringValue = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * ObjectUtils.nullSafeHashCode(this.stringValue);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof SimpleObject)) {
|
||||
return false;
|
||||
}
|
||||
SimpleObject that = (SimpleObject) obj;
|
||||
return ObjectUtils.nullSafeEquals(this.stringValue, that.stringValue);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ package org.springframework.data.map.repository.config;
|
||||
import static org.hamcrest.core.IsNull.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -31,8 +33,9 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link MapRepositoriesRegistrar} with complete defaulting.
|
||||
*
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
@@ -51,30 +54,15 @@ public class MapRepositoryRegistrarWithFullDefaultingIntegrationTests {
|
||||
assertThat(repo, notNullValue());
|
||||
}
|
||||
|
||||
@Data
|
||||
static class Person {
|
||||
|
||||
@Id String id;
|
||||
String firstname;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getFirstname() {
|
||||
return firstname;
|
||||
}
|
||||
|
||||
public void setFirstname(String firstname) {
|
||||
this.firstname = firstname;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static interface PersonRepository extends CrudRepository<Person, String> {
|
||||
interface PersonRepository extends CrudRepository<Person, String> {
|
||||
|
||||
List<Person> findByFirstname(String firstname);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ package org.springframework.data.map.repository.config;
|
||||
import static org.hamcrest.core.IsNull.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -35,8 +37,9 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link MapRepositoriesRegistrar} with complete defaulting.
|
||||
*
|
||||
*
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
@@ -59,30 +62,14 @@ public class MapRepositoryRegistrarWithTemplateDefinitionIntegrationTests {
|
||||
assertThat(repo, notNullValue());
|
||||
}
|
||||
|
||||
@Data
|
||||
static class Person {
|
||||
|
||||
@Id String id;
|
||||
String firstname;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getFirstname() {
|
||||
return firstname;
|
||||
}
|
||||
|
||||
public void setFirstname(String firstname) {
|
||||
this.firstname = firstname;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static interface PersonRepository extends CrudRepository<Person, String> {
|
||||
interface PersonRepository extends CrudRepository<Person, String> {
|
||||
|
||||
List<Person> findByFirstname(String firstname);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user