Skip to content

Commit 238a24c

Browse files
codingkiddobclozel
authored andcommitted
Polish collection usage in HttpHeadersTests
Signed-off-by: Vinod Kumar <codingkiddo@gmail.com>
1 parent 9a54f75 commit 238a24c

1 file changed

Lines changed: 18 additions & 21 deletions

File tree

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

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.time.ZoneOffset;
2424
import java.time.ZonedDateTime;
2525
import java.util.ArrayList;
26-
import java.util.Arrays;
2726
import java.util.Base64;
2827
import java.util.Calendar;
2928
import java.util.Collections;
@@ -134,15 +133,15 @@ void accept() {
134133
void acceptWithMultipleHeaderValues() {
135134
headers.add("Accept", "text/html");
136135
headers.add("Accept", "text/plain");
137-
List<MediaType> expected = Arrays.asList(new MediaType("text", "html"), new MediaType("text", "plain"));
136+
List<MediaType> expected = List.of(new MediaType("text", "html"), new MediaType("text", "plain"));
138137
assertThat(headers.getAccept()).as("Invalid Accept header").isEqualTo(expected);
139138
}
140139

141140
@Test // SPR-14506
142141
void acceptWithMultipleCommaSeparatedHeaderValues() {
143142
headers.add("Accept", "text/html,text/pdf");
144143
headers.add("Accept", "text/plain,text/csv");
145-
List<MediaType> expected = Arrays.asList(new MediaType("text", "html"), new MediaType("text", "pdf"),
144+
List<MediaType> expected = List.of(new MediaType("text", "html"), new MediaType("text", "pdf"),
146145
new MediaType("text", "plain"), new MediaType("text", "csv"));
147146
assertThat(headers.getAccept()).as("Invalid Accept header").isEqualTo(expected);
148147
}
@@ -151,9 +150,7 @@ void acceptWithMultipleCommaSeparatedHeaderValues() {
151150
void acceptCharsets() {
152151
Charset charset1 = StandardCharsets.UTF_8;
153152
Charset charset2 = StandardCharsets.ISO_8859_1;
154-
List<Charset> charsets = new ArrayList<>(2);
155-
charsets.add(charset1);
156-
charsets.add(charset2);
153+
List<Charset> charsets = List.of(charset1, charset2);
157154
headers.setAcceptCharset(charsets);
158155
assertThat(headers.getAcceptCharset()).as("Invalid Accept header").isEqualTo(charsets);
159156
assertThat(headers.getFirst("Accept-Charset")).as("Invalid Accept header").isEqualTo("utf-8, iso-8859-1");
@@ -162,12 +159,12 @@ void acceptCharsets() {
162159
@Test
163160
void acceptCharsetWildcard() {
164161
headers.set("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
165-
assertThat(headers.getAcceptCharset()).as("Invalid Accept header").isEqualTo(Arrays.asList(StandardCharsets.ISO_8859_1, StandardCharsets.UTF_8));
162+
assertThat(headers.getAcceptCharset()).as("Invalid Accept header").isEqualTo(List.of(StandardCharsets.ISO_8859_1, StandardCharsets.UTF_8));
166163
}
167164

168165
@Test
169166
void allow() {
170-
Set<HttpMethod> methods = new LinkedHashSet<>(Arrays.asList(HttpMethod.GET, HttpMethod.POST));
167+
Set<HttpMethod> methods = new LinkedHashSet<>(List.of(HttpMethod.GET, HttpMethod.POST));
171168
headers.setAllow(methods);
172169
assertThat(headers.getAllow()).as("Invalid Allow header").isEqualTo(methods);
173170
assertThat(headers.getFirst("Allow")).as("Invalid Allow header").isEqualTo("GET,POST");
@@ -470,9 +467,9 @@ void accessControlAllowCredentials() {
470467
void accessControlAllowHeaders() {
471468
List<String> allowedHeaders = headers.getAccessControlAllowHeaders();
472469
assertThat(allowedHeaders).isEmpty();
473-
headers.setAccessControlAllowHeaders(Arrays.asList("header1", "header2"));
470+
headers.setAccessControlAllowHeaders(List.of("header1", "header2"));
474471
allowedHeaders = headers.getAccessControlAllowHeaders();
475-
assertThat(Arrays.asList("header1", "header2")).isEqualTo(allowedHeaders);
472+
assertThat(List.of("header1", "header2")).isEqualTo(allowedHeaders);
476473
}
477474

478475
@Test
@@ -482,16 +479,16 @@ void accessControlAllowHeadersMultipleValues() {
482479
headers.add(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS, "header1, header2");
483480
headers.add(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS, "header3");
484481
allowedHeaders = headers.getAccessControlAllowHeaders();
485-
assertThat(allowedHeaders).isEqualTo(Arrays.asList("header1", "header2", "header3"));
482+
assertThat(allowedHeaders).isEqualTo(List.of("header1", "header2", "header3"));
486483
}
487484

488485
@Test
489486
void accessControlAllowMethods() {
490487
List<HttpMethod> allowedMethods = headers.getAccessControlAllowMethods();
491488
assertThat(allowedMethods).isEmpty();
492-
headers.setAccessControlAllowMethods(Arrays.asList(HttpMethod.GET, HttpMethod.POST));
489+
headers.setAccessControlAllowMethods(List.of(HttpMethod.GET, HttpMethod.POST));
493490
allowedMethods = headers.getAccessControlAllowMethods();
494-
assertThat(Arrays.asList(HttpMethod.GET, HttpMethod.POST)).isEqualTo(allowedMethods);
491+
assertThat(List.of(HttpMethod.GET, HttpMethod.POST)).isEqualTo(allowedMethods);
495492
}
496493

497494
@Test
@@ -505,9 +502,9 @@ void accessControlAllowOrigin() {
505502
void accessControlExposeHeaders() {
506503
List<String> exposedHeaders = headers.getAccessControlExposeHeaders();
507504
assertThat(exposedHeaders).isEmpty();
508-
headers.setAccessControlExposeHeaders(Arrays.asList("header1", "header2"));
505+
headers.setAccessControlExposeHeaders(List.of("header1", "header2"));
509506
exposedHeaders = headers.getAccessControlExposeHeaders();
510-
assertThat(Arrays.asList("header1", "header2")).isEqualTo(exposedHeaders);
507+
assertThat(List.of("header1", "header2")).isEqualTo(exposedHeaders);
511508
}
512509

513510
@Test
@@ -521,9 +518,9 @@ void accessControlMaxAge() {
521518
void accessControlRequestHeaders() {
522519
List<String> requestHeaders = headers.getAccessControlRequestHeaders();
523520
assertThat(requestHeaders).isEmpty();
524-
headers.setAccessControlRequestHeaders(Arrays.asList("header1", "header2"));
521+
headers.setAccessControlRequestHeaders(List.of("header1", "header2"));
525522
requestHeaders = headers.getAccessControlRequestHeaders();
526-
assertThat(Arrays.asList("header1", "header2")).isEqualTo(requestHeaders);
523+
assertThat(List.of("header1", "header2")).isEqualTo(requestHeaders);
527524
}
528525

529526
@Test
@@ -564,7 +561,7 @@ void acceptLanguageTrailingSemicolon() {
564561
headers.set(HttpHeaders.ACCEPT_LANGUAGE, headerValue);
565562
assertThat(headers.getFirst(HttpHeaders.ACCEPT_LANGUAGE)).isEqualTo(headerValue);
566563

567-
List<Locale.LanguageRange> expectedRanges = Arrays.asList(
564+
List<Locale.LanguageRange> expectedRanges = List.of(
568565
new Locale.LanguageRange("en-us"),
569566
new Locale.LanguageRange("en"),
570567
new Locale.LanguageRange("nl")
@@ -614,7 +611,7 @@ void firstZonedDateTime() {
614611
headers.add(HttpHeaders.DATE, "Fri, 02 Jun 2017 02:22:00 GMT");
615612
headers.add(HttpHeaders.DATE, "Sat, 18 Dec 2010 10:20:00 GMT");
616613
assertThat(headers.getFirstZonedDateTime(HttpHeaders.DATE).isEqual(date)).isTrue();
617-
assertThat(headers.get(HttpHeaders.DATE)).isEqualTo(Arrays.asList("Fri, 02 Jun 2017 02:22:00 GMT",
614+
assertThat(headers.get(HttpHeaders.DATE)).isEqualTo(List.of("Fri, 02 Jun 2017 02:22:00 GMT",
618615
"Sat, 18 Dec 2010 10:20:00 GMT"));
619616

620617
// obsolete RFC 850 format
@@ -686,12 +683,12 @@ void keySetOperations() {
686683
assertThat(keySet.toArray()).isEqualTo(new String[] {"Alpha", "Bravo"});
687684

688685
// spliterator() via stream()
689-
assertThat(keySet.stream().collect(toList())).isEqualTo(Arrays.asList("Alpha", "Bravo"));
686+
assertThat(keySet.stream().collect(toList())).isEqualTo(List.of("Alpha", "Bravo"));
690687

691688
// iterator()
692689
List<String> results = new ArrayList<>();
693690
keySet.iterator().forEachRemaining(results::add);
694-
assertThat(results).isEqualTo(Arrays.asList("Alpha", "Bravo"));
691+
assertThat(results).isEqualTo(List.of("Alpha", "Bravo"));
695692

696693
// remove()
697694
assertThat(keySet.remove("Alpha")).isTrue();

0 commit comments

Comments
 (0)