Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Jul 30, 2019
1 parent 9a36027 commit c4622db
Show file tree
Hide file tree
Showing 17 changed files with 40 additions and 52 deletions.
Expand Up @@ -430,7 +430,7 @@ public boolean equals(Object other) {

@Override
public int hashCode() {
return 31 * super.hashCode() + ObjectUtils.nullSafeHashCode(this.containingClass);
return (31 * super.hashCode() + ObjectUtils.nullSafeHashCode(this.containingClass));
}


Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
Expand Down Expand Up @@ -144,7 +144,7 @@ public boolean equals(@Nullable Object other) {

@Override
public int hashCode() {
return super.hashCode() * 29 + getObjectName().hashCode();
return (29 * super.hashCode() + getObjectName().hashCode());
}

@Override
Expand Down
Expand Up @@ -591,7 +591,7 @@ public boolean equals(Object other) {

@Override
public int hashCode() {
return 31 * super.hashCode() + ObjectUtils.nullSafeHashCode(this.selector);
return (31 * super.hashCode() + ObjectUtils.nullSafeHashCode(this.selector));
}

@Override
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
Expand Down Expand Up @@ -110,9 +110,8 @@ public boolean supportsParameter(MethodParameter parameter) {
public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception {
HandlerMethodArgumentResolver resolver = getArgumentResolver(parameter);
if (resolver == null) {
throw new IllegalStateException(
"Unsupported parameter type [" + parameter.getParameterType().getName() + "]." +
" supportsParameter should be called first.");
throw new IllegalArgumentException("Unsupported parameter type [" +
parameter.getParameterType().getName() + "]. supportsParameter should be called first.");
}
return resolver.resolveArgument(parameter, message);
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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.
Expand Down Expand Up @@ -178,7 +178,7 @@ public boolean equals(@Nullable Object other) {
*/
@Override
public int hashCode() {
return super.hashCode() * 31 + this.resourceBasePath.hashCode();
return (31 * super.hashCode() + this.resourceBasePath.hashCode());
}

/**
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
Expand Down Expand Up @@ -447,6 +447,7 @@ public Series series() {
* Whether this status code is in the HTTP series
* {@link org.springframework.http.HttpStatus.Series#INFORMATIONAL}.
* This is a shortcut for checking the value of {@link #series()}.
* @since 4.0
* @see #series()
*/
public boolean is1xxInformational() {
Expand All @@ -457,6 +458,7 @@ public boolean is1xxInformational() {
* Whether this status code is in the HTTP series
* {@link org.springframework.http.HttpStatus.Series#SUCCESSFUL}.
* This is a shortcut for checking the value of {@link #series()}.
* @since 4.0
* @see #series()
*/
public boolean is2xxSuccessful() {
Expand All @@ -467,6 +469,7 @@ public boolean is2xxSuccessful() {
* Whether this status code is in the HTTP series
* {@link org.springframework.http.HttpStatus.Series#REDIRECTION}.
* This is a shortcut for checking the value of {@link #series()}.
* @since 4.0
* @see #series()
*/
public boolean is3xxRedirection() {
Expand All @@ -477,6 +480,7 @@ public boolean is3xxRedirection() {
* Whether this status code is in the HTTP series
* {@link org.springframework.http.HttpStatus.Series#CLIENT_ERROR}.
* This is a shortcut for checking the value of {@link #series()}.
* @since 4.0
* @see #series()
*/
public boolean is4xxClientError() {
Expand All @@ -487,6 +491,7 @@ public boolean is4xxClientError() {
* Whether this status code is in the HTTP series
* {@link org.springframework.http.HttpStatus.Series#SERVER_ERROR}.
* This is a shortcut for checking the value of {@link #series()}.
* @since 4.0
* @see #series()
*/
public boolean is5xxServerError() {
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
Expand Down Expand Up @@ -169,7 +169,7 @@ public boolean equals(@Nullable Object other) {

@Override
public int hashCode() {
return (super.hashCode() * 29 + ObjectUtils.nullSafeHashCode(this.status));
return (29 * super.hashCode() + ObjectUtils.nullSafeHashCode(this.status));
}

@Override
Expand Down
Expand Up @@ -109,7 +109,7 @@ public boolean setStatusCode(@Nullable HttpStatus status) {
@Override
@Nullable
public HttpStatus getStatusCode() {
return this.statusCode != null ? HttpStatus.resolve(this.statusCode) : null;
return (this.statusCode != null ? HttpStatus.resolve(this.statusCode) : null);
}

/**
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
Expand All @@ -19,7 +19,6 @@
import java.nio.file.Path;

import io.netty.buffer.ByteBuf;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.cookie.Cookie;
import io.netty.handler.codec.http.cookie.DefaultCookie;
import org.reactivestreams.Publisher;
Expand Down Expand Up @@ -62,14 +61,9 @@ public <T> T getNativeResponse() {
}

@Override
@SuppressWarnings("ConstantConditions")
public HttpStatus getStatusCode() {
HttpStatus httpStatus = super.getStatusCode();
if (httpStatus == null) {
HttpResponseStatus status = this.response.status();
httpStatus = status != null ? HttpStatus.resolve(status.code()) : null;
}
return httpStatus;
return (httpStatus != null ? httpStatus : HttpStatus.resolve(this.response.status().code()));
}


Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
Expand Down Expand Up @@ -100,7 +100,7 @@ public <T> T getNativeResponse() {
@Override
public HttpStatus getStatusCode() {
HttpStatus httpStatus = super.getStatusCode();
return httpStatus != null ? httpStatus : HttpStatus.resolve(this.response.getStatus());
return (httpStatus != null ? httpStatus : HttpStatus.resolve(this.response.getStatus()));
}

@Override
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
Expand Down Expand Up @@ -69,8 +69,7 @@ class UndertowServerHttpResponse extends AbstractListenerServerHttpResponse impl
}

private static HttpHeaders createHeaders(HttpServerExchange exchange) {
UndertowHeadersAdapter headersMap =
new UndertowHeadersAdapter(exchange.getResponseHeaders());
UndertowHeadersAdapter headersMap = new UndertowHeadersAdapter(exchange.getResponseHeaders());
return new HttpHeaders(headersMap);
}

Expand All @@ -84,7 +83,7 @@ public <T> T getNativeResponse() {
@Override
public HttpStatus getStatusCode() {
HttpStatus httpStatus = super.getStatusCode();
return httpStatus != null ? httpStatus : HttpStatus.resolve(this.exchange.getStatusCode());
return (httpStatus != null ? httpStatus : HttpStatus.resolve(this.exchange.getStatusCode()));
}


Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
Expand Down Expand Up @@ -119,9 +119,8 @@ public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewC

HandlerMethodArgumentResolver resolver = getArgumentResolver(parameter);
if (resolver == null) {
throw new IllegalArgumentException(
"Unsupported parameter type [" + parameter.getParameterType().getName() + "]." +
" supportsParameter should be called first.");
throw new IllegalArgumentException("Unsupported parameter type [" +
parameter.getParameterType().getName() + "]. supportsParameter should be called first.");
}
return resolver.resolveArgument(parameter, mavContainer, webRequest, binderFactory);
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
Expand Down Expand Up @@ -40,7 +40,7 @@ public class HandlerMethodArgumentResolverCompositeTests {


@Before
public void setUp() throws Exception {
public void setup() throws Exception {
this.resolverComposite = new HandlerMethodArgumentResolverComposite();

Method method = getClass().getDeclaredMethod("handle", Integer.class, String.class);
Expand All @@ -50,7 +50,7 @@ public void setUp() throws Exception {


@Test
public void supportsParameter() {
public void supportsParameter() throws Exception {
this.resolverComposite.addResolver(new StubArgumentResolver(Integer.class));

assertTrue(this.resolverComposite.supportsParameter(paramInt));
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
Expand Down Expand Up @@ -30,6 +30,7 @@

/**
* Test fixture with {@link HandlerMethodReturnValueHandlerComposite}.
*
* @author Rossen Stoyanchev
*/
@SuppressWarnings("unused")
Expand All @@ -47,8 +48,7 @@ public class HandlerMethodReturnValueHandlerCompositeTests {


@Before
public void setUp() throws Exception {

public void setup() throws Exception {
this.integerType = new MethodParameter(getClass().getDeclaredMethod("handleInteger"), -1);
this.stringType = new MethodParameter(getClass().getDeclaredMethod("handleString"), -1);

Expand All @@ -61,6 +61,7 @@ public void setUp() throws Exception {
mavContainer = new ModelAndViewContainer();
}


@Test
public void supportsReturnType() throws Exception {
assertTrue(this.handlers.supportsReturnType(this.integerType));
Expand All @@ -84,9 +85,8 @@ public void handleReturnValueWithMultipleHandlers() throws Exception {
verifyNoMoreInteractions(anotherIntegerHandler);
}

@Test // SPR-13083
@Test // SPR-13083
public void handleReturnValueWithAsyncHandler() throws Exception {

Promise<Integer> promise = new Promise<>();
MethodParameter promiseType = new MethodParameter(getClass().getDeclaredMethod("handlePromise"), -1);

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
Expand Down Expand Up @@ -129,13 +129,11 @@ private void releaseBody() {

@Override
public ClientResponse build() {

ClientHttpResponse httpResponse =
new BuiltClientHttpResponse(this.statusCode, this.headers, this.cookies, this.body);

// When building ClientResponse manually, the ClientRequest.logPrefix() has to be passed,
// e.g. via ClientResponse.Builder, but this (builder) is not used currently.

return new DefaultClientResponse(httpResponse, this.strategies, "");
}

Expand Down
Expand Up @@ -423,7 +423,7 @@ public ResponseSpec onStatus(Predicate<HttpStatus> statusPredicate,
private static IntPredicate toIntPredicate(Predicate<HttpStatus> predicate) {
return value -> {
HttpStatus status = HttpStatus.resolve(value);
return (status != null) && predicate.test(status);
return (status != null && predicate.test(status));
};
}

Expand All @@ -436,7 +436,6 @@ public ResponseSpec onRawStatus(IntPredicate statusCodePredicate,
}
this.statusHandlers.add(new StatusHandler(statusCodePredicate,
(clientResponse, request) -> exceptionFunction.apply(clientResponse)));

return this;
}

Expand Down Expand Up @@ -539,8 +538,6 @@ private static class StatusHandler {
public StatusHandler(IntPredicate predicate,
BiFunction<ClientResponse, HttpRequest, Mono<? extends Throwable>> exceptionFunction) {

Assert.notNull(predicate, "Predicate must not be null");
Assert.notNull(exceptionFunction, "Function must not be null");
this.predicate = predicate;
this.exceptionFunction = exceptionFunction;
}
Expand All @@ -552,8 +549,6 @@ public boolean test(int status) {
public Mono<? extends Throwable> apply(ClientResponse response, HttpRequest request) {
return this.exceptionFunction.apply(response, request);
}


}
}

Expand Down
Expand Up @@ -583,6 +583,7 @@ <T, P extends Publisher<T>> RequestHeadersSpec<?> body(P publisher,
RequestHeadersSpec<?> syncBody(Object body);
}


/**
* Contract for specifying response operations following the exchange.
*/
Expand Down Expand Up @@ -666,24 +667,22 @@ ResponseSpec onRawStatus(IntPredicate statusCodePredicate,
* status code is 4xx or 5xx
*/
<T> Flux<T> bodyToFlux(ParameterizedTypeReference<T> typeReference);

}


/**
* Contract for specifying request headers and URI for a request.
*
* @param <S> a self reference to the spec type
*/
interface RequestHeadersUriSpec<S extends RequestHeadersSpec<S>>
extends UriSpec<S>, RequestHeadersSpec<S> {
}


/**
* Contract for specifying request headers, body and URI for a request.
*/
interface RequestBodyUriSpec extends RequestBodySpec, RequestHeadersUriSpec<RequestBodySpec> {
}


}

0 comments on commit c4622db

Please sign in to comment.