Use lambdas when possible
Replace anonymous inner classes with lambda declarations (when possible using method references). See gh-9781
This commit is contained in:
committed by
Phillip Webb
parent
d16af43664
commit
2626a3a795
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -1307,14 +1307,7 @@ public class JsonContentAssertTests {
|
||||
}
|
||||
|
||||
private AssertProvider<JsonContentAssert> forJson(final String json) {
|
||||
return new AssertProvider<JsonContentAssert>() {
|
||||
|
||||
@Override
|
||||
public JsonContentAssert assertThat() {
|
||||
return new JsonContentAssert(JsonContentAssertTests.class, json);
|
||||
}
|
||||
|
||||
};
|
||||
return () -> new JsonContentAssert(JsonContentAssertTests.class, json);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -73,14 +73,7 @@ public class ObjectContentAssertTests {
|
||||
}
|
||||
|
||||
private AssertProvider<ObjectContentAssert<Object>> forObject(final Object source) {
|
||||
return new AssertProvider<ObjectContentAssert<Object>>() {
|
||||
|
||||
@Override
|
||||
public ObjectContentAssert<Object> assertThat() {
|
||||
return new ObjectContentAssert<>(source);
|
||||
}
|
||||
|
||||
};
|
||||
return () -> new ObjectContentAssert<>(source);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -71,14 +71,7 @@ public class MockBeanForBeanFactoryIntegrationTests {
|
||||
|
||||
@Override
|
||||
public TestBean getObject() throws Exception {
|
||||
return new TestBean() {
|
||||
|
||||
@Override
|
||||
public String hello() {
|
||||
return "normal";
|
||||
}
|
||||
|
||||
};
|
||||
return () -> "normal";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.boot.test.mock.web;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLDecoder;
|
||||
@@ -87,12 +86,8 @@ public class SpringBootMockServletContextTests implements ServletContextAware {
|
||||
assertThat(resource).isNotEqualTo(nullValue());
|
||||
File file = new File(URLDecoder.decode(resource.getPath(), "UTF-8"));
|
||||
assertThat(file).exists().isDirectory();
|
||||
String[] contents = file.list(new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File dir, String name) {
|
||||
return !(".".equals(name) || "..".equals(name));
|
||||
}
|
||||
});
|
||||
String[] contents = file
|
||||
.list((dir, name) -> !(".".equals(name) || "..".equals(name)));
|
||||
assertThat(contents).isNotEqualTo(nullValue());
|
||||
assertThat(contents.length).isEqualTo(0);
|
||||
}
|
||||
|
||||
@@ -154,13 +154,7 @@ public class TestRestTemplateTests {
|
||||
return mock(type);
|
||||
}
|
||||
|
||||
}, new ReflectionUtils.MethodFilter() {
|
||||
@Override
|
||||
public boolean matches(Method method) {
|
||||
return Modifier.isPublic(method.getModifiers());
|
||||
}
|
||||
|
||||
});
|
||||
}, (method) -> Modifier.isPublic(method.getModifiers()));
|
||||
|
||||
}
|
||||
|
||||
@@ -217,209 +211,99 @@ public class TestRestTemplateTests {
|
||||
|
||||
@Test
|
||||
public void deleteHandlesRelativeUris() throws IOException {
|
||||
verifyRelativeUriHandling(new TestRestTemplateCallback() {
|
||||
|
||||
@Override
|
||||
public void doWithTestRestTemplate(TestRestTemplate testRestTemplate,
|
||||
URI relativeUri) {
|
||||
testRestTemplate.delete(relativeUri);
|
||||
}
|
||||
|
||||
});
|
||||
verifyRelativeUriHandling(TestRestTemplate::delete);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exchangeWithRequestEntityAndClassHandlesRelativeUris()
|
||||
throws IOException {
|
||||
verifyRelativeUriHandling(new TestRestTemplateCallback() {
|
||||
|
||||
@Override
|
||||
public void doWithTestRestTemplate(TestRestTemplate testRestTemplate,
|
||||
URI relativeUri) {
|
||||
testRestTemplate.exchange(
|
||||
new RequestEntity<String>(HttpMethod.GET, relativeUri),
|
||||
String.class);
|
||||
}
|
||||
|
||||
});
|
||||
verifyRelativeUriHandling((testRestTemplate, relativeUri) -> testRestTemplate
|
||||
.exchange(new RequestEntity<String>(HttpMethod.GET, relativeUri),
|
||||
String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exchangeWithRequestEntityAndParameterizedTypeReferenceHandlesRelativeUris()
|
||||
throws IOException {
|
||||
verifyRelativeUriHandling(new TestRestTemplateCallback() {
|
||||
|
||||
@Override
|
||||
public void doWithTestRestTemplate(TestRestTemplate testRestTemplate,
|
||||
URI relativeUri) {
|
||||
testRestTemplate.exchange(
|
||||
new RequestEntity<String>(HttpMethod.GET, relativeUri),
|
||||
verifyRelativeUriHandling((testRestTemplate, relativeUri) -> testRestTemplate
|
||||
.exchange(new RequestEntity<String>(HttpMethod.GET, relativeUri),
|
||||
new ParameterizedTypeReference<String>() {
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exchangeHandlesRelativeUris() throws IOException {
|
||||
verifyRelativeUriHandling(new TestRestTemplateCallback() {
|
||||
|
||||
@Override
|
||||
public void doWithTestRestTemplate(TestRestTemplate testRestTemplate,
|
||||
URI relativeUri) {
|
||||
testRestTemplate.exchange(relativeUri, HttpMethod.GET,
|
||||
new HttpEntity<>(new byte[0]), String.class);
|
||||
}
|
||||
|
||||
});
|
||||
verifyRelativeUriHandling(
|
||||
(testRestTemplate, relativeUri) -> testRestTemplate.exchange(relativeUri,
|
||||
HttpMethod.GET, new HttpEntity<>(new byte[0]), String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exchangeWithParameterizedTypeReferenceHandlesRelativeUris()
|
||||
throws IOException {
|
||||
verifyRelativeUriHandling(new TestRestTemplateCallback() {
|
||||
|
||||
@Override
|
||||
public void doWithTestRestTemplate(TestRestTemplate testRestTemplate,
|
||||
URI relativeUri) {
|
||||
testRestTemplate.exchange(relativeUri, HttpMethod.GET,
|
||||
new HttpEntity<>(new byte[0]),
|
||||
verifyRelativeUriHandling(
|
||||
(testRestTemplate, relativeUri) -> testRestTemplate.exchange(relativeUri,
|
||||
HttpMethod.GET, new HttpEntity<>(new byte[0]),
|
||||
new ParameterizedTypeReference<String>() {
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void executeHandlesRelativeUris() throws IOException {
|
||||
verifyRelativeUriHandling(new TestRestTemplateCallback() {
|
||||
|
||||
@Override
|
||||
public void doWithTestRestTemplate(TestRestTemplate testRestTemplate,
|
||||
URI relativeUri) {
|
||||
testRestTemplate.execute(relativeUri, HttpMethod.GET, null, null);
|
||||
}
|
||||
|
||||
});
|
||||
verifyRelativeUriHandling((testRestTemplate, relativeUri) -> testRestTemplate
|
||||
.execute(relativeUri, HttpMethod.GET, null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getForEntityHandlesRelativeUris() throws IOException {
|
||||
verifyRelativeUriHandling(new TestRestTemplateCallback() {
|
||||
|
||||
@Override
|
||||
public void doWithTestRestTemplate(TestRestTemplate testRestTemplate,
|
||||
URI relativeUri) {
|
||||
testRestTemplate.getForEntity(relativeUri, String.class);
|
||||
}
|
||||
|
||||
});
|
||||
verifyRelativeUriHandling((testRestTemplate, relativeUri) -> testRestTemplate
|
||||
.getForEntity(relativeUri, String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getForObjectHandlesRelativeUris() throws IOException {
|
||||
verifyRelativeUriHandling(new TestRestTemplateCallback() {
|
||||
|
||||
@Override
|
||||
public void doWithTestRestTemplate(TestRestTemplate testRestTemplate,
|
||||
URI relativeUri) {
|
||||
testRestTemplate.getForObject(relativeUri, String.class);
|
||||
}
|
||||
|
||||
});
|
||||
verifyRelativeUriHandling((testRestTemplate, relativeUri) -> testRestTemplate
|
||||
.getForObject(relativeUri, String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void headForHeadersHandlesRelativeUris() throws IOException {
|
||||
verifyRelativeUriHandling(new TestRestTemplateCallback() {
|
||||
|
||||
@Override
|
||||
public void doWithTestRestTemplate(TestRestTemplate testRestTemplate,
|
||||
URI relativeUri) {
|
||||
testRestTemplate.headForHeaders(relativeUri);
|
||||
}
|
||||
|
||||
});
|
||||
verifyRelativeUriHandling(TestRestTemplate::headForHeaders);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void optionsForAllowHandlesRelativeUris() throws IOException {
|
||||
verifyRelativeUriHandling(new TestRestTemplateCallback() {
|
||||
|
||||
@Override
|
||||
public void doWithTestRestTemplate(TestRestTemplate testRestTemplate,
|
||||
URI relativeUri) {
|
||||
testRestTemplate.optionsForAllow(relativeUri);
|
||||
}
|
||||
|
||||
});
|
||||
verifyRelativeUriHandling(TestRestTemplate::optionsForAllow);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void patchForObjectHandlesRelativeUris() throws IOException {
|
||||
verifyRelativeUriHandling(new TestRestTemplateCallback() {
|
||||
|
||||
@Override
|
||||
public void doWithTestRestTemplate(TestRestTemplate testRestTemplate,
|
||||
URI relativeUri) {
|
||||
testRestTemplate.patchForObject(relativeUri, "hello", String.class);
|
||||
}
|
||||
|
||||
});
|
||||
verifyRelativeUriHandling((testRestTemplate, relativeUri) -> testRestTemplate
|
||||
.patchForObject(relativeUri, "hello", String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postForEntityHandlesRelativeUris() throws IOException {
|
||||
verifyRelativeUriHandling(new TestRestTemplateCallback() {
|
||||
|
||||
@Override
|
||||
public void doWithTestRestTemplate(TestRestTemplate testRestTemplate,
|
||||
URI relativeUri) {
|
||||
testRestTemplate.postForEntity(relativeUri, "hello", String.class);
|
||||
}
|
||||
|
||||
});
|
||||
verifyRelativeUriHandling((testRestTemplate, relativeUri) -> testRestTemplate
|
||||
.postForEntity(relativeUri, "hello", String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postForLocationHandlesRelativeUris() throws IOException {
|
||||
verifyRelativeUriHandling(new TestRestTemplateCallback() {
|
||||
|
||||
@Override
|
||||
public void doWithTestRestTemplate(TestRestTemplate testRestTemplate,
|
||||
URI relativeUri) {
|
||||
testRestTemplate.postForLocation(relativeUri, "hello");
|
||||
}
|
||||
|
||||
});
|
||||
verifyRelativeUriHandling((testRestTemplate, relativeUri) -> testRestTemplate
|
||||
.postForLocation(relativeUri, "hello"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postForObjectHandlesRelativeUris() throws IOException {
|
||||
verifyRelativeUriHandling(new TestRestTemplateCallback() {
|
||||
|
||||
@Override
|
||||
public void doWithTestRestTemplate(TestRestTemplate testRestTemplate,
|
||||
URI relativeUri) {
|
||||
testRestTemplate.postForObject(relativeUri, "hello", String.class);
|
||||
}
|
||||
|
||||
});
|
||||
verifyRelativeUriHandling((testRestTemplate, relativeUri) -> testRestTemplate
|
||||
.postForObject(relativeUri, "hello", String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void putHandlesRelativeUris() throws IOException {
|
||||
verifyRelativeUriHandling(new TestRestTemplateCallback() {
|
||||
|
||||
@Override
|
||||
public void doWithTestRestTemplate(TestRestTemplate testRestTemplate,
|
||||
URI relativeUri) {
|
||||
testRestTemplate.put(relativeUri, "hello");
|
||||
}
|
||||
|
||||
});
|
||||
verifyRelativeUriHandling((testRestTemplate, relativeUri) -> testRestTemplate
|
||||
.put(relativeUri, "hello"));
|
||||
}
|
||||
|
||||
private void verifyRelativeUriHandling(TestRestTemplateCallback callback)
|
||||
|
||||
Reference in New Issue
Block a user