DATACMNS-867 - Additional Java 8 language feature cleanup.

Make use of lambdas and method references though out the codebase. Remove no longer required generic type parameters.
Additionally remove unused imports and replace single element list initialization with dedicated singletonList.
Use Assertion overloads taking Supplier for dynamic assertion error messages.
This commit is contained in:
Christoph Strobl
2017-02-15 12:06:09 +01:00
committed by Oliver Gierke
parent aa4c51e1ea
commit be347eaaab
176 changed files with 673 additions and 797 deletions

View File

@@ -44,17 +44,13 @@ public class DefaultAuditableBeanWrapperFactoryUnitTests {
@Test
public void returnsAuditableInterfaceBeanWrapperForAuditable() {
assertThat(factory.getBeanWrapperFor(Optional.of(new AuditedUser()))).hasValueSatisfying(it -> {
assertThat(it).isInstanceOf(AuditableInterfaceBeanWrapper.class);
});
assertThat(factory.getBeanWrapperFor(Optional.of(new AuditedUser()))).hasValueSatisfying(it -> assertThat(it).isInstanceOf(AuditableInterfaceBeanWrapper.class));
}
@Test
public void returnsReflectionAuditingBeanWrapperForNonAuditableButAnnotated() {
assertThat(factory.getBeanWrapperFor(Optional.of(new AnnotatedUser()))).hasValueSatisfying(it -> {
assertThat(it).isInstanceOf(ReflectionAuditingBeanWrapper.class);
});
assertThat(factory.getBeanWrapperFor(Optional.of(new AnnotatedUser()))).hasValueSatisfying(it -> assertThat(it).isInstanceOf(ReflectionAuditingBeanWrapper.class));
}
@Test
@@ -89,8 +85,6 @@ public class DefaultAuditableBeanWrapperFactoryUnitTests {
Optional<AuditableBeanWrapper> wrapper = factory.getBeanWrapperFor(Optional.of(user));
assertThat(wrapper).hasValueSatisfying(it -> {
it.setLastModifiedDate(Optional.of(zonedDateTime));
});
assertThat(wrapper).hasValueSatisfying(it -> it.setLastModifiedDate(Optional.of(zonedDateTime)));
}
}

View File

@@ -82,7 +82,7 @@ public class IsNewAwareAuditingHandlerUnitTests extends AuditingHandlerUnitTests
@Test // DATACMNS-365
public void setsUpHandlerWithMappingContext() {
new IsNewAwareAuditingHandler(new PersistentEntities(Collections.<MappingContext<?, ?>> emptySet()));
new IsNewAwareAuditingHandler(new PersistentEntities(Collections.emptySet()));
}
@Test // DATACMNS-638

View File

@@ -96,9 +96,7 @@ public class MappingAuditableBeanWrapperFactoryUnitTests {
Optional<AuditableBeanWrapper> wrapper = factory.getBeanWrapperFor(Optional.of(sample));
assertThat(wrapper).hasValueSatisfying(it -> {
it.setLastModifiedDate(Optional.of(Instant.now()));
});
assertThat(wrapper).hasValueSatisfying(it -> it.setLastModifiedDate(Optional.of(Instant.now())));
}
@Test // DATACMNS-365
@@ -109,9 +107,7 @@ public class MappingAuditableBeanWrapperFactoryUnitTests {
@Test // DATACMNS-365
public void returnsAuditableWrapperForAuditable() {
assertThat(factory.getBeanWrapperFor(Optional.of(mock(ExtendingAuditable.class)))).hasValueSatisfying(it -> {
assertThat(it).isInstanceOf(AuditableInterfaceBeanWrapper.class);
});
assertThat(factory.getBeanWrapperFor(Optional.of(mock(ExtendingAuditable.class)))).hasValueSatisfying(it -> assertThat(it).isInstanceOf(AuditableInterfaceBeanWrapper.class));
}
@Test // DATACMNS-638
@@ -166,9 +162,7 @@ public class MappingAuditableBeanWrapperFactoryUnitTests {
Optional<AuditableBeanWrapper> wrapper = factory.getBeanWrapperFor(Optional.of(sample));
assertThat(wrapper).hasValueSatisfying(it -> {
assertThat(it.getLastModifiedDate()).isEqualTo(expected);
});
assertThat(wrapper).hasValueSatisfying(it -> assertThat(it.getLastModifiedDate()).isEqualTo(expected));
}
static class Sample {

View File

@@ -14,7 +14,6 @@
*/
package org.springframework.data.auditing.config;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import java.lang.annotation.Annotation;

View File

@@ -16,7 +16,6 @@
package org.springframework.data.convert;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.springframework.data.util.ClassTypeInformation.*;
@@ -90,9 +89,7 @@ public class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProp
assertThat(instance.createInstance(entity, provider)).isInstanceOf(Foo.class);
assertThat(constructor).hasValueSatisfying(it -> {
verify(provider, times(1)).getParameterValue(it.getParameters().iterator().next());
});
assertThat(constructor).hasValueSatisfying(it -> verify(provider, times(1)).getParameterValue(it.getParameters().iterator().next()));
}
@Test(expected = MappingInstantiationException.class) // DATACMNS-300, DATACMNS-578
@@ -108,7 +105,7 @@ public class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProp
@Test // DATACMNS-134, DATACMNS-578
public void createsInnerClassInstanceCorrectly() {
BasicPersistentEntity<Inner, P> entity = new BasicPersistentEntity<Inner, P>(from(Inner.class));
BasicPersistentEntity<Inner, P> entity = new BasicPersistentEntity<>(from(Inner.class));
assertThat(entity.getPersistenceConstructor()).hasValueSatisfying(constructor -> {
Parameter<Object, P> parameter = constructor.getParameters().iterator().next();
@@ -167,9 +164,7 @@ public class ClassGeneratingEntityInstantiatorUnitTests<P extends PersistentProp
doReturn(new PreferredConstructorDiscoverer<>(ObjCtorDefault.class).getConstructor())//
.when(entity).getPersistenceConstructor();
IntStream.range(0, 2).forEach(i -> {
assertThat(this.instance.createInstance(entity, provider)).isInstanceOf(ObjCtorDefault.class);
});
IntStream.range(0, 2).forEach(i -> assertThat(this.instance.createInstance(entity, provider)).isInstanceOf(ObjCtorDefault.class));
}
@Test // DATACMNS-578

View File

@@ -52,7 +52,7 @@ public class ConfigurableTypeInformationMapperUnitTests<T extends PersistentProp
@Test(expected = IllegalArgumentException.class)
public void rejectsNonBijectionalMap() {
Map<Class<?>, String> map = new HashMap<Class<?>, String>();
Map<Class<?>, String> map = new HashMap<>();
map.put(String.class, "1");
map.put(Object.class, "1");

View File

@@ -53,7 +53,7 @@ public class DefaultTypeMapperUnitTests {
@Before
public void setUp() {
this.typeMapper = new DefaultTypeMapper<Map<String, String>>(accessor, Arrays.asList(mapper));
this.typeMapper = new DefaultTypeMapper<>(accessor, Collections.singletonList(mapper));
this.source = Collections.singletonMap("key", ALIAS.toString());
doReturn(ALIAS).when(accessor).readAliasFrom(source);
@@ -98,7 +98,7 @@ public class DefaultTypeMapperUnitTests {
TypeInformation<?> typeInformation = TypeInformation.class.cast(result);
assertThat(typeInformation.getType()).isEqualTo(Bar.class);
OptionalAssert.assertOptional(typeInformation.getProperty("field")).value(nested -> nested.getType())
OptionalAssert.assertOptional(typeInformation.getProperty("field")).value(TypeInformation::getType)
.isEqualTo(Character.class);
}

View File

@@ -56,7 +56,7 @@ public class EntityInstantiatorsUnitTests {
doReturn(String.class).when(entity).getType();
Map<Class<?>, EntityInstantiator> customInstantiators = Collections
.<Class<?>, EntityInstantiator> singletonMap(String.class, customInstantiator);
.singletonMap(String.class, customInstantiator);
EntityInstantiators instantiators = new EntityInstantiators(customInstantiators);
assertThat(instantiators.getInstantiatorFor(entity)).isEqualTo(customInstantiator);
@@ -68,7 +68,7 @@ public class EntityInstantiatorsUnitTests {
doReturn(Object.class).when(entity).getType();
Map<Class<?>, EntityInstantiator> customInstantiators = Collections
.<Class<?>, EntityInstantiator> singletonMap(String.class, ReflectionEntityInstantiator.INSTANCE);
.singletonMap(String.class, ReflectionEntityInstantiator.INSTANCE);
EntityInstantiators instantiators = new EntityInstantiators(customInstantiator, customInstantiators);
instantiators.getInstantiatorFor(entity);

View File

@@ -128,7 +128,7 @@ public class Jsr310ConvertersUnitTests {
@Test
public void convertsZoneIdToStringAndBack() {
Map<String, ZoneId> ids = new HashMap<String, ZoneId>();
Map<String, ZoneId> ids = new HashMap<>();
ids.put("Europe/Berlin", ZoneId.of("Europe/Berlin"));
ids.put("+06:00", ZoneId.of("+06:00"));

View File

@@ -16,7 +16,6 @@
package org.springframework.data.convert;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.springframework.data.convert.ReflectionEntityInstantiator.*;
import static org.springframework.data.util.ClassTypeInformation.*;
@@ -87,9 +86,7 @@ public class ReflectionEntityInstantiatorUnitTests<P extends PersistentProperty<
Object instance = INSTANCE.createInstance(entity, provider);
assertThat(instance).isInstanceOf(Foo.class);
assertThat(constructor).hasValueSatisfying(it -> {
verify(provider, times(1)).getParameterValue(it.getParameters().iterator().next());
});
assertThat(constructor).hasValueSatisfying(it -> verify(provider, times(1)).getParameterValue(it.getParameters().iterator().next()));
}
@Test(expected = MappingInstantiationException.class) // DATACMNS-300
@@ -105,7 +102,7 @@ public class ReflectionEntityInstantiatorUnitTests<P extends PersistentProperty<
@Test // DATACMNS-134
public void createsInnerClassInstanceCorrectly() {
BasicPersistentEntity<Inner, P> entity = new BasicPersistentEntity<Inner, P>(from(Inner.class));
BasicPersistentEntity<Inner, P> entity = new BasicPersistentEntity<>(from(Inner.class));
assertThat(entity.getPersistenceConstructor()).hasValueSatisfying(it -> {
Parameter<Object, P> parameter = it.getParameters().iterator().next();
@@ -131,7 +128,7 @@ public class ReflectionEntityInstantiatorUnitTests<P extends PersistentProperty<
@SuppressWarnings({ "unchecked", "rawtypes" })
public void capturesContextOnInstantiationException() throws Exception {
PersistentEntity<Sample, P> entity = new BasicPersistentEntity<Sample, P>(from(Sample.class));
PersistentEntity<Sample, P> entity = new BasicPersistentEntity<>(from(Sample.class));
doReturn(Optional.of("FOO")).when(provider).getParameterValue(any(Parameter.class));

View File

@@ -111,7 +111,7 @@ public class ThreeTenBackPortConvertersUnitTests {
@Test
public void convertsZoneIdToStringAndBack() {
Map<String, ZoneId> ids = new HashMap<String, ZoneId>();
Map<String, ZoneId> ids = new HashMap<>();
ids.put("Europe/Berlin", ZoneId.of("Europe/Berlin"));
ids.put("+06:00", ZoneId.of("+06:00"));

View File

@@ -21,11 +21,6 @@ import static org.springframework.data.domain.ExampleMatcher.*;
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.domain.ExampleMatcher.GenericPropertyMatcher;
import org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers;
import org.springframework.data.domain.ExampleMatcher.MatcherConfigurer;
import org.springframework.data.domain.ExampleMatcher.NullHandler;
import org.springframework.data.domain.ExampleMatcher.StringMatcher;
/**
* Unit test for {@link ExampleMatcher}.
@@ -169,24 +164,14 @@ public class ExampleMatcherUnitTests {
.withNullHandler(NullHandler.IGNORE) //
.withIgnoreCase("ignored-case") //
.withMatcher("hello", GenericPropertyMatchers.contains().caseSensitive()) //
.withMatcher("world", new MatcherConfigurer<GenericPropertyMatcher>() {
@Override
public void configureMatcher(GenericPropertyMatcher matcher) {
matcher.endsWith();
}
});
.withMatcher("world", matcher -> matcher.endsWith());
ExampleMatcher sameAsMatcher = matching() //
.withIgnorePaths("foo", "bar", "baz") //
.withNullHandler(NullHandler.IGNORE) //
.withIgnoreCase("ignored-case") //
.withMatcher("hello", GenericPropertyMatchers.contains().caseSensitive()) //
.withMatcher("world", new MatcherConfigurer<GenericPropertyMatcher>() {
@Override
public void configureMatcher(GenericPropertyMatcher matcher) {
matcher.endsWith();
}
});
.withMatcher("world", matcher -> matcher.endsWith());
ExampleMatcher different = matching() //
.withIgnorePaths("foo", "bar", "baz") //

View File

@@ -20,7 +20,6 @@ import static org.springframework.data.domain.ExampleMatcher.*;
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers;
/**
* Test for {@link Example}.

View File

@@ -34,17 +34,17 @@ public class PageImplUnitTests {
@Test
public void assertEqualsForSimpleSetup() throws Exception {
PageImpl<String> page = new PageImpl<>(Arrays.asList("Foo"));
PageImpl<String> page = new PageImpl<>(Collections.singletonList("Foo"));
assertEqualsAndHashcode(page, page);
assertEqualsAndHashcode(page, new PageImpl<>(Arrays.asList("Foo")));
assertEqualsAndHashcode(page, new PageImpl<>(Collections.singletonList("Foo")));
}
@Test
public void assertEqualsForComplexSetup() throws Exception {
Pageable pageable = PageRequest.of(0, 10);
List<String> content = Arrays.asList("Foo");
List<String> content = Collections.singletonList("Foo");
PageImpl<String> page = new PageImpl<>(content, pageable, 100);
@@ -68,7 +68,7 @@ public class PageImplUnitTests {
@Test
public void returnsNextPageable() {
Page<Object> page = new PageImpl<>(Arrays.asList(new Object()), PageRequest.of(0, 1), 10);
Page<Object> page = new PageImpl<>(Collections.singletonList(new Object()), PageRequest.of(0, 1), 10);
assertThat(page.isFirst()).isTrue();
assertThat(page.hasPrevious()).isFalse();
@@ -82,7 +82,7 @@ public class PageImplUnitTests {
@Test
public void returnsPreviousPageable() {
Page<Object> page = new PageImpl<>(Arrays.asList(new Object()), PageRequest.of(1, 1), 2);
Page<Object> page = new PageImpl<>(Collections.singletonList(new Object()), PageRequest.of(1, 1), 2);
assertThat(page.isFirst()).isFalse();
assertThat(page.hasPrevious()).isTrue();
@@ -116,7 +116,7 @@ public class PageImplUnitTests {
@Test // DATACMNS-323
public void returnsCorrectTotalPages() {
Page<String> page = new PageImpl<>(Arrays.asList("a"));
Page<String> page = new PageImpl<>(Collections.singletonList("a"));
assertThat(page.getTotalPages()).isEqualTo(1);
assertThat(page.hasNext()).isFalse();
@@ -127,7 +127,7 @@ public class PageImplUnitTests {
public void transformsPageCorrectly() {
Page<Integer> transformed = new PageImpl<>(Arrays.asList("foo", "bar"), PageRequest.of(0, 2), 10)
.map(source -> source.length());
.map(String::length);
assertThat(transformed.getContent()).hasSize(2);
assertThat(transformed.getContent()).contains(3, 3);

View File

@@ -20,6 +20,7 @@ import static org.assertj.core.api.Assertions.*;
import java.io.IOException;
import java.io.StringWriter;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
@@ -103,8 +104,8 @@ public class SpringDataJaxbUnitTests {
PageWrapper wrapper = new PageWrapper();
Content content = new Content();
content.name = "Foo";
wrapper.page = new PageImpl<>(Arrays.asList(content));
wrapper.pageWithLinks = new PageImpl<>(Arrays.asList(content));
wrapper.page = new PageImpl<>(Collections.singletonList(content));
wrapper.pageWithLinks = new PageImpl<>(Collections.singletonList(content));
marshaller.marshal(wrapper, new StringWriter());
}

View File

@@ -18,6 +18,7 @@ package org.springframework.data.geo;
import static org.assertj.core.api.Assertions.*;
import java.util.Arrays;
import java.util.Collections;
import org.junit.Test;
import org.springframework.util.SerializationUtils;
@@ -45,7 +46,7 @@ public class GeoResultsUnitTests {
public void testSerialization() {
GeoResult<String> result = new GeoResult<>("test", new Distance(2));
GeoResults<String> geoResults = new GeoResults<>(Arrays.asList(result));
GeoResults<String> geoResults = new GeoResults<>(Collections.singletonList(result));
@SuppressWarnings("unchecked")
GeoResults<String> serialized = (GeoResults<String>) SerializationUtils

View File

@@ -45,8 +45,8 @@ public class ParameterUnitTests<P extends PersistentProperty<P>> {
@Test
public void twoParametersWithIdenticalSetupEqual() {
Parameter<Object, P> left = new Parameter<Object, P>(Optional.of("name"), type, annotations, Optional.of(entity));
Parameter<Object, P> right = new Parameter<Object, P>(Optional.of("name"), type, annotations, Optional.of(entity));
Parameter<Object, P> left = new Parameter<>(Optional.of("name"), type, annotations, Optional.of(entity));
Parameter<Object, P> right = new Parameter<>(Optional.of("name"), type, annotations, Optional.of(entity));
assertThat(left).isEqualTo(right);
assertThat(left.hashCode()).isEqualTo(right.hashCode());
@@ -55,8 +55,8 @@ public class ParameterUnitTests<P extends PersistentProperty<P>> {
@Test
public void twoParametersWithIdenticalSetupAndNullNameEqual() {
Parameter<Object, P> left = new Parameter<Object, P>(Optional.empty(), type, annotations, Optional.of(entity));
Parameter<Object, P> right = new Parameter<Object, P>(Optional.empty(), type, annotations, Optional.of(entity));
Parameter<Object, P> left = new Parameter<>(Optional.empty(), type, annotations, Optional.of(entity));
Parameter<Object, P> right = new Parameter<>(Optional.empty(), type, annotations, Optional.of(entity));
assertThat(left).isEqualTo(right);
assertThat(left.hashCode()).isEqualTo(right.hashCode());
@@ -65,8 +65,8 @@ public class ParameterUnitTests<P extends PersistentProperty<P>> {
@Test
public void twoParametersWithIdenticalAndNullEntitySetupEqual() {
Parameter<Object, P> left = new Parameter<Object, P>(Optional.of("name"), type, annotations, Optional.empty());
Parameter<Object, P> right = new Parameter<Object, P>(Optional.of("name"), type, annotations, Optional.empty());
Parameter<Object, P> left = new Parameter<>(Optional.of("name"), type, annotations, Optional.empty());
Parameter<Object, P> right = new Parameter<>(Optional.of("name"), type, annotations, Optional.empty());
assertThat(left).isEqualTo(right);
assertThat(left.hashCode()).isEqualTo(right.hashCode());
@@ -75,8 +75,8 @@ public class ParameterUnitTests<P extends PersistentProperty<P>> {
@Test
public void twoParametersWithDifferentNameAreNotEqual() {
Parameter<Object, P> left = new Parameter<Object, P>(Optional.of("first"), type, annotations, Optional.of(entity));
Parameter<Object, P> right = new Parameter<Object, P>(Optional.of("second"), type, annotations,
Parameter<Object, P> left = new Parameter<>(Optional.of("first"), type, annotations, Optional.of(entity));
Parameter<Object, P> right = new Parameter<>(Optional.of("second"), type, annotations,
Optional.of(entity));
assertThat(left).isNotEqualTo(right);
@@ -85,8 +85,8 @@ public class ParameterUnitTests<P extends PersistentProperty<P>> {
@Test
public void twoParametersWithDifferenTypeAreNotEqual() {
Parameter<Object, P> left = new Parameter<Object, P>(Optional.of("name"), type, annotations, Optional.of(entity));
Parameter<String, P> right = new Parameter<String, P>(Optional.of("name"), ClassTypeInformation.from(String.class),
Parameter<Object, P> left = new Parameter<>(Optional.of("name"), type, annotations, Optional.of(entity));
Parameter<String, P> right = new Parameter<>(Optional.of("name"), ClassTypeInformation.from(String.class),
annotations, Optional.of(stringEntity));
assertThat(left).isNotEqualTo(right);

View File

@@ -96,8 +96,8 @@ public class PreferredConstructorDiscovererUnitTests<P extends PersistentPropert
@Test // DATACMNS-134
public void discoversInnerClassConstructorCorrectly() {
PersistentEntity<Inner, P> entity = new BasicPersistentEntity<Inner, P>(ClassTypeInformation.from(Inner.class));
PreferredConstructorDiscoverer<Inner, P> discoverer = new PreferredConstructorDiscoverer<Inner, P>(entity);
PersistentEntity<Inner, P> entity = new BasicPersistentEntity<>(ClassTypeInformation.from(Inner.class));
PreferredConstructorDiscoverer<Inner, P> discoverer = new PreferredConstructorDiscoverer<>(entity);
assertThat(discoverer.getConstructor()).hasValueSatisfying(constructor -> {

View File

@@ -39,7 +39,7 @@ public class SimpleTypeHolderUnitTests {
@Test(expected = IllegalArgumentException.class)
public void rejectsNullOriginal() {
new SimpleTypeHolder(new HashSet<Class<?>>(), null);
new SimpleTypeHolder(new HashSet<>(), null);
}
@Test(expected = IllegalArgumentException.class) // DATACMNS-31
@@ -59,7 +59,7 @@ public class SimpleTypeHolderUnitTests {
@Test
public void doesNotAddDefaultConvertersIfConfigured() {
SimpleTypeHolder holder = new SimpleTypeHolder(new HashSet<Class<?>>(), false);
SimpleTypeHolder holder = new SimpleTypeHolder(new HashSet<>(), false);
assertThat(holder.isSimpleType(UUID.class)).isFalse();
}

View File

@@ -75,20 +75,17 @@ public class AbstractMappingContextIntegrationTests<T extends PersistentProperty
Thread a = new Thread(() -> context.getPersistentEntity(Person.class));
Thread b = new Thread(new Runnable() {
Thread b = new Thread(() -> {
public void run() {
PersistentEntity<Object, T> entity = context.getRequiredPersistentEntity(Person.class);
PersistentEntity<Object, T> entity = context.getRequiredPersistentEntity(Person.class);
entity.doWithProperties((PropertyHandler<T>) persistentProperty -> {
try {
Thread.sleep(250);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
});
}
entity.doWithProperties((PropertyHandler<T>) persistentProperty -> {
try {
Thread.sleep(250);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
});
});
a.start();

View File

@@ -142,9 +142,7 @@ public class AbstractMappingContextUnitTests {
PersistentEntity<Object, SamplePersistentProperty> entity = mappingContext
.getRequiredPersistentEntity(Extension.class);
assertThat(entity.getPersistentProperty("foo")).hasValueSatisfying(it -> {
assertThat(it.isIdProperty()).isTrue();
});
assertThat(entity.getPersistentProperty("foo")).hasValueSatisfying(it -> assertThat(it.isIdProperty()).isTrue());
}
@Test // DATACMNS-345
@@ -155,11 +153,7 @@ public class AbstractMappingContextUnitTests {
PersistentEntity<Object, SamplePersistentProperty> entity = mappingContext
.getRequiredPersistentEntity(Sample.class);
assertThat(entity.getPersistentProperty("persons")).hasValueSatisfying(it -> {
assertThat(mappingContext.getPersistentEntity(it)).hasValueSatisfying(inner -> {
assertThat(inner.getType()).isEqualTo(Person.class);
});
});
assertThat(entity.getPersistentProperty("persons")).hasValueSatisfying(it -> assertThat(mappingContext.getPersistentEntity(it)).hasValueSatisfying(inner -> assertThat(inner.getType()).isEqualTo(Person.class)));
}
@Test // DATACMNS-380

View File

@@ -16,10 +16,10 @@
package org.springframework.data.mapping.context;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import java.util.Arrays;
import java.util.Collections;
import org.junit.Before;
import org.junit.Test;
@@ -46,7 +46,7 @@ public class DefaultPersistenPropertyPathUnitTests<T extends PersistentProperty<
@Before
public void setUp() {
oneLeg = new DefaultPersistentPropertyPath<>(Arrays.asList(first));
oneLeg = new DefaultPersistentPropertyPath<>(Collections.singletonList(first));
twoLegs = new DefaultPersistentPropertyPath<>(Arrays.asList(first, second));
}
@@ -98,7 +98,7 @@ public class DefaultPersistenPropertyPathUnitTests<T extends PersistentProperty<
PersistentPropertyPath<T> extension = twoLegs.getExtensionForBaseOf(oneLeg);
assertThat(extension).isEqualTo(new DefaultPersistentPropertyPath<>(Arrays.asList(second)));
assertThat(extension).isEqualTo(new DefaultPersistentPropertyPath<>(Collections.singletonList(second)));
}
@Test

View File

@@ -41,21 +41,21 @@ public class MappingContextEventUnitTests<E extends PersistentEntity<?, P>, P ex
@Test
public void returnsPersistentEntityHandedToTheEvent() {
MappingContextEvent<E, P> event = new MappingContextEvent<E, P>(mappingContext, entity);
MappingContextEvent<E, P> event = new MappingContextEvent<>(mappingContext, entity);
assertThat(event.getPersistentEntity()).isEqualTo(entity);
}
@Test
public void usesMappingContextAsEventSource() {
MappingContextEvent<E, P> event = new MappingContextEvent<E, P>(mappingContext, entity);
MappingContextEvent<E, P> event = new MappingContextEvent<>(mappingContext, entity);
assertThat(event.getSource()).isEqualTo(mappingContext);
}
@Test
public void detectsEmittingMappingContextCorrectly() {
MappingContextEvent<E, P> event = new MappingContextEvent<E, P>(mappingContext, entity);
MappingContextEvent<E, P> event = new MappingContextEvent<>(mappingContext, entity);
assertThat(event.wasEmittedBy(mappingContext)).isTrue();
assertThat(event.wasEmittedBy(otherMappingContext)).isFalse();
}

View File

@@ -65,15 +65,13 @@ public class PersistentEntitiesUnitTests {
context.setInitialEntitySet(Collections.singleton(Sample.class));
context.initialize();
PersistentEntities entities = new PersistentEntities(Arrays.asList(context));
PersistentEntities entities = new PersistentEntities(Collections.singletonList(context));
assertThat(entities.getPersistentEntity(Sample.class)).isPresent();
assertThat(entities.getPersistentEntity(Object.class)).isNotPresent();
assertThat(entities.getManagedTypes()).contains(ClassTypeInformation.from(Sample.class));
assertThat(entities.getPersistentEntity(Sample.class)).hasValueSatisfying(it -> {
assertThat(entities).contains(it);
});
assertThat(entities.getPersistentEntity(Sample.class)).hasValueSatisfying(it -> assertThat(entities).contains(it));
}

View File

@@ -12,7 +12,7 @@ public class SampleMappingContext
@SuppressWarnings("unchecked")
protected <S> BasicPersistentEntity<Object, SamplePersistentProperty> createPersistentEntity(
TypeInformation<S> typeInformation) {
return new BasicPersistentEntity<Object, SamplePersistentProperty>((TypeInformation<Object>) typeInformation);
return new BasicPersistentEntity<>((TypeInformation<Object>) typeInformation);
}
@Override

View File

@@ -92,9 +92,7 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
assertThat(cache.containsKey(MyAnnotation.class)).isFalse();
// Assert meta annotation is found and cached
assertThat(property.findAnnotation(MyAnnotation.class)).hasValueSatisfying(annotation -> {
assertThat(cache.containsKey(MyAnnotation.class)).isTrue();
});
assertThat(property.findAnnotation(MyAnnotation.class)).hasValueSatisfying(annotation -> assertThat(cache.containsKey(MyAnnotation.class)).isTrue());
});
}
@@ -112,33 +110,25 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
@Test // DATACMNS-243
public void defaultsToFieldAccess() {
assertThat(getProperty(FieldAccess.class, "name")).hasValueSatisfying(it -> {
assertThat(it.usePropertyAccess()).isFalse();
});
assertThat(getProperty(FieldAccess.class, "name")).hasValueSatisfying(it -> assertThat(it.usePropertyAccess()).isFalse());
}
@Test // DATACMNS-243
public void usesAccessTypeDeclaredOnTypeAsDefault() {
assertThat(getProperty(PropertyAccess.class, "firstname")).hasValueSatisfying(it -> {
assertThat(it.usePropertyAccess()).isTrue();
});
assertThat(getProperty(PropertyAccess.class, "firstname")).hasValueSatisfying(it -> assertThat(it.usePropertyAccess()).isTrue());
}
@Test // DATACMNS-243
public void propertyAnnotationOverridesTypeConfiguration() {
assertThat(getProperty(PropertyAccess.class, "lastname")).hasValueSatisfying(it -> {
assertThat(it.usePropertyAccess()).isFalse();
});
assertThat(getProperty(PropertyAccess.class, "lastname")).hasValueSatisfying(it -> assertThat(it.usePropertyAccess()).isFalse());
}
@Test // DATACMNS-243
public void fieldAnnotationOverridesTypeConfiguration() {
assertThat(getProperty(PropertyAccess.class, "emailAddress")).hasValueSatisfying(it -> {
assertThat(it.usePropertyAccess()).isFalse();
});
assertThat(getProperty(PropertyAccess.class, "emailAddress")).hasValueSatisfying(it -> assertThat(it.usePropertyAccess()).isFalse());
}
@Test // DATACMNS-243
@@ -149,9 +139,7 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
@Test // DATACMNS-534
public void treatsNoAnnotationCorrectly() {
assertThat(getProperty(ClassWithReadOnlyProperties.class, "noAnnotations")).hasValueSatisfying(it -> {
assertThat(it.isWritable()).isTrue();
});
assertThat(getProperty(ClassWithReadOnlyProperties.class, "noAnnotations")).hasValueSatisfying(it -> assertThat(it.isWritable()).isTrue());
}
@Test // DATACMNS-534
@@ -162,17 +150,13 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
@Test // DATACMNS-534
public void treatsReadOnlyAsNonWritable() {
assertThat(getProperty(ClassWithReadOnlyProperties.class, "readOnlyProperty")).hasValueSatisfying(it -> {
assertThat(it.isWritable()).isFalse();
});
assertThat(getProperty(ClassWithReadOnlyProperties.class, "readOnlyProperty")).hasValueSatisfying(it -> assertThat(it.isWritable()).isFalse());
}
@Test // DATACMNS-534
public void considersPropertyWithReadOnlyMetaAnnotationReadOnly() {
assertThat(getProperty(ClassWithReadOnlyProperties.class, "customReadOnlyProperty")).hasValueSatisfying(it -> {
assertThat(it.isWritable()).isFalse();
});
assertThat(getProperty(ClassWithReadOnlyProperties.class, "customReadOnlyProperty")).hasValueSatisfying(it -> assertThat(it.isWritable()).isFalse());
}
@Test // DATACMNS-556
@@ -208,31 +192,23 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
assertThat(cache.containsKey(MyAnnotation.class)).isFalse();
// Assert meta annotation is found and cached
assertThat(property.findAnnotation(MyAnnotation.class)).hasValueSatisfying(it -> {
assertThat(cache.containsKey(MyAnnotation.class)).isTrue();
});
assertThat(property.findAnnotation(MyAnnotation.class)).hasValueSatisfying(it -> assertThat(cache.containsKey(MyAnnotation.class)).isTrue());
});
}
@Test // DATACMNS-825
public void composedAnnotationWithAliasShouldHaveSynthesizedAttributeValues() {
assertThat(entity.getPersistentProperty("metaAliased")).hasValueSatisfying(property -> {
assertThat(property.findAnnotation(MyAnnotation.class)).hasValueSatisfying(annotation -> {
assertThat(AnnotationUtils.getValue(annotation)).isEqualTo("spring");
});
});
assertThat(entity.getPersistentProperty("metaAliased")).hasValueSatisfying(property -> assertThat(property.findAnnotation(MyAnnotation.class)).hasValueSatisfying(annotation -> assertThat(AnnotationUtils.getValue(annotation)).isEqualTo("spring")));
}
@Test // DATACMNS-867
public void revisedAnnotationWithAliasShouldHaveSynthesizedAttributeValues() {
assertThat(entity.getPersistentProperty("setter")).hasValueSatisfying(property -> {
assertThat(property.findAnnotation(RevisedAnnnotationWithAliasFor.class)).hasValueSatisfying(annotation -> {
assertThat(annotation.name()).isEqualTo("my-value");
assertThat(annotation.value()).isEqualTo("my-value");
});
});
assertThat(entity.getPersistentProperty("setter")).hasValueSatisfying(property -> assertThat(property.findAnnotation(RevisedAnnnotationWithAliasFor.class)).hasValueSatisfying(annotation -> {
assertThat(annotation.name()).isEqualTo("my-value");
assertThat(annotation.value()).isEqualTo("my-value");
}));
}
@SuppressWarnings("unchecked")

View File

@@ -159,15 +159,11 @@ public class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
Optional<SamplePersistentProperty> property = entity.getPersistentProperty(LastModifiedBy.class);
assertThat(property).hasValueSatisfying(it -> {
assertThat(it.getName()).isEqualTo("field");
});
assertThat(property).hasValueSatisfying(it -> assertThat(it.getName()).isEqualTo("field"));
property = entity.getPersistentProperty(CreatedBy.class);
assertThat(property).hasValueSatisfying(it -> {
assertThat(it.getName()).isEqualTo("property");
});
assertThat(property).hasValueSatisfying(it -> assertThat(it.getName()).isEqualTo("property"));
assertThat(entity.getPersistentProperty(CreatedDate.class)).isNotPresent();
}
@@ -253,13 +249,7 @@ public class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
BasicPersistentEntity<Entity, T> entity = createEntity(Entity.class);
entity.addAssociation(null);
entity.doWithAssociations(new SimpleAssociationHandler() {
@Override
public void doWithAssociation(Association<? extends PersistentProperty<?>> association) {
Assert.fail("Expected the method to never be called!");
}
});
entity.doWithAssociations((SimpleAssociationHandler) association -> Assert.fail("Expected the method to never be called!"));
}
private <S> BasicPersistentEntity<S, T> createEntity(Class<S> type) {
@@ -267,7 +257,7 @@ public class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
}
private <S> BasicPersistentEntity<S, T> createEntity(Class<S> type, Comparator<T> comparator) {
return new BasicPersistentEntity<S, T>(ClassTypeInformation.from(type), Optional.ofNullable(comparator));
return new BasicPersistentEntity<>(ClassTypeInformation.from(type), Optional.ofNullable(comparator));
}
@TypeAlias("foo")

View File

@@ -108,7 +108,7 @@ public class ClassGeneratingPropertyAccessorFactoryDatatypeTests {
private static List<Object[]> parameters(List<Class<?>> types, String propertyName, Object value) throws Exception {
List<Object[]> parameters = new ArrayList<Object[]>();
List<Object[]> parameters = new ArrayList<>();
for (Class<?> type : types) {

View File

@@ -56,7 +56,7 @@ public class ClassGeneratingPropertyAccessorFactoryEntityTypeTests {
private EntityInformation<Object, Serializable> getEntityInformation(Class<?> type) {
PersistentEntity<Object, SamplePersistentProperty> entity = mappingContext.getRequiredPersistentEntity(type);
return new PersistentEntityInformation<Object, Serializable>(entity);
return new PersistentEntityInformation<>(entity);
}
interface Algorithm {

View File

@@ -65,7 +65,7 @@ public class ClassGeneratingPropertyAccessorFactoryTests {
@Parameters(name = "{3}")
public static List<Object[]> parameters() {
List<Object[]> parameters = new ArrayList<Object[]>();
List<Object[]> parameters = new ArrayList<>();
List<String> propertyNames = Arrays.asList("privateField", "packageDefaultField", "protectedField", "publicField",
"privateProperty", "packageDefaultProperty", "protectedProperty", "publicProperty", "syntheticProperty");
@@ -86,7 +86,7 @@ public class ClassGeneratingPropertyAccessorFactoryTests {
private static List<Object[]> parameters(Object bean, List<String> propertyNames, Class<?> expectedConstructorType) {
List<Object[]> parameters = new ArrayList<Object[]>();
List<Object[]> parameters = new ArrayList<>();
for (String propertyName : propertyNames) {
parameters.add(new Object[] { bean, propertyName, expectedConstructorType,
@@ -128,21 +128,15 @@ public class ClassGeneratingPropertyAccessorFactoryTests {
@Test // DATACMNS-809
public void getPropertyShouldFailOnUnhandledProperty() {
assertThat(getProperty(new Dummy(), "dummy")).hasValueSatisfying(property -> {
assertThatExceptionOfType(UnsupportedOperationException.class)//
.isThrownBy(() -> getPersistentPropertyAccessor(bean).getProperty(property));
});
assertThat(getProperty(new Dummy(), "dummy")).hasValueSatisfying(property -> assertThatExceptionOfType(UnsupportedOperationException.class)//
.isThrownBy(() -> getPersistentPropertyAccessor(bean).getProperty(property)));
}
@Test // DATACMNS-809
public void setPropertyShouldFailOnUnhandledProperty() {
assertThat(getProperty(new Dummy(), "dummy")).hasValueSatisfying(property -> {
assertThatExceptionOfType(UnsupportedOperationException.class)//
.isThrownBy(() -> getPersistentPropertyAccessor(bean).setProperty(property, Optional.empty()));
});
assertThat(getProperty(new Dummy(), "dummy")).hasValueSatisfying(property -> assertThatExceptionOfType(UnsupportedOperationException.class)//
.isThrownBy(() -> getPersistentPropertyAccessor(bean).setProperty(property, Optional.empty())));
}
@Test // DATACMNS-809

View File

@@ -59,9 +59,7 @@ public class ConvertingPropertyAccessorUnitTests {
Entity entity = new Entity();
entity.id = 1L;
assertThat(getIdProperty()).hasValueSatisfying(it -> {
assertThat(getAccessor(entity, CONVERSION_SERVICE).getProperty(it, String.class)).hasValue("1");
});
assertThat(getIdProperty()).hasValueSatisfying(it -> assertThat(getAccessor(entity, CONVERSION_SERVICE).getProperty(it, String.class)).hasValue("1"));
}
@Test // DATACMNS-596

View File

@@ -16,7 +16,6 @@
package org.springframework.data.mapping.model;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import java.util.Iterator;
@@ -77,13 +76,10 @@ public class PersistentEntityParameterValueProviderUnitTests<P extends Persisten
ParameterValueProvider<P> provider = new PersistentEntityParameterValueProvider<>(entity, propertyValueProvider,
Optional.of(property));
assertThat(entity.getPersistenceConstructor()).hasValueSatisfying(constructor -> {
assertThatExceptionOfType(MappingException.class)//
.isThrownBy(() -> provider.getParameterValue(constructor.getParameters().iterator().next()))//
.withMessageContaining("bar")//
.withMessageContaining(Entity.class.getName());
});
assertThat(entity.getPersistenceConstructor()).hasValueSatisfying(constructor -> assertThatExceptionOfType(MappingException.class)//
.isThrownBy(() -> provider.getParameterValue(constructor.getParameters().iterator().next()))//
.withMessageContaining("bar")//
.withMessageContaining(Entity.class.getName()));
}
static class Outer {

View File

@@ -16,7 +16,6 @@
package org.springframework.data.mapping.model;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import java.util.Optional;

View File

@@ -60,7 +60,7 @@ public class MapAccessingMethodInterceptorUnitTests {
@Test // DATACMNS-630
public void setterInvocationStoresValueInMap() throws Throwable {
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Object> map = new HashMap<>();
when(invocation.getMethod()).thenReturn(Sample.class.getMethod("setName", String.class));
when(invocation.getArguments()).thenReturn(new Object[] { "Foo" });
@@ -74,7 +74,7 @@ public class MapAccessingMethodInterceptorUnitTests {
@Test // DATACMNS-630
public void getterInvocationReturnsValueFromMap() throws Throwable {
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Object> map = new HashMap<>();
map.put("name", "Foo");
when(invocation.getMethod()).thenReturn(Sample.class.getMethod("getName"));
@@ -87,7 +87,7 @@ public class MapAccessingMethodInterceptorUnitTests {
@Test // DATACMNS-630
public void getterReturnsNullIfMapDoesNotContainValue() throws Throwable {
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Object> map = new HashMap<>();
when(invocation.getMethod()).thenReturn(Sample.class.getMethod("getName"));
@@ -98,7 +98,7 @@ public class MapAccessingMethodInterceptorUnitTests {
public void rejectsNonAccessorInvocation() throws Throwable {
when(invocation.getMethod()).thenReturn(Sample.class.getMethod("someMethod"));
new MapAccessingMethodInterceptor(Collections.<String, Object> emptyMap()).invoke(invocation);
new MapAccessingMethodInterceptor(Collections.emptyMap()).invoke(invocation);
}
interface Sample {

View File

@@ -16,7 +16,6 @@
package org.springframework.data.projection;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import java.util.Collection;

View File

@@ -94,11 +94,11 @@ public class ProxyProjectionFactoryUnitTests {
@Test // DATACMNS-630
public void createsMapBasedProxyFromSource() {
HashMap<String, Object> addressSource = new HashMap<String, Object>();
HashMap<String, Object> addressSource = new HashMap<>();
addressSource.put("zipCode", "ZIP");
addressSource.put("city", "NewYork");
Map<String, Object> source = new HashMap<String, Object>();
Map<String, Object> source = new HashMap<>();
source.put("firstname", "Dave");
source.put("lastname", "Matthews");
source.put("address", addressSource);

View File

@@ -93,7 +93,7 @@ public class SpelEvaluatingMethodInterceptorUnitTests {
@Test // DATACMNS-630
public void allowsMapAccessViaPropertyExpression() throws Throwable {
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Object> map = new HashMap<>();
map.put("name", "Dave");
when(invocation.getMethod()).thenReturn(Projection.class.getMethod("propertyFromTarget"));

View File

@@ -15,7 +15,6 @@
*/
package org.springframework.data.querydsl;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import java.io.Serializable;

View File

@@ -120,7 +120,7 @@ public class QuerydslBindingsFactoryUnitTests {
@Override
public void customize(QuerydslBindings bindings, QUser user) {
bindings.bind(QUser.user.firstname).firstOptional((path, value) -> value.map(it -> path.contains(it)));
bindings.bind(QUser.user.firstname).firstOptional((path, value) -> value.map(path::contains));
}
}
}

View File

@@ -53,9 +53,7 @@ public class QuerydslDefaultBindingUnitTests {
Optional<Predicate> predicate = binding.bind(QUser.user.address.city, Collections.singleton("two rivers"));
assertThat(predicate).hasValueSatisfying(it -> {
assertThat(it.toString()).isEqualTo(QUser.user.address.city.eq("two rivers").toString());
});
assertThat(predicate).hasValueSatisfying(it -> assertThat(it.toString()).isEqualTo(QUser.user.address.city.eq("two rivers").toString()));
}
@Test // DATACMNS-669

View File

@@ -59,7 +59,7 @@ public class QuerydslPredicateBuilderUnitTests {
public void setUp() {
this.builder = new QuerydslPredicateBuilder(new DefaultFormattingConversionService(),
SimpleEntityPathResolver.INSTANCE);
this.values = new LinkedMultiValueMap<String, String>();
this.values = new LinkedMultiValueMap<>();
}
@Test(expected = IllegalArgumentException.class) // DATACMNS-669
@@ -122,7 +122,7 @@ public class QuerydslPredicateBuilderUnitTests {
values.add("lastname", null);
QuerydslBindings bindings = new QuerydslBindings();
bindings.bind(QUser.user.lastname).firstOptional((path, value) -> value.map(it -> path.contains(it)));
bindings.bind(QUser.user.lastname).firstOptional((path, value) -> value.map(path::contains));
builder.getPredicate(USER_TYPE, values, bindings);
}

View File

@@ -96,7 +96,7 @@ public class DummyCdiExtension extends CdiRepositoryExtensionSupport {
@Override
protected void setComponentInstanceMap() {
componentInstanceMap = new HashMap<Contextual<?>, BeanInstanceBag<?>>();
componentInstanceMap = new HashMap<>();
}
@Override

View File

@@ -15,7 +15,6 @@
*/
package org.springframework.data.repository.config;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import java.lang.annotation.Annotation;

View File

@@ -43,7 +43,7 @@ public class RepositoryComponentProviderUnitTests {
@Test
public void findsAnnotatedRepositoryInterface() {
RepositoryComponentProvider provider = new RepositoryComponentProvider(Collections.<TypeFilter> emptyList());
RepositoryComponentProvider provider = new RepositoryComponentProvider(Collections.emptyList());
Set<BeanDefinition> components = provider.findCandidateComponents("org.springframework.data.repository.sample");
assertThat(components).hasSize(3);
@@ -54,7 +54,7 @@ public class RepositoryComponentProviderUnitTests {
@Test
public void limitsFoundRepositoriesToIncludeFiltersOnly() {
List<? extends TypeFilter> filters = Arrays.asList(new AssignableTypeFilter(MyOtherRepository.class));
List<? extends TypeFilter> filters = Collections.singletonList(new AssignableTypeFilter(MyOtherRepository.class));
RepositoryComponentProvider provider = new RepositoryComponentProvider(filters);
Set<BeanDefinition> components = provider.findCandidateComponents("org.springframework.data.repository");
@@ -66,7 +66,7 @@ public class RepositoryComponentProviderUnitTests {
@Test // DATACMNS-90
public void shouldConsiderNestedRepositoryInterfacesIfEnabled() {
RepositoryComponentProvider provider = new RepositoryComponentProvider(Collections.<TypeFilter> emptyList());
RepositoryComponentProvider provider = new RepositoryComponentProvider(Collections.emptyList());
provider.setConsiderNestedRepositoryInterfaces(true);
Set<BeanDefinition> components = provider.findCandidateComponents("org.springframework.data.repository.config");

View File

@@ -72,12 +72,12 @@ public class RepositoryConfigurationExtensionSupportUnitTests {
@Override
protected Collection<Class<? extends Annotation>> getIdentifyingAnnotations() {
return Collections.<Class<? extends Annotation>>singleton(Primary.class);
return Collections.singleton(Primary.class);
}
@Override
protected Collection<Class<?>> getIdentifyingTypes() {
return Collections.<Class<?>>singleton(StoreInterface.class);
return Collections.singleton(StoreInterface.class);
}
}

View File

@@ -16,7 +16,6 @@
package org.springframework.data.repository.config;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import org.junit.Test;

View File

@@ -51,7 +51,7 @@ public class AbstractEntityInformationUnitTests {
@Test // DATACMNS-357
public void detectsNewStateForPrimitiveIds() {
CustomEntityInformation<PrimitiveIdEntity, Serializable> fooEn = new CustomEntityInformation<PrimitiveIdEntity, Serializable>(
CustomEntityInformation<PrimitiveIdEntity, Serializable> fooEn = new CustomEntityInformation<>(
PrimitiveIdEntity.class);
PrimitiveIdEntity entity = new PrimitiveIdEntity();
@@ -64,7 +64,7 @@ public class AbstractEntityInformationUnitTests {
@Test // DATACMNS-357
public void detectsNewStateForPrimitiveWrapperIds() {
CustomEntityInformation<PrimitiveWrapperIdEntity, Serializable> fooEn = new CustomEntityInformation<PrimitiveWrapperIdEntity, Serializable>(
CustomEntityInformation<PrimitiveWrapperIdEntity, Serializable> fooEn = new CustomEntityInformation<>(
PrimitiveWrapperIdEntity.class);
PrimitiveWrapperIdEntity entity = new PrimitiveWrapperIdEntity();

View File

@@ -136,11 +136,7 @@ public class DefaultCrudMethodsUnitTests {
Arrays
.asList(methods.getSaveMethod(), methods.getDeleteMethod(), methods.getFindAllMethod(),
methods.getFindOneMethod())//
.forEach(method -> {
assertThat(method).hasValueSatisfying(it -> {
assertThat(it.isAccessible()).isTrue();
});
});
.forEach(method -> assertThat(method).hasValueSatisfying(it -> assertThat(it.isAccessible()).isTrue()));
}
private static CrudMethods getMethodsFor(Class<?> repositoryInterface) {

View File

@@ -16,7 +16,6 @@
package org.springframework.data.repository.core.support;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import lombok.Getter;
@@ -25,6 +24,7 @@ import lombok.Value;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.UUID;
import org.aopalliance.aop.Advice;
@@ -109,7 +109,7 @@ public class EventPublishingRepositoryProxyPostProcessorUnitTests {
doReturn(SampleRepository.class.getMethod("save", Object.class)).when(invocation).getMethod();
SomeEvent event = new SomeEvent();
MultipleEvents sample = MultipleEvents.of(Arrays.asList(event));
MultipleEvents sample = MultipleEvents.of(Collections.singletonList(event));
doReturn(new Object[] { sample }).when(invocation).getArguments();
EventPublishingMethodInterceptor//
@@ -161,8 +161,8 @@ public class EventPublishingRepositoryProxyPostProcessorUnitTests {
public void publishesEventsForCallToSaveWithIterable() throws Throwable {
SomeEvent event = new SomeEvent();
MultipleEvents sample = MultipleEvents.of(Arrays.asList(event));
doReturn(new Object[] { Arrays.asList(sample) }).when(invocation).getArguments();
MultipleEvents sample = MultipleEvents.of(Collections.singletonList(event));
doReturn(new Object[] {Collections.singletonList(sample)}).when(invocation).getArguments();
doReturn(SampleRepository.class.getMethod("save", Iterable.class)).when(invocation).getMethod();

View File

@@ -21,6 +21,7 @@ import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatc
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.ExampleMatcher.GenericPropertyMatcher;
import org.springframework.data.domain.ExampleMatcher.NoOpPropertyValueTransformer;
import org.springframework.data.domain.ExampleMatcher.NullHandler;
import org.springframework.data.domain.ExampleMatcher.PropertyValueTransformer;
@@ -153,7 +154,7 @@ public class ExampleSpecificationAccessorUnitTests {
specification = ExampleMatcher.matching().withStringMatcher(StringMatcher.ENDING)
.withMatcher("firstname", contains()).withMatcher("address.city", startsWith())
.withMatcher("lastname", matcher -> matcher.ignoreCase());
.withMatcher("lastname", GenericPropertyMatcher::ignoreCase);
exampleSpecificationAccessor = new ExampleMatcherAccessor(specification);
@@ -168,7 +169,7 @@ public class ExampleSpecificationAccessorUnitTests {
specification = ExampleMatcher.matching().//
withStringMatcher(StringMatcher.STARTING).//
withMatcher("firstname", matcher -> matcher.ignoreCase());
withMatcher("firstname", GenericPropertyMatcher::ignoreCase);
exampleSpecificationAccessor = new ExampleMatcherAccessor(specification);
@@ -217,13 +218,7 @@ public class ExampleSpecificationAccessorUnitTests {
@Test // DATACMNS-810
public void getValueTransformerForPathReturnsConfigurtedTransformerForPath() {
PropertyValueTransformer transformer = new PropertyValueTransformer() {
@Override
public Object convert(Object source) {
return source.toString();
}
};
PropertyValueTransformer transformer = source -> source.toString();
specification = ExampleMatcher.matching().//
withTransformer("firstname", transformer);

View File

@@ -62,7 +62,7 @@ public class PersistableEntityInformationUnitTests {
@Test
public void returnsGivenClassAsEntityType() throws Exception {
PersistableEntityInformation<PersistableEntity, Long> info = new PersistableEntityInformation<PersistableEntity, Long>(
PersistableEntityInformation<PersistableEntity, Long> info = new PersistableEntityInformation<>(
PersistableEntity.class);
assertThat(info.getJavaType()).isEqualTo(PersistableEntity.class);

View File

@@ -15,7 +15,6 @@
*/
package org.springframework.data.repository.core.support;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import org.junit.Test;

View File

@@ -39,7 +39,7 @@ public class PersistentEntityInformationUnitTests {
SampleMappingContext context = new SampleMappingContext();
PersistentEntity<Object, SamplePersistentProperty> entity = context.getRequiredPersistentEntity(Sample.class);
EntityInformation<Object, Long> information = new PersistentEntityInformation<Object, Long>(entity);
EntityInformation<Object, Long> information = new PersistentEntityInformation<>(entity);
assertThat(information.getIdType()).isEqualTo(Long.class);
Sample sample = new Sample();
@@ -55,7 +55,7 @@ public class PersistentEntityInformationUnitTests {
PersistentEntity<Object, SamplePersistentProperty> entity = context
.getRequiredPersistentEntity(EntityWithoutId.class);
PersistentEntityInformation<Object, Serializable> information = new PersistentEntityInformation<Object, Serializable>(
PersistentEntityInformation<Object, Serializable> information = new PersistentEntityInformation<>(
entity);
assertThat(information.getId(new EntityWithoutId())).isNotPresent();
}

View File

@@ -15,7 +15,6 @@
*/
package org.springframework.data.repository.core.support;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import java.util.Optional;

View File

@@ -15,7 +15,6 @@
*/
package org.springframework.data.repository.core.support;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import reactor.core.publisher.Mono;

View File

@@ -49,7 +49,7 @@ public class ReflectionEntityInformationUnitTests {
PrimitiveId primitiveId = new PrimitiveId();
EntityInformation<PrimitiveId, Serializable> information = new ReflectionEntityInformation<PrimitiveId, Serializable>(
EntityInformation<PrimitiveId, Serializable> information = new ReflectionEntityInformation<>(
PrimitiveId.class);
assertThat(information.isNew(primitiveId)).isTrue();
@@ -63,7 +63,7 @@ public class ReflectionEntityInformationUnitTests {
}
private static <T> EntityInformation<T, Serializable> getEntityInformation(Class<T> type) {
return new ReflectionEntityInformation<T, Serializable>(type, Id.class);
return new ReflectionEntityInformation<>(type, Id.class);
}
static class Sample {

View File

@@ -248,7 +248,7 @@ public class RepositoryFactorySupportUnitTests {
assumeThat(SPRING_VERSION.isGreaterThanOrEqualTo(FOUR_DOT_TWO), is(true));
List<User> reference = Arrays.asList(new User());
List<User> reference = Collections.singletonList(new User());
expect(prepareConvertingRepository(reference).readAllByFirstname("Foo"), reference);
}
@@ -256,7 +256,7 @@ public class RepositoryFactorySupportUnitTests {
@Test // DATACMNS-714
public void wrapsExecutionResultIntoListenableFutureWithEntityCollectionIfConfigured() throws Exception {
List<User> reference = Arrays.asList(new User());
List<User> reference = Collections.singletonList(new User());
expect(prepareConvertingRepository(reference).readAllByLastname("Foo"), reference);
}

View File

@@ -15,7 +15,6 @@
*/
package org.springframework.data.repository.init;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import java.util.Collection;

View File

@@ -55,7 +55,7 @@ public class ExtensionAwareEvaluationContextProviderUnitTests {
public void setUp() throws Exception {
this.method = SampleRepo.class.getMethod("findByFirstname", String.class);
this.provider = new ExtensionAwareEvaluationContextProvider(Collections.<EvaluationContextExtension>emptyList());
this.provider = new ExtensionAwareEvaluationContextProvider(Collections.emptyList());
}
@Test // DATACMNS-533
@@ -199,7 +199,7 @@ public class ExtensionAwareEvaluationContextProviderUnitTests {
final AtomicInteger counter = new AtomicInteger();
this.provider = new ExtensionAwareEvaluationContextProvider(Arrays.asList( //
this.provider = new ExtensionAwareEvaluationContextProvider(Collections.singletonList( //
new DummyExtension("_first", "first") {
@Override

View File

@@ -58,7 +58,7 @@ public class ResultProcessorUnitTests {
ResultProcessor information = new ResultProcessor(getQueryMethod("findAll"), new SpelAwareProxyProjectionFactory());
Sample sample = new Sample("Dave", "Matthews");
List<Sample> result = new ArrayList<>(Arrays.asList(sample));
List<Sample> result = new ArrayList<>(Collections.singletonList(sample));
List<Sample> converted = information.processResult(result);
assertThat(converted).contains(sample);
@@ -69,7 +69,7 @@ public class ResultProcessorUnitTests {
ResultProcessor information = getProcessor("findOneProjection");
SampleProjection result = information.processResult(Arrays.asList("Matthews"));
SampleProjection result = information.processResult(Collections.singletonList("Matthews"));
assertThat(result.getLastname()).isEqualTo("Matthews");
}
@@ -80,8 +80,8 @@ public class ResultProcessorUnitTests {
ResultProcessor information = getProcessor("findAllProjection");
List<String> columns = Arrays.asList("Matthews");
List<List<String>> source = new ArrayList<List<String>>(Arrays.asList(columns));
List<String> columns = Collections.singletonList("Matthews");
List<List<String>> source = new ArrayList<>(Collections.singletonList(columns));
List<SampleProjection> result = information.processResult(source);
@@ -94,8 +94,8 @@ public class ResultProcessorUnitTests {
ResultProcessor information = getProcessor("findAllProjection");
List<Map<String, Object>> source = new ArrayList<Map<String, Object>>(
Arrays.asList(Collections.<String, Object>singletonMap("lastname", "Matthews")));
List<Map<String, Object>> source = new ArrayList<>(
Collections.singletonList(Collections.singletonMap("lastname", "Matthews")));
List<SampleProjection> result = information.processResult(source);
@@ -108,7 +108,7 @@ public class ResultProcessorUnitTests {
ResultProcessor information = getProcessor("findAllProjection");
List<Sample> source = new ArrayList<>(Arrays.asList(new Sample("Dave", "Matthews")));
List<Sample> source = new ArrayList<>(Collections.singletonList(new Sample("Dave", "Matthews")));
List<SampleProjection> result = information.processResult(source);
assertThat(result).hasSize(1);
@@ -120,7 +120,7 @@ public class ResultProcessorUnitTests {
ResultProcessor information = getProcessor("findPageProjection", Pageable.class);
Page<Sample> source = new PageImpl<>(Arrays.asList(new Sample("Dave", "Matthews")));
Page<Sample> source = new PageImpl<>(Collections.singletonList(new Sample("Dave", "Matthews")));
Page<SampleProjection> result = information.processResult(source);
assertThat(result.getContent()).hasSize(1);
@@ -186,7 +186,7 @@ public class ResultProcessorUnitTests {
@SuppressWarnings("unchecked")
public void supportsStreamAsReturnWrapper() throws Exception {
Stream<Sample> samples = Arrays.asList(new Sample("Dave", "Matthews")).stream();
Stream<Sample> samples = Collections.singletonList(new Sample("Dave", "Matthews")).stream();
Object result = getProcessor("findStreamProjection").processResult(samples);
@@ -209,7 +209,7 @@ public class ResultProcessorUnitTests {
ResultProcessor processor = getProcessor("findAllProjection");
SpecialList<Sample> specialList = new SpecialList<Sample>(new Object());
SpecialList<Sample> specialList = new SpecialList<>(new Object());
specialList.add(new Sample("Dave", "Matthews"));
processor.processResult(specialList);

View File

@@ -22,6 +22,7 @@ import static org.springframework.data.repository.query.parser.Part.Type.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
@@ -138,12 +139,12 @@ public class PartTreeUnitTests {
@Test
public void parsesNearCorrectly() {
assertType(asList("locationNear"), NEAR, "location");
assertType(Collections.singletonList("locationNear"), NEAR, "location");
}
@Test
public void supportToStringWithoutSortOrder() throws Exception {
assertType(asList("firstname"), SIMPLE_PROPERTY, "firstname");
assertType(Collections.singletonList("firstname"), SIMPLE_PROPERTY, "firstname");
}
@Test
@@ -222,7 +223,7 @@ public class PartTreeUnitTests {
@Test // DATACMNS-94
public void parsesExistsKeywordCorrectly() {
assertType(asList("lastnameExists"), EXISTS, "lastname", 0, false);
assertType(Collections.singletonList("lastnameExists"), EXISTS, "lastname", 0, false);
}
@Test // DATACMNS-94

View File

@@ -24,14 +24,14 @@ public class SampleConfiguration {
@Bean
public RepositoryFactoryBeanSupport<Repository<User, Long>, User, Long> userRepositoryFactory() {
return new DummyRepositoryFactoryBean<Repository<User, Long>, User, Long>(UserRepository.class);
return new DummyRepositoryFactoryBean<>(UserRepository.class);
}
@Bean
public RepositoryFactoryBeanSupport<Repository<Product, Long>, Product, Long> productRepositoryFactory(
ProductRepository productRepository) {
DummyRepositoryFactoryBean<Repository<Product, Long>, Product, Long> factory = new DummyRepositoryFactoryBean<Repository<Product, Long>, Product, Long>(
DummyRepositoryFactoryBean<Repository<Product, Long>, Product, Long> factory = new DummyRepositoryFactoryBean<>(
ProductRepository.class);
factory.setCustomImplementation(productRepository);

View File

@@ -39,7 +39,6 @@ import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
import org.springframework.data.repository.query.Param;
import org.springframework.data.repository.support.RepositoryInvocationTestUtils.VerifyingMethodInterceptor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.format.annotation.DateTimeFormat.ISO;
import org.springframework.format.support.DefaultFormattingConversionService;

View File

@@ -16,7 +16,6 @@
package org.springframework.data.repository.support;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import java.lang.reflect.Method;

View File

@@ -29,7 +29,6 @@ import org.springframework.data.domain.Sort;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.core.RepositoryMetadata;
import org.springframework.data.repository.core.support.DefaultRepositoryMetadata;
import org.springframework.data.repository.support.RepositoryInvocationTestUtils.VerifyingMethodInterceptor;
import org.springframework.format.support.DefaultFormattingConversionService;
/**

View File

@@ -45,7 +45,6 @@ import org.springframework.data.repository.core.support.DefaultRepositoryMetadat
import org.springframework.data.repository.query.Param;
import org.springframework.data.repository.support.CrudRepositoryInvokerUnitTests.Person;
import org.springframework.data.repository.support.CrudRepositoryInvokerUnitTests.PersonRepository;
import org.springframework.data.repository.support.RepositoryInvocationTestUtils.VerifyingMethodInterceptor;
import org.springframework.format.support.DefaultFormattingConversionService;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
@@ -135,7 +134,7 @@ public class ReflectionRepositoryInvokerUnitTests {
@Test // DATACMNS-589
public void invokesQueryMethod() throws Exception {
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<String, String>();
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
parameters.add("firstName", "John");
Method method = PersonRepository.class.getMethod("findByFirstName", String.class, Pageable.class);
@@ -148,7 +147,7 @@ public class ReflectionRepositoryInvokerUnitTests {
@Test // DATACMNS-589
public void considersFormattingAnnotationsOnQueryMethodParameters() throws Exception {
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<String, String>();
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
parameters.add("date", "2013-07-18T10:49:00.000+02:00");
Method method = PersonRepository.class.getMethod("findByCreatedUsingISO8601Date", Date.class, Pageable.class);
@@ -208,7 +207,7 @@ public class ReflectionRepositoryInvokerUnitTests {
for (String[] ids : Arrays.asList(new String[] { "1,2" }, new String[] { "1", "2" })) {
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<String, String>();
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
parameters.put("ids", Arrays.asList(ids));
Method method = PersonRepository.class.getMethod("findByIdIn", Collection.class);
@@ -224,7 +223,7 @@ public class ReflectionRepositoryInvokerUnitTests {
RepositoryInvoker invoker = getInvokerFor(mock(SimpleRepository.class));
MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<String, Object>();
MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<>();
parameters.add("value", "value");
Method method = SimpleRepository.class.getMethod("findByClass", int.class);

View File

@@ -116,7 +116,7 @@ public class RepositoriesUnitTests {
public void discoversRepositoryForAlternativeDomainType() {
RepositoryMetadata metadata = new CustomRepositoryMetadata(SampleRepository.class);
RepositoryFactoryInformation<?, ?> information = new SampleRepoFactoryInformation<Object, Serializable>(metadata);
RepositoryFactoryInformation<?, ?> information = new SampleRepoFactoryInformation<>(metadata);
GenericApplicationContext context = new GenericApplicationContext();
context.getBeanFactory().registerSingleton("foo", information);
@@ -217,7 +217,7 @@ public class RepositoriesUnitTests {
*/
@Override
public Set<Class<?>> getAlternativeDomainTypes() {
return Collections.<Class<?>>singleton(super.getDomainType());
return Collections.singleton(super.getDomainType());
}
}

View File

@@ -167,7 +167,7 @@ public class QueryExecutionConvertersUnitTests {
@Test // DATACMNS-795
public void turnsNullIntoScalaOptionEmpty() {
assertThat(conversionService.convert(new NullableWrapper(null), Option.class)).isEqualTo(Option.<Object> empty());
assertThat(conversionService.convert(new NullableWrapper(null), Option.class)).isEqualTo(Option.empty());
}
@Test // DATACMNS-795

View File

@@ -47,7 +47,7 @@ public class ChainedTransactionManagerTests {
createAndCommitTransaction();
assertThat(transactionManager).matches(tptm -> tptm.isCommitted());
assertThat(transactionManager).matches(TestPlatformTransactionManager::isCommitted);
}
@Test
@@ -56,7 +56,7 @@ public class ChainedTransactionManagerTests {
setupTransactionManagers(createFailingTransactionManager("single"));
assertThatExceptionOfType(HeuristicCompletionException.class)//
.isThrownBy(() -> createAndCommitTransaction())//
.isThrownBy(this::createAndCommitTransaction)//
.matches(e -> e.getOutcomeState() == HeuristicCompletionException.STATE_ROLLED_BACK);
}
@@ -69,8 +69,8 @@ public class ChainedTransactionManagerTests {
setupTransactionManagers(first, second);
createAndCommitTransaction();
assertThat(first).matches(ptm -> ptm.isCommitted());
assertThat(second).matches(ptm -> ptm.isCommitted());
assertThat(first).matches(TestPlatformTransactionManager::isCommitted);
assertThat(second).matches(TestPlatformTransactionManager::isCommitted);
}
@Test
@@ -92,7 +92,7 @@ public class ChainedTransactionManagerTests {
createNonFailingTransactionManager("second"));
assertThatExceptionOfType(HeuristicCompletionException.class)//
.isThrownBy(() -> createAndCommitTransaction())//
.isThrownBy(this::createAndCommitTransaction)//
.matches(e -> e.getOutcomeState() == HeuristicCompletionException.STATE_MIXED);
}
@@ -105,8 +105,8 @@ public class ChainedTransactionManagerTests {
setupTransactionManagers(first, second);
createAndRollbackTransaction();
assertThat(first).matches(ptm -> ptm.wasRolledBack());
assertThat(second).matches(ptm -> ptm.wasRolledBack());
assertThat(first).matches(TestPlatformTransactionManager::wasRolledBack);
assertThat(second).matches(TestPlatformTransactionManager::wasRolledBack);
}

View File

@@ -48,9 +48,9 @@ public class ClassTypeInformationUnitTests {
OptionalAssert<TypeInformation<?>> assertThat = assertOptional(discoverer.getProperty("content"));
assertThat.value(it -> it.getType()).isEqualTo(String.class);
assertThat.flatMap(it -> it.getComponentType()).isNotPresent();
assertThat.flatMap(it -> it.getMapValueType()).isNotPresent();
assertThat.value(TypeInformation::getType).isEqualTo(String.class);
assertThat.flatMap(TypeInformation::getComponentType).isNotPresent();
assertThat.flatMap(TypeInformation::getMapValueType).isNotPresent();
}
@Test
@@ -60,11 +60,11 @@ public class ClassTypeInformationUnitTests {
assertThat(discoverer.getType()).isEqualTo(ConcreteWrapper.class);
assertOptional(discoverer.getProperty("wrapped")).andAssert(inner -> {
inner.value(it -> it.getType()).isEqualTo(GenericType.class);
inner.flatMap(it -> it.getProperty("content")).value(it -> it.getType()).isEqualTo(String.class);
inner.value(TypeInformation::getType).isEqualTo(GenericType.class);
inner.flatMap(it -> it.getProperty("content")).value(TypeInformation::getType).isEqualTo(String.class);
});
assertOptional(discoverer.getProperty("wrapped.content")).value(it -> it.getType()).isEqualTo(String.class);
assertOptional(discoverer.getProperty("wrapped.content")).value(TypeInformation::getType).isEqualTo(String.class);
}
@Test
@@ -72,7 +72,7 @@ public class ClassTypeInformationUnitTests {
public void discoversBoundType() {
TypeInformation<GenericTypeWithBound> information = ClassTypeInformation.from(GenericTypeWithBound.class);
assertOptional(information.getProperty("person")).value(it -> it.getType()).isEqualTo(Person.class);
assertOptional(information.getProperty("person")).value(TypeInformation::getType).isEqualTo(Person.class);
}
@Test
@@ -80,7 +80,7 @@ public class ClassTypeInformationUnitTests {
TypeInformation<SpecialGenericTypeWithBound> information = ClassTypeInformation
.from(SpecialGenericTypeWithBound.class);
assertOptional(information.getProperty("person")).value(it -> it.getType()).isEqualTo(SpecialPerson.class);
assertOptional(information.getProperty("person")).value(TypeInformation::getType).isEqualTo(SpecialPerson.class);
}
@Test
@@ -89,8 +89,8 @@ public class ClassTypeInformationUnitTests {
TypeInformation<AnotherGenericType> information = ClassTypeInformation.from(AnotherGenericType.class);
assertOptional(information.getProperty("nested")).value(it -> it.getType()).isEqualTo(GenericTypeWithBound.class);
assertOptional(information.getProperty("nested.person")).value(it -> it.getType()).isEqualTo(Person.class);
assertOptional(information.getProperty("nested")).value(TypeInformation::getType).isEqualTo(GenericTypeWithBound.class);
assertOptional(information.getProperty("nested.person")).value(TypeInformation::getType).isEqualTo(Person.class);
}
@Test
@@ -100,25 +100,25 @@ public class ClassTypeInformationUnitTests {
OptionalAssert<TypeInformation<?>> optional = assertOptional(information.getProperty("array"));
optional.flatMap(it -> it.getComponentType()).value(it -> it.getType()).isEqualTo(String.class);
optional.value(it -> it.getType()).satisfies(it -> {
optional.flatMap(TypeInformation::getComponentType).value(TypeInformation::getType).isEqualTo(String.class);
optional.value(TypeInformation::getType).satisfies(it -> {
assertThat(it).isEqualTo(String[].class);
assertThat(it.isArray()).isTrue();
});
optional = assertOptional(information.getProperty("foo"));
optional.value(it -> it.getType()).isEqualTo(Collection[].class);
optional.flatMap(it -> it.getComponentType()).andAssert(it -> {
it.value(inner -> inner.getType()).isEqualTo(Collection.class);
it.flatMap(inner -> inner.getComponentType()).value(inner -> inner.getType()).isEqualTo(String.class);
optional.value(TypeInformation::getType).isEqualTo(Collection[].class);
optional.flatMap(TypeInformation::getComponentType).andAssert(it -> {
it.value(TypeInformation::getType).isEqualTo(Collection.class);
it.flatMap(TypeInformation::getComponentType).value(TypeInformation::getType).isEqualTo(String.class);
});
optional = assertOptional(information.getProperty("rawSet"));
optional.value(it -> it.getType()).isEqualTo(Set.class);
optional.flatMap(it -> it.getComponentType()).value(it -> it.getType()).isEqualTo(Object.class);
optional.flatMap(it -> it.getMapValueType()).isNotPresent();
optional.value(TypeInformation::getType).isEqualTo(Set.class);
optional.flatMap(TypeInformation::getComponentType).value(TypeInformation::getType).isEqualTo(Object.class);
optional.flatMap(TypeInformation::getMapValueType).isNotPresent();
}
@Test
@@ -127,13 +127,13 @@ public class ClassTypeInformationUnitTests {
TypeInformation<StringMapContainer> information = ClassTypeInformation.from(StringMapContainer.class);
OptionalAssert<TypeInformation<?>> assertion = assertOptional(information.getProperty("genericMap"));
assertion.value(it -> it.getType()).isEqualTo(Map.class);
assertion.flatMap(it -> it.getMapValueType()).value(it -> it.getType()).isEqualTo(String.class);
assertion.value(TypeInformation::getType).isEqualTo(Map.class);
assertion.flatMap(TypeInformation::getMapValueType).value(TypeInformation::getType).isEqualTo(String.class);
assertion = assertOptional(information.getProperty("map"));
assertion.value(it -> it.getType()).isEqualTo(Map.class);
assertion.flatMap(it -> it.getMapValueType()).value(it -> it.getType()).isEqualTo(Calendar.class);
assertion.value(TypeInformation::getType).isEqualTo(Map.class);
assertion.flatMap(TypeInformation::getMapValueType).value(TypeInformation::getType).isEqualTo(Calendar.class);
}
@Test
@@ -150,8 +150,8 @@ public class ClassTypeInformationUnitTests {
TypeInformation<PropertyGetter> from = ClassTypeInformation.from(PropertyGetter.class);
assertOptional(from.getProperty("_name")).value(it -> it.getType()).isEqualTo(String.class);
assertOptional(from.getProperty("name")).value(it -> it.getType()).isEqualTo(byte[].class);
assertOptional(from.getProperty("_name")).value(TypeInformation::getType).isEqualTo(String.class);
assertOptional(from.getProperty("name")).value(TypeInformation::getType).isEqualTo(byte[].class);
}
@Test // DATACMNS-77
@@ -168,15 +168,15 @@ public class ClassTypeInformationUnitTests {
OptionalAssert<TypeInformation<?>> assertion = assertOptional(information.getProperty("wildcard"));
assertion.value(it -> it.isCollectionLike()).isEqualTo(true);
assertion.flatMap(it -> it.getComponentType()).value(it -> it.getType()).isEqualTo(String.class);
assertion.value(TypeInformation::isCollectionLike).isEqualTo(true);
assertion.flatMap(TypeInformation::getComponentType).value(TypeInformation::getType).isEqualTo(String.class);
assertion = assertOptional(information.getProperty("complexWildcard"));
assertion.value(it -> it.isCollectionLike()).isEqualTo(true);
assertion.flatMap(it -> it.getComponentType()).andAssert(it -> {
it.value(inner -> inner.isCollectionLike()).isEqualTo(true);
it.flatMap(inner -> inner.getComponentType()).value(inner -> inner.getType()).isEqualTo(String.class);
assertion.value(TypeInformation::isCollectionLike).isEqualTo(true);
assertion.flatMap(TypeInformation::getComponentType).andAssert(it -> {
it.value(TypeInformation::isCollectionLike).isEqualTo(true);
it.flatMap(TypeInformation::getComponentType).value(TypeInformation::getType).isEqualTo(String.class);
});
}
@@ -266,7 +266,7 @@ public class ClassTypeInformationUnitTests {
TypeInformation<?> information = from(String[][].class);
assertThat(information.getType()).isEqualTo(String[][].class);
assertOptional(information.getComponentType()).value(it -> it.getType()).isEqualTo(String[].class);
assertOptional(information.getComponentType()).value(TypeInformation::getType).isEqualTo(String[].class);
assertThat(information.getActualType().getActualType().getType()).isEqualTo(String.class);
}
@@ -299,17 +299,17 @@ public class ClassTypeInformationUnitTests {
assertion//
// Type
.andAssert(inner -> inner.value(it -> it.getType()).isEqualTo(SortedMap.class))//
.andAssert(inner -> inner.value(TypeInformation::getType).isEqualTo(SortedMap.class))//
// Map value type
.andAssert(inner -> inner.flatMap(it -> it.getMapValueType()).andAssert(value -> {
value.value(it -> it.getType()).isEqualTo(SortedMap.class);
value.flatMap(it -> it.getComponentType()).value(it -> it.getType()).isEqualTo(String.class);
.andAssert(inner -> inner.flatMap(TypeInformation::getMapValueType).andAssert(value -> {
value.value(TypeInformation::getType).isEqualTo(SortedMap.class);
value.flatMap(TypeInformation::getComponentType).value(TypeInformation::getType).isEqualTo(String.class);
// Nested value type
}).flatMap(it -> it.getMapValueType()).andAssert(nestedValue -> {
nestedValue.value(it -> it.getType()).isEqualTo(List.class);
nestedValue.flatMap(it -> it.getComponentType()).value(it -> it.getType()).isEqualTo(Person.class);
}).flatMap(TypeInformation::getMapValueType).andAssert(nestedValue -> {
nestedValue.value(TypeInformation::getType).isEqualTo(List.class);
nestedValue.flatMap(TypeInformation::getComponentType).value(TypeInformation::getType).isEqualTo(Person.class);
}));
}
@@ -325,9 +325,9 @@ public class ClassTypeInformationUnitTests {
ClassTypeInformation<ConcreteRoot> rootType = from(ConcreteRoot.class);
assertOptional(rootType.getProperty("subs"))//
.map(it -> it.getActualType())//
.map(TypeInformation::getActualType)//
.flatMap(it -> it.getProperty("subSub"))//
.value(it -> it.getType()).isEqualTo(ConcreteSubSub.class);
.value(TypeInformation::getType).isEqualTo(ConcreteSubSub.class);
}
@Test // DATACMNS-594
@@ -335,7 +335,7 @@ public class ClassTypeInformationUnitTests {
assertOptional(ClassTypeInformation.from(ConcreteRootIntermediate.class)
.getProperty("intermediate.content.intermediate.content"))//
.value(it -> it.getType()).isEqualTo(Leaf.class);
.value(TypeInformation::getType).isEqualTo(Leaf.class);
}
@Test // DATACMNS-783, DATACMNS-853
@@ -346,9 +346,9 @@ public class ClassTypeInformationUnitTests {
assertOptional(root.getProperty("abstractBar"))//
.map(it -> it.specialize(ClassTypeInformation.from(Bar.class)))//
.andAssert(inner -> {
inner.value(it -> it.getType()).isEqualTo(Bar.class);
inner.flatMap(it -> it.getProperty("field")).value(it -> it.getType()).isEqualTo(Character.class);
inner.flatMap(it -> it.getProperty("anotherField")).value(it -> it.getType()).isEqualTo(Integer.class);
inner.value(TypeInformation::getType).isEqualTo(Bar.class);
inner.flatMap(it -> it.getProperty("field")).value(TypeInformation::getType).isEqualTo(Character.class);
inner.flatMap(it -> it.getProperty("anotherField")).value(TypeInformation::getType).isEqualTo(Integer.class);
});
}
@@ -385,7 +385,7 @@ public class ClassTypeInformationUnitTests {
ClassTypeInformation<Concrete> information = ClassTypeInformation.from(Concrete.class);
assertOptional(information.getProperty("field")).value(it -> it.getType()).isEqualTo(Nested.class);
assertOptional(information.getProperty("field")).value(TypeInformation::getType).isEqualTo(Nested.class);
}
@Test // DATACMNS-940
@@ -393,9 +393,7 @@ public class ClassTypeInformationUnitTests {
ClassTypeInformation<SampleTraversable> information = ClassTypeInformation.from(SampleTraversable.class);
assertThat(information.getComponentType()).hasValueSatisfying(it -> {
assertThat(it.getType()).isAssignableFrom(Integer.class);
});
assertThat(information.getComponentType()).hasValueSatisfying(it -> assertThat(it.getType()).isAssignableFrom(Integer.class));
}
@Test // DATACMNS-940
@@ -403,13 +401,9 @@ public class ClassTypeInformationUnitTests {
ClassTypeInformation<SampleMap> information = ClassTypeInformation.from(SampleMap.class);
assertThat(information.getComponentType()).hasValueSatisfying(it -> {
assertThat(it.getType()).isAssignableFrom(String.class);
});
assertThat(information.getComponentType()).hasValueSatisfying(it -> assertThat(it.getType()).isAssignableFrom(String.class));
assertThat(information.getMapValueType()).hasValueSatisfying(it -> {
assertThat(it.getType()).isAssignableFrom(Integer.class);
});
assertThat(information.getMapValueType()).hasValueSatisfying(it -> assertThat(it.getType()).isAssignableFrom(Integer.class));
}
static class StringMapContainer extends MapContainer<String> {

View File

@@ -37,16 +37,16 @@ public class DataCmns511Tests {
ClassTypeInformation.from(AbstractRole.class).getProperty("createdBy"));
assertion.flatMap(it -> it.getProperty("roles"))//
.map(it -> it.getActualType())//
.map(TypeInformation::getActualType)//
.flatMap(it -> it.getProperty("createdBy"))//
.andAssert(second -> {
OptionalAssert<TypeInformation<?>> third = second.flatMap(it -> it.getProperty("roles"))//
.map(it -> it.getActualType())//
.map(TypeInformation::getActualType)//
.flatMap(it -> it.getProperty("createdBy"));
second.isEqualTo(third);
second.value(it -> it.hashCode()).isEqualTo(third.getActual().hashCode());
second.value(Object::hashCode).isEqualTo(third.getActual().hashCode());
});
}

View File

@@ -35,7 +35,7 @@ public class OptionalAssert<T> extends org.assertj.core.api.OptionalAssert<T> {
}
public static <T> OptionalAssert<T> assertOptional(Optional<T> optional) {
return new OptionalAssert<T>(optional);
return new OptionalAssert<>(optional);
}
public Optional<T> getActual() {
@@ -60,7 +60,7 @@ public class OptionalAssert<T> extends org.assertj.core.api.OptionalAssert<T> {
Assertions.assertThat(actual).isPresent();
return Assertions.assertThat(actual.map(function).orElseThrow(() -> new IllegalStateException()));
return Assertions.assertThat(actual.map(function).orElseThrow(IllegalStateException::new));
}
public OptionalAssert<T> isEqualTo(OptionalAssert<?> other) {

View File

@@ -85,19 +85,19 @@ public class ParameterizedTypeUnitTests {
OptionalAssert<TypeInformation<?>> assertion = assertOptional(propertyType);
assertion.flatMap(it -> it.getProperty("value")).value(it -> it.getType()).isEqualTo(String.class);
assertion.flatMap(it -> it.getMapValueType()).value(it -> it.getType()).isEqualTo(String.class);
assertion.flatMap(it -> it.getProperty("value")).value(TypeInformation::getType).isEqualTo(String.class);
assertion.flatMap(TypeInformation::getMapValueType).value(TypeInformation::getType).isEqualTo(String.class);
propertyType = type.getProperty("param2");
assertion.flatMap(it -> it.getProperty("value")).value(it -> it.getType()).isEqualTo(String.class);
assertion.flatMap(it -> it.getMapValueType()).value(it -> it.getType()).isEqualTo(String.class);
assertion.flatMap(it -> it.getProperty("value")).value(TypeInformation::getType).isEqualTo(String.class);
assertion.flatMap(TypeInformation::getMapValueType).value(TypeInformation::getType).isEqualTo(String.class);
}
@Test // DATACMNS-446
public void createsToStringRepresentation() {
assertOptional(from(Foo.class).getProperty("param")).value(it -> it.toString())
assertOptional(from(Foo.class).getProperty("param")).value(Object::toString)
.isEqualTo("org.springframework.data.util.ParameterizedTypeUnitTests$Localized<java.lang.String>");
}
@@ -110,11 +110,7 @@ public class ParameterizedTypeUnitTests {
assertThat(first).isEqualTo(second);
assertThat(first).hasValueSatisfying(left -> {
assertThat(second).hasValueSatisfying(right -> {
assertThat(left.hashCode()).isEqualTo(right.hashCode());
});
});
assertThat(first).hasValueSatisfying(left -> assertThat(second).hasValueSatisfying(right -> assertThat(left.hashCode()).isEqualTo(right.hashCode())));
}
@Test // DATACMNS-485
@@ -123,7 +119,7 @@ public class ParameterizedTypeUnitTests {
Optional<TypeInformation<?>> type = from(First.class).getProperty("property");
assertOptional(type).map(it -> it.getActualType()).isEqualTo(type);
assertOptional(type).map(TypeInformation::getActualType).isEqualTo(type);
}
@Test // DATACMNS-697
@@ -132,9 +128,9 @@ public class ParameterizedTypeUnitTests {
TypeInformation<NormalizedProfile> information = ClassTypeInformation.from(NormalizedProfile.class);
assertOptional(information.getProperty("education2.data"))//
.flatMap(it -> it.getComponentType())//
.flatMap(TypeInformation::getComponentType)//
.flatMap(it -> it.getProperty("value"))//
.value(it -> it.getType())//
.value(TypeInformation::getType)//
.isEqualTo(Education.class);
}
@@ -145,7 +141,7 @@ public class ParameterizedTypeUnitTests {
ClassTypeInformation.from(Bar.class).getProperty("param"));
assertion.hasValueSatisfying(it -> assertThat(it).isInstanceOf(ParameterizedTypeInformation.class));
assertion.flatMap(it -> it.getMapValueType()).isEmpty();
assertion.flatMap(TypeInformation::getMapValueType).isEmpty();
}
@SuppressWarnings("serial")

View File

@@ -38,7 +38,7 @@ public class StreamUtilsTests {
List<String> input = Arrays.asList("a", "b", "c");
Stream<String> stream = createStreamFromIterator(input.iterator());
List<String> output = stream.collect(Collectors.<String> toList());
List<String> output = stream.collect(Collectors.toList());
assertThat(input).isEqualTo(output);
}

View File

@@ -75,9 +75,9 @@ public class TypeDiscovererUnitTests {
public void dealsWithTypesReferencingThemselves() {
TypeInformation<SelfReferencing> information = from(SelfReferencing.class);
Optional<TypeInformation<?>> first = information.getProperty("parent").flatMap(it -> it.getMapValueType());
Optional<TypeInformation<?>> first = information.getProperty("parent").flatMap(TypeInformation::getMapValueType);
Optional<TypeInformation<?>> second = first.flatMap(it -> it.getProperty("map"))
.flatMap(it -> it.getMapValueType());
.flatMap(TypeInformation::getMapValueType);
assertThat(second).isEqualTo(first);
}
@@ -88,9 +88,7 @@ public class TypeDiscovererUnitTests {
TypeInformation<SelfReferencingMap> information = from(SelfReferencingMap.class);
Optional<TypeInformation<?>> property = information.getProperty("map");
assertThat(property).hasValueSatisfying(it -> {
assertThat(it.getMapValueType()).hasValue(information);
});
assertThat(property).hasValueSatisfying(it -> assertThat(it.getMapValueType()).hasValue(information));
}
@Test
@@ -98,13 +96,9 @@ public class TypeDiscovererUnitTests {
TypeInformation<?> discoverer = new TypeDiscoverer<>(CustomMap.class, EMPTY_MAP);
assertThat(discoverer.getMapValueType()).hasValueSatisfying(it -> {
assertThat(it.getType()).isEqualTo(Locale.class);
});
assertThat(discoverer.getMapValueType()).hasValueSatisfying(it -> assertThat(it.getType()).isEqualTo(Locale.class));
assertThat(discoverer.getComponentType()).hasValueSatisfying(it -> {
assertThat(it.getType()).isEqualTo(String.class);
});
assertThat(discoverer.getComponentType()).hasValueSatisfying(it -> assertThat(it.getType()).isEqualTo(String.class));
}
@Test
@@ -112,19 +106,15 @@ public class TypeDiscovererUnitTests {
TypeDiscoverer<CustomCollection> discoverer = new TypeDiscoverer<>(CustomCollection.class, firstMap);
assertThat(discoverer.getComponentType()).hasValueSatisfying(it -> {
assertThat(it.getType()).isEqualTo(String.class);
});
assertThat(discoverer.getComponentType()).hasValueSatisfying(it -> assertThat(it.getType()).isEqualTo(String.class));
}
@Test
public void returnsComponentTypeForArrays() {
TypeDiscoverer<String[]> discoverer = new TypeDiscoverer<String[]>(String[].class, EMPTY_MAP);
TypeDiscoverer<String[]> discoverer = new TypeDiscoverer<>(String[].class, EMPTY_MAP);
assertThat(discoverer.getComponentType()).hasValueSatisfying(it -> {
assertThat(it.getType()).isEqualTo(String.class);
});
assertThat(discoverer.getComponentType()).hasValueSatisfying(it -> assertThat(it.getType()).isEqualTo(String.class));
}
@Test // DATACMNS-57
@@ -137,9 +127,7 @@ public class TypeDiscovererUnitTests {
assertThat(types).hasSize(2);
assertThat(types.get(0).getType()).isEqualTo(List.class);
assertThat(types.get(0).getComponentType()).hasValueSatisfying(it -> {
assertThat(it.getType()).isEqualTo(String.class);
});
assertThat(types.get(0).getComponentType()).hasValueSatisfying(it -> assertThat(it.getType()).isEqualTo(String.class));
}
@Test

View File

@@ -22,9 +22,7 @@ public class TypeInformationAssert extends AbstractAssert<TypeInformationAssert,
public TypeInformationAssert hasComponentType(Class<?> type) {
Assertions.assertThat(actual.getComponentType()).hasValueSatisfying(it -> {
Assertions.assertThat(it.getType()).isEqualTo(type);
});
Assertions.assertThat(actual.getComponentType()).hasValueSatisfying(it -> Assertions.assertThat(it.getType()).isEqualTo(type));
return this;
}

View File

@@ -157,7 +157,7 @@ public class VersionUnitTests {
public void rejectsNonNumericPartOnNonLastPosition() {
exception.expect(IllegalArgumentException.class);
exception.expectCause(Matchers.<Throwable> instanceOf(IllegalArgumentException.class));
exception.expectCause(Matchers.instanceOf(IllegalArgumentException.class));
exception.expectMessage("1.RELEASE.2");
Version.parse("1.RELEASE.2");

View File

@@ -49,7 +49,7 @@ public class MapDataBinderUnitTests {
MutablePropertyValues values = new MutablePropertyValues();
values.add("foo.date", new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(reference));
Map<String, Object> nested = new HashMap<String, Object>();
Map<String, Object> nested = new HashMap<>();
nested.put("date", reference);
assertThat(bind(values)).containsEntry("foo", nested);
@@ -67,7 +67,7 @@ public class MapDataBinderUnitTests {
List<String> list = new ArrayList<>();
list.add("String");
assertThat(result).isEqualTo((Map) singletonMap("foo", singletonMap("bar", singletonMap("fooBar", list))));
assertThat(result).isEqualTo(singletonMap("foo", singletonMap("bar", singletonMap("fooBar", list))));
}
@Test // DATACMNS-630
@@ -80,11 +80,11 @@ public class MapDataBinderUnitTests {
Map<String, Object> result = bind(values);
Map<String, Object> dave = new HashMap<String, Object>();
Map<String, Object> dave = new HashMap<>();
dave.put("firstname", "Dave");
dave.put("lastname", "Matthews");
assertThat(result).isEqualTo((Map) singletonMap("foo", dave));
assertThat(result).isEqualTo(singletonMap("foo", dave));
}
@Test // DATACMNS-630

View File

@@ -69,7 +69,7 @@ public abstract class PageableDefaultUnitTests {
@Test
public void returnsDefaultIfNoRequestParametersAndNoDefault() throws Exception {
assertSupportedAndResult(getParameterOfMethod("supportedMethod"), (Pageable) ReflectionTestUtils
assertSupportedAndResult(getParameterOfMethod("supportedMethod"), ReflectionTestUtils
.invokeMethod(ReflectionTestUtils.getField(getResolver(), "fallbackPageable"), "get"));
}

View File

@@ -253,7 +253,7 @@ public class PagedResourcesAssemblerUnitTests {
Person person = new Person();
person.name = "Dave";
return new PageImpl<>(Arrays.asList(person), request, 3);
return new PageImpl<>(Collections.singletonList(person), request, 3);
}
private static Map<String, String> getQueryParameters(Link link) {

View File

@@ -18,6 +18,7 @@ package org.springframework.data.web.config;
import static org.assertj.core.api.Assertions.*;
import java.util.Arrays;
import java.util.Collections;
import org.junit.Before;
import org.junit.Test;
@@ -99,7 +100,7 @@ public class PageableResourcesAssemblerIntegrationTests {
@RequestMapping("/persons")
PagedResources<Resource<Person>> sample(Pageable pageable) {
Page<Person> page = new PageImpl<>(Arrays.asList(new Person()), pageable,
Page<Person> page = new PageImpl<>(Collections.singletonList(new Person()), pageable,
pageable.getOffset() + pageable.getPageSize() + 1);
return assembler.toResource(page);

View File

@@ -97,7 +97,7 @@ public class QuerydslPredicateArgumentResolverUnitTests {
request.addParameter("firstname", "rand");
Predicate predicate = (BooleanExpression) resolver.resolveArgument(
Predicate predicate = resolver.resolveArgument(
getMethodParameterFor("simpleFind", Predicate.class), null, new ServletWebRequest(request), null);
assertThat(predicate).isEqualTo((Predicate) QUser.user.firstname.eq("rand"));
@@ -157,7 +157,7 @@ public class QuerydslPredicateArgumentResolverUnitTests {
request.addParameter("inceptionYear", "978");
Predicate predicate = (BooleanExpression) resolver.resolveArgument(
Predicate predicate = resolver.resolveArgument(
getMethodParameterFor("specificFind", Predicate.class), null, new ServletWebRequest(request), null);
assertThat(predicate).isEqualTo((Predicate) QUser.user.inceptionYear.eq(978L));
@@ -168,7 +168,7 @@ public class QuerydslPredicateArgumentResolverUnitTests {
request.addParameter("inceptionYear", new String[] { "978", "998" });
Predicate predicate = (BooleanExpression) resolver.resolveArgument(
Predicate predicate = resolver.resolveArgument(
getMethodParameterFor("specificFind", Predicate.class), null, new ServletWebRequest(request), null);
assertThat(predicate).isEqualTo((Predicate) QUser.user.inceptionYear.in(978L, 998L));