From 0f0de5024a1d40c9f81806906ce774acebe4f7dd Mon Sep 17 00:00:00 2001 From: Rebwon Date: Sat, 20 Mar 2021 21:31:47 +0900 Subject: [PATCH] Polish tests Closes gh-26708 --- ...rEntityManagerFactoryIntegrationTests.java | 5 ++- .../springframework/http/HttpEntityTests.java | 28 ++++++++--------- .../server/ServletServerHttpRequestTests.java | 31 ++++++++++--------- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/AbstractContainerEntityManagerFactoryIntegrationTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/AbstractContainerEntityManagerFactoryIntegrationTests.java index 15c27ccc5f03..8885d6eb7e02 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/AbstractContainerEntityManagerFactoryIntegrationTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/AbstractContainerEntityManagerFactoryIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2021 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. @@ -224,8 +224,7 @@ public void testQueryNoPersonsSharedNotTransactional() { q.setFlushMode(FlushModeType.AUTO); List people = q.getResultList(); assertThat(people.size()).isEqualTo(0); - assertThatExceptionOfType(Exception.class).isThrownBy(() -> - q.getSingleResult()) + assertThatExceptionOfType(Exception.class).isThrownBy(q::getSingleResult) .withMessageContaining("closed"); // We would typically expect an IllegalStateException, but Hibernate throws a // PersistenceException. So we assert the contents of the exception message instead. diff --git a/spring-web/src/test/java/org/springframework/http/HttpEntityTests.java b/spring-web/src/test/java/org/springframework/http/HttpEntityTests.java index 7b97e86afd72..6ebf469d088e 100644 --- a/spring-web/src/test/java/org/springframework/http/HttpEntityTests.java +++ b/spring-web/src/test/java/org/springframework/http/HttpEntityTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2021 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. @@ -31,7 +31,7 @@ public class HttpEntityTests { @Test - public void noHeaders() { + void noHeaders() { String body = "foo"; HttpEntity entity = new HttpEntity<>(body); assertThat(entity.getBody()).isSameAs(body); @@ -39,7 +39,7 @@ public void noHeaders() { } @Test - public void httpHeaders() { + void httpHeaders() { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.TEXT_PLAIN); String body = "foo"; @@ -50,7 +50,7 @@ public void httpHeaders() { } @Test - public void multiValueMap() { + void multiValueMap() { MultiValueMap map = new LinkedMultiValueMap<>(); map.set("Content-Type", "text/plain"); String body = "foo"; @@ -61,30 +61,30 @@ public void multiValueMap() { } @Test - public void testEquals() { + void testEquals() { MultiValueMap map1 = new LinkedMultiValueMap<>(); map1.set("Content-Type", "text/plain"); MultiValueMap map2 = new LinkedMultiValueMap<>(); map2.set("Content-Type", "application/json"); - assertThat(new HttpEntity<>().equals(new HttpEntity())).isTrue(); - assertThat(new HttpEntity<>(map1).equals(new HttpEntity())).isFalse(); - assertThat(new HttpEntity<>().equals(new HttpEntity(map2))).isFalse(); + assertThat(new HttpEntity<>().equals(new HttpEntity<>())).isTrue(); + assertThat(new HttpEntity<>(map1).equals(new HttpEntity<>())).isFalse(); + assertThat(new HttpEntity<>().equals(new HttpEntity<>(map2))).isFalse(); - assertThat(new HttpEntity<>(map1).equals(new HttpEntity(map1))).isTrue(); - assertThat(new HttpEntity<>(map1).equals(new HttpEntity(map2))).isFalse(); + assertThat(new HttpEntity<>(map1).equals(new HttpEntity<>(map1))).isTrue(); + assertThat(new HttpEntity<>(map1).equals(new HttpEntity<>(map2))).isFalse(); assertThat(new HttpEntity(null, null).equals(new HttpEntity(null, null))).isTrue(); assertThat(new HttpEntity<>("foo", null).equals(new HttpEntity(null, null))).isFalse(); assertThat(new HttpEntity(null, null).equals(new HttpEntity<>("bar", null))).isFalse(); - assertThat(new HttpEntity<>("foo", map1).equals(new HttpEntity("foo", map1))).isTrue(); - assertThat(new HttpEntity<>("foo", map1).equals(new HttpEntity("bar", map1))).isFalse(); + assertThat(new HttpEntity<>("foo", map1).equals(new HttpEntity<>("foo", map1))).isTrue(); + assertThat(new HttpEntity<>("foo", map1).equals(new HttpEntity<>("bar", map1))).isFalse(); } @Test - public void responseEntity() { + void responseEntity() { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.TEXT_PLAIN); String body = "foo"; @@ -104,7 +104,7 @@ public void responseEntity() { } @Test - public void requestEntity() throws Exception { + void requestEntity() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.TEXT_PLAIN); String body = "foo"; diff --git a/spring-web/src/test/java/org/springframework/http/server/ServletServerHttpRequestTests.java b/spring-web/src/test/java/org/springframework/http/server/ServletServerHttpRequestTests.java index b0aa8e1cda06..336289185e55 100644 --- a/spring-web/src/test/java/org/springframework/http/server/ServletServerHttpRequestTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/ServletServerHttpRequestTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2021 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. @@ -45,20 +45,20 @@ public class ServletServerHttpRequestTests { @BeforeEach - public void create() { + void create() { mockRequest = new MockHttpServletRequest(); request = new ServletServerHttpRequest(mockRequest); } @Test - public void getMethod() { + void getMethod() { mockRequest.setMethod("POST"); assertThat(request.getMethod()).as("Invalid method").isEqualTo(HttpMethod.POST); } @Test - public void getUriForSimplePath() throws URISyntaxException { + void getUriForSimplePath() throws URISyntaxException { URI uri = new URI("https://example.com/path"); mockRequest.setScheme(uri.getScheme()); mockRequest.setServerName(uri.getHost()); @@ -69,7 +69,7 @@ public void getUriForSimplePath() throws URISyntaxException { } @Test - public void getUriWithQueryString() throws URISyntaxException { + void getUriWithQueryString() throws URISyntaxException { URI uri = new URI("https://example.com/path?query"); mockRequest.setScheme(uri.getScheme()); mockRequest.setServerName(uri.getHost()); @@ -80,7 +80,7 @@ public void getUriWithQueryString() throws URISyntaxException { } @Test // SPR-16414 - public void getUriWithQueryParam() throws URISyntaxException { + void getUriWithQueryParam() throws URISyntaxException { mockRequest.setScheme("https"); mockRequest.setServerPort(443); mockRequest.setServerName("example.com"); @@ -90,7 +90,7 @@ public void getUriWithQueryParam() throws URISyntaxException { } @Test // SPR-16414 - public void getUriWithMalformedQueryParam() throws URISyntaxException { + void getUriWithMalformedQueryParam() throws URISyntaxException { mockRequest.setScheme("https"); mockRequest.setServerPort(443); mockRequest.setServerName("example.com"); @@ -100,7 +100,7 @@ public void getUriWithMalformedQueryParam() throws URISyntaxException { } @Test // SPR-13876 - public void getUriWithEncoding() throws URISyntaxException { + void getUriWithEncoding() throws URISyntaxException { URI uri = new URI("https://example.com/%E4%B8%AD%E6%96%87" + "?redirect=https%3A%2F%2Fgithub.com%2Fspring-projects%2Fspring-framework"); mockRequest.setScheme(uri.getScheme()); @@ -112,7 +112,7 @@ public void getUriWithEncoding() throws URISyntaxException { } @Test - public void getHeaders() { + void getHeaders() { String headerName = "MyHeader"; String headerValue1 = "value1"; String headerValue2 = "value2"; @@ -132,7 +132,7 @@ public void getHeaders() { } @Test - public void getHeadersWithEmptyContentTypeAndEncoding() { + void getHeadersWithEmptyContentTypeAndEncoding() { String headerName = "MyHeader"; String headerValue1 = "value1"; String headerValue2 = "value2"; @@ -152,8 +152,8 @@ public void getHeadersWithEmptyContentTypeAndEncoding() { } @Test - public void getBody() throws IOException { - byte[] content = "Hello World".getBytes("UTF-8"); + void getBody() throws IOException { + byte[] content = "Hello World".getBytes(StandardCharsets.UTF_8); mockRequest.setContent(content); byte[] result = FileCopyUtils.copyToByteArray(request.getBody()); @@ -161,16 +161,17 @@ public void getBody() throws IOException { } @Test - public void getFormBody() throws IOException { + void getFormBody() throws IOException { // Charset (SPR-8676) mockRequest.setContentType("application/x-www-form-urlencoded; charset=UTF-8"); mockRequest.setMethod("POST"); mockRequest.addParameter("name 1", "value 1"); - mockRequest.addParameter("name 2", new String[] {"value 2+1", "value 2+2"}); + mockRequest.addParameter("name 2", "value 2+1", "value 2+2"); mockRequest.addParameter("name 3", (String) null); byte[] result = FileCopyUtils.copyToByteArray(request.getBody()); - byte[] content = "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3".getBytes("UTF-8"); + byte[] content = "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3".getBytes( + StandardCharsets.UTF_8); assertThat(result).as("Invalid content returned").isEqualTo(content); }