Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
izeye committed Feb 15, 2023
1 parent 3e3f046 commit ce3be72
Show file tree
Hide file tree
Showing 18 changed files with 49 additions and 51 deletions.
2 changes: 1 addition & 1 deletion framework-docs/src/docs/asciidoc/web/webmvc.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4777,7 +4777,7 @@ directly. For example:
ContextSnapshot snapshot = ContextSnapshot.captureAll();
// On a different thread: restore ThreadLocal values
try (ContextSnapshot.Scope scoped = snapshot.setThreadLocals()) {
try (ContextSnapshot.Scope scope = snapshot.setThreadLocals()) {
// ...
}
----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@

package org.springframework.context.aot

import org.assertj.core.api.Assertions
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.mockito.Mockito
import org.springframework.aot.generate.GenerationContext
import org.springframework.aot.hint.MemberCategory
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates
import org.springframework.aot.test.generate.TestGenerationContext
Expand All @@ -41,20 +40,20 @@ class KotlinReflectionBeanRegistrationAotProcessorTests {

@Test
fun processorIsRegistered() {
Assertions.assertThat(
assertThat(
AotServices.factories(javaClass.classLoader).load(BeanRegistrationAotProcessor::class.java))
.anyMatch(KotlinReflectionBeanRegistrationAotProcessor::class.java::isInstance)
}

@Test
fun shouldProcessKotlinBean() {
process(SampleKotlinBean::class.java)
Assertions.assertThat(
assertThat(
RuntimeHintsPredicates.reflection()
.onType(SampleKotlinBean::class.java)
.withMemberCategory(MemberCategory.INTROSPECT_DECLARED_METHODS)
).accepts(generationContext.runtimeHints)
Assertions.assertThat(
assertThat(
RuntimeHintsPredicates.reflection()
.onType(BaseKotlinBean::class.java)
.withMemberCategory(MemberCategory.INTROSPECT_DECLARED_METHODS)
Expand All @@ -64,7 +63,7 @@ class KotlinReflectionBeanRegistrationAotProcessorTests {
@Test
fun shouldNotProcessJavaBean() {
process(SampleJavaBean::class.java)
Assertions.assertThat(generationContext.runtimeHints.reflection().typeHints()).isEmpty()
assertThat(generationContext.runtimeHints.reflection().typeHints()).isEmpty()
}

private fun process(beanClass: Class<*>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import jakarta.validation.ValidationException
import jakarta.validation.Validator
import jakarta.validation.constraints.NotEmpty
import kotlinx.coroutines.runBlocking
import org.assertj.core.api.Assertions
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatExceptionOfType
import org.junit.jupiter.api.Test
import org.springframework.aop.framework.ProxyFactory
import org.springframework.validation.annotation.Validated
Expand All @@ -41,8 +42,8 @@ class KotlinMethodValidationTests {
validator.afterPropertiesSet()
proxyFactory.addAdvice(MethodValidationInterceptor(validator as Validator))
val proxy = proxyFactory.getProxy() as MyValidBean
Assertions.assertThat(proxy.validName("name")).isEqualTo("name")
Assertions.assertThatExceptionOfType(ValidationException::class.java).isThrownBy {
assertThat(proxy.validName("name")).isEqualTo("name")
assertThatExceptionOfType(ValidationException::class.java).isThrownBy {
proxy.validName("")
}
}
Expand All @@ -55,8 +56,8 @@ class KotlinMethodValidationTests {
validator.afterPropertiesSet()
proxyFactory.addAdvice(MethodValidationInterceptor(validator as Validator))
val proxy = proxyFactory.getProxy() as MyValidCoroutinesBean
Assertions.assertThat(proxy.validName("name")).isEqualTo("name")
Assertions.assertThatExceptionOfType(ValidationException::class.java).isThrownBy {
assertThat(proxy.validName("name")).isEqualTo("name")
assertThatExceptionOfType(ValidationException::class.java).isThrownBy {
runBlocking {
proxy.validName("")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

@Deprecated
public class TinyBitSet {
private static int[] T = new int[256];
private static final int[] T = new int[256];
private int value = 0;

private static int gcount(int x) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private static class StandardRepeatableContainers extends RepeatableContainers {

private static final Object NONE = new Object();

private static StandardRepeatableContainers INSTANCE = new StandardRepeatableContainers();
private static final StandardRepeatableContainers INSTANCE = new StandardRepeatableContainers();

StandardRepeatableContainers() {
super(null);
Expand Down Expand Up @@ -270,7 +270,7 @@ public int hashCode() {
*/
private static class NoRepeatableContainers extends RepeatableContainers {

private static NoRepeatableContainers INSTANCE = new NoRepeatableContainers();
private static final NoRepeatableContainers INSTANCE = new NoRepeatableContainers();

NoRepeatableContainers() {
super(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
public class ResourceDecoder extends AbstractDataBufferDecoder<Resource> {

/** Name of hint with a filename for the resource(e.g. from "Content-Disposition" HTTP header). */
public static String FILENAME_HINT = ResourceDecoder.class.getName() + ".filename";
public static final String FILENAME_HINT = ResourceDecoder.class.getName() + ".filename";


public ResourceDecoder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -897,9 +897,9 @@ private Resource findResource(ModuleReader moduleReader, String name) {
}

/**
* If it's a "file:" URI, use FileSystemResource to avoid duplicates
* for the same path discovered via class-path scanning.
*/
* If it's a "file:" URI, use FileSystemResource to avoid duplicates
* for the same path discovered via class-path scanning.
*/
private Resource convertModuleSystemURI(URI uri) {
return (ResourceUtils.URL_PROTOCOL_FILE.equals(uri.getScheme()) ?
new FileSystemResource(uri.getPath()) : UrlResource.from(uri));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.springframework.aot.hint

/**
* Extension for [TypeHint.Builder.onReachableType] providing a `onReachableType<Foo>())`
* Extension for [TypeHint.Builder.onReachableType] providing a `onReachableType<Foo>()`
* variant.
*
* @author Sebastien Deleuze
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ResourceHintsExtensionsTests {
private val resourceHints = mockk<ResourceHints>()

@Test
fun `registerType extension with MemberCategory`() {
fun `registerType extension`() {
every { resourceHints.registerType(any<Class<String>>()) } returns resourceHints
resourceHints.registerType<String>()
verify { resourceHints.registerType(String::class.java) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import io.r2dbc.spi.R2dbcBadGrammarException;
import io.r2dbc.spi.R2dbcTimeoutException;
import io.r2dbc.spi.Statement;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
Expand Down Expand Up @@ -345,7 +344,7 @@ void testConnectionReleasedWhenRollbackFails() {
.doOnNext(connection -> {
throw new IllegalStateException("Intentional error to trigger rollback");
}).then()).as(StepVerifier::create)
.verifyErrorSatisfies(e -> Assertions.assertThat(e)
.verifyErrorSatisfies(e -> assertThat(e)
.isInstanceOf(BadSqlGrammarException.class)
.hasCause(new R2dbcBadGrammarException("Rollback should fail"))
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public final class MockMvcWebConnection implements WebConnection {

private WebClient webClient;

private static int MAX_FORWARDS = 100;
private static final int MAX_FORWARDS = 100;


/**
Expand Down Expand Up @@ -143,7 +143,7 @@ public WebResponse getResponse(WebRequest webRequest) throws IOException {
forwards += 1;
}
if (forwards == MAX_FORWARDS) {
throw new IllegalStateException("Forwarded more than " + forwards + " times in a row, potential infinite forward loop");
throw new IllegalStateException("Forwarded " + forwards + " times in a row, potential infinite forward loop");
}
storeCookies(webRequest, httpServletResponse.getCookies());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void forward() throws IOException {
public void infiniteForward() {
this.webClient.setWebConnection(new MockMvcWebConnection(this.mockMvc, this.webClient, ""));
assertThatIllegalStateException().isThrownBy(() -> this.webClient.getPage("http://localhost/infiniteForward"))
.withMessage("Forwarded more than 100 times in a row, potential infinite forward loop");
.withMessage("Forwarded 100 times in a row, potential infinite forward loop");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
*/
public class Jackson2ObjectMapperBuilder {

private static boolean jackson2XmlPresent = ClassUtils.isPresent(
private static final boolean jackson2XmlPresent = ClassUtils.isPresent(
"com.fasterxml.jackson.dataformat.xml.XmlMapper", Jackson2ObjectMapperBuilder.class.getClassLoader());


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.springframework.http;

import java.net.URI;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -46,11 +45,8 @@ void normal() {
assertThat(responseEntity).isNotNull();
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(responseEntity.getHeaders().containsKey(headerName)).isTrue();
List<String> list = responseEntity.getHeaders().get(headerName);
assertThat(list).hasSize(2);
assertThat(list.get(0)).isEqualTo(headerValue1);
assertThat(list.get(1)).isEqualTo(headerValue2);
assertThat((int) responseEntity.getBody()).isEqualTo((int) entity);
assertThat(responseEntity.getHeaders().get(headerName)).containsExactly(headerValue1, headerValue2);
assertThat(responseEntity.getBody()).isEqualTo(entity);
}

@Test
Expand All @@ -69,7 +65,7 @@ void okEntity() {

assertThat(responseEntity).isNotNull();
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat((int) responseEntity.getBody()).isEqualTo((int) entity);
assertThat(responseEntity.getBody()).isEqualTo(entity);
}

@Test
Expand All @@ -79,7 +75,7 @@ void ofOptional() {

assertThat(responseEntity).isNotNull();
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat((int) responseEntity.getBody()).isEqualTo((int) entity);
assertThat(responseEntity.getBody()).isEqualTo(entity);
}

@Test
Expand All @@ -98,7 +94,7 @@ void ofNullable() {

assertThat(responseEntity).isNotNull();
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat((int) responseEntity.getBody()).isEqualTo((int) entity);
assertThat(responseEntity.getBody()).isEqualTo(entity);
}

@Test
Expand Down Expand Up @@ -270,7 +266,7 @@ void emptyCacheControl() {
assertThat(responseEntity).isNotNull();
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(responseEntity.getHeaders().containsKey(HttpHeaders.CACHE_CONTROL)).isFalse();
assertThat((int) responseEntity.getBody()).isEqualTo((int) entity);
assertThat(responseEntity.getBody()).isEqualTo(entity);
}

@Test
Expand All @@ -286,7 +282,7 @@ void cacheControl() {
assertThat(responseEntity).isNotNull();
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(responseEntity.getHeaders().containsKey(HttpHeaders.CACHE_CONTROL)).isTrue();
assertThat((int) responseEntity.getBody()).isEqualTo((int) entity);
assertThat(responseEntity.getBody()).isEqualTo(entity);
String cacheControlHeader = responseEntity.getHeaders().getCacheControl();
assertThat(cacheControlHeader).isEqualTo(
"max-age=3600, must-revalidate, private, proxy-revalidate, s-maxage=1800");
Expand All @@ -304,7 +300,7 @@ void cacheControlNoCache() {
assertThat(responseEntity).isNotNull();
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(responseEntity.getHeaders().containsKey(HttpHeaders.CACHE_CONTROL)).isTrue();
assertThat((int) responseEntity.getBody()).isEqualTo((int) entity);
assertThat(responseEntity.getBody()).isEqualTo(entity);

String cacheControlHeader = responseEntity.getHeaders().getCacheControl();
assertThat(cacheControlHeader).isEqualTo("no-store");
Expand All @@ -316,7 +312,7 @@ void statusCodeAsInt() {
ResponseEntity<Integer> responseEntity = ResponseEntity.status(200).body(entity);

assertThat(responseEntity.getStatusCode().value()).isEqualTo(200);
assertThat((int) responseEntity.getBody()).isEqualTo((int) entity);
assertThat(responseEntity.getBody()).isEqualTo(entity);
}

@Test
Expand All @@ -326,7 +322,7 @@ void customStatusCode() {
ResponseEntity<Integer> responseEntity = ResponseEntity.status(299).body(entity);

assertThat(responseEntity.getStatusCodeValue()).isEqualTo(299);
assertThat((int) responseEntity.getBody()).isEqualTo((int) entity);
assertThat(responseEntity.getBody()).isEqualTo(entity);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

package org.springframework.web.method.annotation

import org.assertj.core.api.Assertions
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatThrownBy
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers.*
Expand Down Expand Up @@ -61,7 +62,7 @@ class ModelAttributeMethodProcessorKotlinTests {
val factory = Mockito.mock<WebDataBinderFactory>()
BDDMockito.given(factory.createBinder(any(), any(), eq("param")))
.willAnswer { WebRequestDataBinder(it.getArgument(1)) }
Assertions.assertThat(processor.resolveArgument(this.param, container, requestWithParam, factory)).isEqualTo(Param("b"))
assertThat(processor.resolveArgument(this.param, container, requestWithParam, factory)).isEqualTo(Param("b"))
}

@Test
Expand All @@ -71,7 +72,7 @@ class ModelAttributeMethodProcessorKotlinTests {
val factory = Mockito.mock<WebDataBinderFactory>()
BDDMockito.given(factory.createBinder(any(), any(), eq("param")))
.willAnswer { WebRequestDataBinder(it.getArgument(1)) }
Assertions.assertThatThrownBy {
assertThatThrownBy {
processor.resolveArgument(this.param, container, requestWithParam, factory)
}.isInstanceOf(MethodArgumentNotValidException::class.java)
.hasMessageContaining("parameter a")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public class DefaultClientRequestObservationConvention implements ClientRequestO

private static final KeyValue URI_NONE = KeyValue.of(LowCardinalityKeyNames.URI, KeyValue.NONE_VALUE);

private static final KeyValue URI_ROOT = KeyValue.of(LowCardinalityKeyNames.URI, ROOT_PATH);

private static final KeyValue METHOD_NONE = KeyValue.of(LowCardinalityKeyNames.METHOD, KeyValue.NONE_VALUE);

private static final KeyValue STATUS_IO_ERROR = KeyValue.of(LowCardinalityKeyNames.STATUS, "IO_ERROR");
Expand Down Expand Up @@ -101,7 +103,7 @@ protected KeyValue uri(ClientRequestObservationContext context) {
}
ClientRequest request = context.getRequest();
if (request != null && ROOT_PATH.equals(request.url().getPath())) {
return KeyValue.of(LowCardinalityKeyNames.URI, ROOT_PATH);
return URI_ROOT;
}
return URI_NONE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package org.springframework.web.reactive.function.client.support
import kotlinx.coroutines.runBlocking
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.MockWebServer
import org.assertj.core.api.Assertions
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
Expand Down Expand Up @@ -66,7 +66,7 @@ class KotlinWebClientHttpServiceProxyTests {
}
runBlocking {
val greeting = initHttpService().getGreetingSuspending()
Assertions.assertThat(greeting).isEqualTo("Hello Spring!")
assertThat(greeting).isEqualTo("Hello Spring!")
}
}

Expand All @@ -93,7 +93,7 @@ class KotlinWebClientHttpServiceProxyTests {
).setBody("Hello Spring!")
}
val greeting = initHttpService().getGreetingBlocking()
Assertions.assertThat(greeting).isEqualTo("Hello Spring!")
assertThat(greeting).isEqualTo("Hello Spring!")
}

@Test
Expand All @@ -115,8 +115,8 @@ class KotlinWebClientHttpServiceProxyTests {
val service = initHttpService(webClient)
runBlocking {
val greeting = service.getGreetingSuspendingWithAttribute("myAttributeValue")
Assertions.assertThat(greeting).isEqualTo("Hello Spring!")
Assertions.assertThat(attributes).containsEntry("myAttribute", "myAttributeValue")
assertThat(greeting).isEqualTo("Hello Spring!")
assertThat(attributes).containsEntry("myAttribute", "myAttributeValue")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ void getHandlerMediaTypeNotSupported(TestRequestMappingInfoHandlerMapping mappin
}

@PathPatternsParameterizedTest // gh-28062
void getHandlerMethodTypeNotSupportedWithParseError(TestRequestMappingInfoHandlerMapping mapping) {
void getHandlerMediaTypeNotSupportedWithParseError(TestRequestMappingInfoHandlerMapping mapping) {
MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/person/1");
request.setContentType("This string");
assertThatExceptionOfType(HttpMediaTypeNotSupportedException.class)
Expand Down

0 comments on commit ce3be72

Please sign in to comment.