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

@@ -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());
}