Skip to content

Commit 7954dc7

Browse files
Rebwonsbrannen
authored andcommitted
Polish tests
Closes gh-26708
1 parent 22d9012 commit 7954dc7

File tree

3 files changed

+32
-32
lines changed

3 files changed

+32
-32
lines changed

spring-orm/src/test/java/org/springframework/orm/jpa/AbstractContainerEntityManagerFactoryIntegrationTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -224,8 +224,7 @@ public void testQueryNoPersonsSharedNotTransactional() {
224224
q.setFlushMode(FlushModeType.AUTO);
225225
List<Person> people = q.getResultList();
226226
assertThat(people.size()).isEqualTo(0);
227-
assertThatExceptionOfType(Exception.class).isThrownBy(() ->
228-
q.getSingleResult())
227+
assertThatExceptionOfType(Exception.class).isThrownBy(q::getSingleResult)
229228
.withMessageContaining("closed");
230229
// We would typically expect an IllegalStateException, but Hibernate throws a
231230
// PersistenceException. So we assert the contents of the exception message instead.

spring-web/src/test/java/org/springframework/http/HttpEntityTests.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,15 +31,15 @@
3131
public class HttpEntityTests {
3232

3333
@Test
34-
public void noHeaders() {
34+
void noHeaders() {
3535
String body = "foo";
3636
HttpEntity<String> entity = new HttpEntity<>(body);
3737
assertThat(entity.getBody()).isSameAs(body);
3838
assertThat(entity.getHeaders().isEmpty()).isTrue();
3939
}
4040

4141
@Test
42-
public void httpHeaders() {
42+
void httpHeaders() {
4343
HttpHeaders headers = new HttpHeaders();
4444
headers.setContentType(MediaType.TEXT_PLAIN);
4545
String body = "foo";
@@ -50,7 +50,7 @@ public void httpHeaders() {
5050
}
5151

5252
@Test
53-
public void multiValueMap() {
53+
void multiValueMap() {
5454
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
5555
map.set("Content-Type", "text/plain");
5656
String body = "foo";
@@ -61,30 +61,30 @@ public void multiValueMap() {
6161
}
6262

6363
@Test
64-
public void testEquals() {
64+
void testEquals() {
6565
MultiValueMap<String, String> map1 = new LinkedMultiValueMap<>();
6666
map1.set("Content-Type", "text/plain");
6767

6868
MultiValueMap<String, String> map2 = new LinkedMultiValueMap<>();
6969
map2.set("Content-Type", "application/json");
7070

71-
assertThat(new HttpEntity<>().equals(new HttpEntity<Object>())).isTrue();
72-
assertThat(new HttpEntity<>(map1).equals(new HttpEntity<Object>())).isFalse();
73-
assertThat(new HttpEntity<>().equals(new HttpEntity<Object>(map2))).isFalse();
71+
assertThat(new HttpEntity<>().equals(new HttpEntity<>())).isTrue();
72+
assertThat(new HttpEntity<>(map1).equals(new HttpEntity<>())).isFalse();
73+
assertThat(new HttpEntity<>().equals(new HttpEntity<>(map2))).isFalse();
7474

75-
assertThat(new HttpEntity<>(map1).equals(new HttpEntity<Object>(map1))).isTrue();
76-
assertThat(new HttpEntity<>(map1).equals(new HttpEntity<Object>(map2))).isFalse();
75+
assertThat(new HttpEntity<>(map1).equals(new HttpEntity<>(map1))).isTrue();
76+
assertThat(new HttpEntity<>(map1).equals(new HttpEntity<>(map2))).isFalse();
7777

7878
assertThat(new HttpEntity<String>(null, null).equals(new HttpEntity<String>(null, null))).isTrue();
7979
assertThat(new HttpEntity<>("foo", null).equals(new HttpEntity<String>(null, null))).isFalse();
8080
assertThat(new HttpEntity<String>(null, null).equals(new HttpEntity<>("bar", null))).isFalse();
8181

82-
assertThat(new HttpEntity<>("foo", map1).equals(new HttpEntity<String>("foo", map1))).isTrue();
83-
assertThat(new HttpEntity<>("foo", map1).equals(new HttpEntity<String>("bar", map1))).isFalse();
82+
assertThat(new HttpEntity<>("foo", map1).equals(new HttpEntity<>("foo", map1))).isTrue();
83+
assertThat(new HttpEntity<>("foo", map1).equals(new HttpEntity<>("bar", map1))).isFalse();
8484
}
8585

8686
@Test
87-
public void responseEntity() {
87+
void responseEntity() {
8888
HttpHeaders headers = new HttpHeaders();
8989
headers.setContentType(MediaType.TEXT_PLAIN);
9090
String body = "foo";
@@ -104,7 +104,7 @@ public void responseEntity() {
104104
}
105105

106106
@Test
107-
public void requestEntity() throws Exception {
107+
void requestEntity() throws Exception {
108108
HttpHeaders headers = new HttpHeaders();
109109
headers.setContentType(MediaType.TEXT_PLAIN);
110110
String body = "foo";

spring-web/src/test/java/org/springframework/http/server/ServletServerHttpRequestTests.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -45,20 +45,20 @@ public class ServletServerHttpRequestTests {
4545

4646

4747
@BeforeEach
48-
public void create() {
48+
void create() {
4949
mockRequest = new MockHttpServletRequest();
5050
request = new ServletServerHttpRequest(mockRequest);
5151
}
5252

5353

5454
@Test
55-
public void getMethod() {
55+
void getMethod() {
5656
mockRequest.setMethod("POST");
5757
assertThat(request.getMethod()).as("Invalid method").isEqualTo(HttpMethod.POST);
5858
}
5959

6060
@Test
61-
public void getUriForSimplePath() throws URISyntaxException {
61+
void getUriForSimplePath() throws URISyntaxException {
6262
URI uri = new URI("https://example.com/path");
6363
mockRequest.setScheme(uri.getScheme());
6464
mockRequest.setServerName(uri.getHost());
@@ -69,7 +69,7 @@ public void getUriForSimplePath() throws URISyntaxException {
6969
}
7070

7171
@Test
72-
public void getUriWithQueryString() throws URISyntaxException {
72+
void getUriWithQueryString() throws URISyntaxException {
7373
URI uri = new URI("https://example.com/path?query");
7474
mockRequest.setScheme(uri.getScheme());
7575
mockRequest.setServerName(uri.getHost());
@@ -80,7 +80,7 @@ public void getUriWithQueryString() throws URISyntaxException {
8080
}
8181

8282
@Test // SPR-16414
83-
public void getUriWithQueryParam() throws URISyntaxException {
83+
void getUriWithQueryParam() throws URISyntaxException {
8484
mockRequest.setScheme("https");
8585
mockRequest.setServerPort(443);
8686
mockRequest.setServerName("example.com");
@@ -90,7 +90,7 @@ public void getUriWithQueryParam() throws URISyntaxException {
9090
}
9191

9292
@Test // SPR-16414
93-
public void getUriWithMalformedQueryParam() throws URISyntaxException {
93+
void getUriWithMalformedQueryParam() throws URISyntaxException {
9494
mockRequest.setScheme("https");
9595
mockRequest.setServerPort(443);
9696
mockRequest.setServerName("example.com");
@@ -100,7 +100,7 @@ public void getUriWithMalformedQueryParam() throws URISyntaxException {
100100
}
101101

102102
@Test // SPR-13876
103-
public void getUriWithEncoding() throws URISyntaxException {
103+
void getUriWithEncoding() throws URISyntaxException {
104104
URI uri = new URI("https://example.com/%E4%B8%AD%E6%96%87" +
105105
"?redirect=https%3A%2F%2Fgithub.202132.xyz%2Fspring-projects%2Fspring-framework");
106106
mockRequest.setScheme(uri.getScheme());
@@ -112,7 +112,7 @@ public void getUriWithEncoding() throws URISyntaxException {
112112
}
113113

114114
@Test
115-
public void getHeaders() {
115+
void getHeaders() {
116116
String headerName = "MyHeader";
117117
String headerValue1 = "value1";
118118
String headerValue2 = "value2";
@@ -132,7 +132,7 @@ public void getHeaders() {
132132
}
133133

134134
@Test
135-
public void getHeadersWithEmptyContentTypeAndEncoding() {
135+
void getHeadersWithEmptyContentTypeAndEncoding() {
136136
String headerName = "MyHeader";
137137
String headerValue1 = "value1";
138138
String headerValue2 = "value2";
@@ -152,25 +152,26 @@ public void getHeadersWithEmptyContentTypeAndEncoding() {
152152
}
153153

154154
@Test
155-
public void getBody() throws IOException {
156-
byte[] content = "Hello World".getBytes("UTF-8");
155+
void getBody() throws IOException {
156+
byte[] content = "Hello World".getBytes(StandardCharsets.UTF_8);
157157
mockRequest.setContent(content);
158158

159159
byte[] result = FileCopyUtils.copyToByteArray(request.getBody());
160160
assertThat(result).as("Invalid content returned").isEqualTo(content);
161161
}
162162

163163
@Test
164-
public void getFormBody() throws IOException {
164+
void getFormBody() throws IOException {
165165
// Charset (SPR-8676)
166166
mockRequest.setContentType("application/x-www-form-urlencoded; charset=UTF-8");
167167
mockRequest.setMethod("POST");
168168
mockRequest.addParameter("name 1", "value 1");
169-
mockRequest.addParameter("name 2", new String[] {"value 2+1", "value 2+2"});
169+
mockRequest.addParameter("name 2", "value 2+1", "value 2+2");
170170
mockRequest.addParameter("name 3", (String) null);
171171

172172
byte[] result = FileCopyUtils.copyToByteArray(request.getBody());
173-
byte[] content = "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3".getBytes("UTF-8");
173+
byte[] content = "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3".getBytes(
174+
StandardCharsets.UTF_8);
174175
assertThat(result).as("Invalid content returned").isEqualTo(content);
175176
}
176177

0 commit comments

Comments
 (0)