Replace this lambda with a method reference

See gh-15401
This commit is contained in:
igor-suhorukov 2018-12-07 00:52:04 +03:00 committed by Stephane Nicoll
parent 71173f2db5
commit 5c1813aef8
13 changed files with 21 additions and 19 deletions

View File

@ -80,7 +80,7 @@ public class CloudFoundryWebEndpointDiscovererTests {
private void load(Class<?> configuration,
Consumer<CloudFoundryWebEndpointDiscoverer> consumer) {
this.load((id) -> null, (id) -> id.toString(), configuration, consumer);
this.load((id) -> null, EndpointId::toString, configuration, consumer);
}
private void load(Function<EndpointId, Long> timeToLive,

View File

@ -92,7 +92,7 @@ public class TokenTests {
String claims = "{\"exp\": 2147483647, \"iss\": \"http://localhost:8080/uaa/oauth/token\"}";
Token token = createToken(header, claims);
assertThatExceptionOfType(CloudFoundryAuthorizationException.class)
.isThrownBy(() -> token.getSignatureAlgorithm())
.isThrownBy(token::getSignatureAlgorithm)
.satisfies(reasonRequirement(Reason.INVALID_TOKEN));
}
@ -102,7 +102,7 @@ public class TokenTests {
String claims = "{\"exp\": 2147483647}";
Token token = createToken(header, claims);
assertThatExceptionOfType(CloudFoundryAuthorizationException.class)
.isThrownBy(() -> token.getIssuer())
.isThrownBy(token::getIssuer)
.satisfies(reasonRequirement(Reason.INVALID_TOKEN));
}
@ -112,7 +112,7 @@ public class TokenTests {
String claims = "{\"exp\": 2147483647}";
Token token = createToken(header, claims);
assertThatExceptionOfType(CloudFoundryAuthorizationException.class)
.isThrownBy(() -> token.getKeyId())
.isThrownBy(token::getKeyId)
.satisfies(reasonRequirement(Reason.INVALID_TOKEN));
}
@ -122,7 +122,7 @@ public class TokenTests {
String claims = "{\"iss\": \"http://localhost:8080/uaa/oauth/token\"" + "}";
Token token = createToken(header, claims);
assertThatExceptionOfType(CloudFoundryAuthorizationException.class)
.isThrownBy(() -> token.getExpiry())
.isThrownBy(token::getExpiry)
.satisfies(reasonRequirement(Reason.INVALID_TOKEN));
}

View File

@ -84,7 +84,7 @@ public class ServletEndpointManagementContextConfigurationTests {
@Bean
public ServletEndpointsSupplier servletEndpointsSupplier() {
return () -> Collections.emptyList();
return Collections::emptyList;
}
@Bean

View File

@ -61,7 +61,7 @@ public class JerseyWebEndpointManagementContextConfigurationTests {
@Bean
public WebEndpointsSupplier webEndpointsSupplier() {
return () -> Collections.emptyList();
return Collections::emptyList;
}
}

View File

@ -26,6 +26,7 @@ import org.glassfish.jersey.server.model.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
import org.springframework.boot.actuate.endpoint.EndpointId;
import org.springframework.boot.actuate.endpoint.http.ActuatorMediaType;
import org.springframework.boot.actuate.endpoint.invoke.convert.ConversionServiceParameterValueMapper;
import org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver;
@ -142,7 +143,7 @@ public class JerseyEndpointRequestIntegrationTests
mediaTypes);
WebEndpointDiscoverer discoverer = new WebEndpointDiscoverer(
this.applicationContext, new ConversionServiceParameterValueMapper(),
endpointMediaTypes, Arrays.asList((id) -> id.toString()),
endpointMediaTypes, Arrays.asList(EndpointId::toString),
Collections.emptyList(), Collections.emptyList());
Collection<Resource> resources = new JerseyEndpointResourceFactory()
.createEndpointResources(new EndpointMapping("/actuator"),

View File

@ -22,6 +22,7 @@ import java.util.List;
import org.junit.jupiter.api.Test;
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
import org.springframework.boot.actuate.endpoint.EndpointId;
import org.springframework.boot.actuate.endpoint.http.ActuatorMediaType;
import org.springframework.boot.actuate.endpoint.invoke.convert.ConversionServiceParameterValueMapper;
import org.springframework.boot.actuate.endpoint.web.EndpointLinksResolver;
@ -130,7 +131,7 @@ public class MvcEndpointRequestIntegrationTests
mediaTypes);
WebEndpointDiscoverer discoverer = new WebEndpointDiscoverer(
this.applicationContext, new ConversionServiceParameterValueMapper(),
endpointMediaTypes, Arrays.asList((id) -> id.toString()),
endpointMediaTypes, Arrays.asList(EndpointId::toString),
Collections.emptyList(), Collections.emptyList());
return new WebMvcEndpointHandlerMapping(new EndpointMapping("/actuator"),
discoverer.getEndpoints(), endpointMediaTypes,

View File

@ -182,7 +182,7 @@ public class WebEndpointDiscovererTests {
@Test
public void getEndpointsWhenHasCacheWithTtlShouldCacheReadOperationWithTtlValue() {
load((id) -> 500L, (id) -> id.toString(), TestEndpointConfiguration.class,
load((id) -> 500L, EndpointId::toString, TestEndpointConfiguration.class,
(discoverer) -> {
Map<EndpointId, ExposableWebEndpoint> endpoints = mapEndpoints(
discoverer.getEndpoints());
@ -246,7 +246,7 @@ public class WebEndpointDiscovererTests {
}
private void load(Class<?> configuration, Consumer<WebEndpointDiscoverer> consumer) {
this.load((id) -> null, (id) -> id.toString(), configuration, consumer);
this.load((id) -> null, EndpointId::toString, configuration, consumer);
}
private void load(Function<EndpointId, Long> timeToLive,

View File

@ -260,7 +260,7 @@ public class HttpExchangeTracerTests {
public void principalIsNotIncludedByDefault() {
HttpTrace trace = new HttpTrace(createRequest());
new HttpExchangeTracer(EnumSet.noneOf(Include.class)).sendingResponse(trace,
createResponse(), () -> createPrincipal(), null);
createResponse(), this::createPrincipal, null);
assertThat(trace.getPrincipal()).isNull();
}
@ -268,7 +268,7 @@ public class HttpExchangeTracerTests {
public void principalCanBeIncluded() {
HttpTrace trace = new HttpTrace(createRequest());
new HttpExchangeTracer(EnumSet.of(Include.PRINCIPAL)).sendingResponse(trace,
createResponse(), () -> createPrincipal(), null);
createResponse(), this::createPrincipal, null);
assertThat(trace.getPrincipal()).isNotNull();
assertThat(trace.getPrincipal().getName()).isEqualTo("alice");
}

View File

@ -72,7 +72,7 @@ public final class OAuth2ClientPropertiesRegistrationAdapter {
map.from(properties::getAuthorizationGrantType).as(AuthorizationGrantType::new)
.to(builder::authorizationGrantType);
map.from(properties::getRedirectUri).to(builder::redirectUriTemplate);
map.from(properties::getScope).as((scope) -> StringUtils.toStringArray(scope))
map.from(properties::getScope).as(StringUtils::toStringArray)
.to(builder::scope);
map.from(properties::getClientName).to(builder::clientName);
return builder.build();

View File

@ -794,7 +794,7 @@ public class WebMvcAutoConfigurationTests {
@Test
public void cachePeriod() {
this.contextRunner.withPropertyValues("spring.resources.cache.period:5")
.run((context) -> assertCachePeriod(context));
.run(this::assertCachePeriod);
}
private void assertCachePeriod(AssertableWebApplicationContext context) {
@ -817,7 +817,7 @@ public class WebMvcAutoConfigurationTests {
this.contextRunner
.withPropertyValues("spring.resources.cache.cachecontrol.max-age:5",
"spring.resources.cache.cachecontrol.proxy-revalidate:true")
.run((context) -> assertCacheControl(context));
.run(this::assertCacheControl);
}
@Test

View File

@ -44,7 +44,7 @@ public class RemoteUrlPropertyExtractorTests {
@Test
public void missingUrl() {
assertThatIllegalStateException().isThrownBy(() -> doTest())
assertThatIllegalStateException().isThrownBy(this::doTest)
.withMessageContaining("No remote URL specified");
}

View File

@ -132,7 +132,7 @@ public class ApplicationContextAssertProviderTests {
ApplicationContextAssertProvider<ApplicationContext> context = get(
this.startupFailureSupplier);
assertThatIllegalStateException()
.isThrownBy(() -> context.getSourceApplicationContext())
.isThrownBy(context::getSourceApplicationContext)
.withCause(this.startupFailure).withMessageContaining("failed to start");
}

View File

@ -67,7 +67,7 @@ public class BindResultTests {
public void getWhenHasNoValueShouldThrowException() {
BindResult<String> result = BindResult.of(null);
assertThatExceptionOfType(NoSuchElementException.class)
.isThrownBy(() -> result.get()).withMessageContaining("No value bound");
.isThrownBy(result::get).withMessageContaining("No value bound");
}
@Test