Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
snicoll committed Jan 9, 2024
1 parent 4b04430 commit c440510
Show file tree
Hide file tree
Showing 209 changed files with 1,487 additions and 1,551 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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 @@ -28,7 +28,7 @@
/**
* @author Arjen Poutsma
*/
public class HttpEntityTests {
class HttpEntityTests {

@Test
void noHeaders() {
Expand Down Expand Up @@ -104,7 +104,7 @@ void responseEntity() {
}

@Test
void requestEntity() throws Exception {
void requestEntity() {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.TEXT_PLAIN);
String body = "foo";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.net.InetSocketAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.time.ZoneId;
Expand Down Expand Up @@ -53,7 +52,7 @@
* @author Juergen Hoeller
* @author Sam Brannen
*/
public class HttpHeadersTests {
class HttpHeadersTests {

private final HttpHeaders headers = new HttpHeaders();

Expand Down Expand Up @@ -152,7 +151,7 @@ void contentType() {
}

@Test
void location() throws URISyntaxException {
void location() {
URI location = URI.create("https://www.example.com/hotels");
headers.setLocation(location);
assertThat(headers.getLocation()).as("Invalid Location header").isEqualTo(location);
Expand Down Expand Up @@ -201,7 +200,7 @@ void illegalETag() {
void ifMatch() {
String ifMatch = "\"v2.6\"";
headers.setIfMatch(ifMatch);
assertThat(headers.getIfMatch()).element(0).as("Invalid If-Match header").isEqualTo(ifMatch);
assertThat(headers.getIfMatch()).containsExactly(ifMatch);
assertThat(headers.getFirst("If-Match")).as("Invalid If-Match header").isEqualTo("\"v2.6\"");
}

Expand All @@ -215,24 +214,23 @@ void ifMatchIllegalHeader() {
void ifMatchMultipleHeaders() {
headers.add(HttpHeaders.IF_MATCH, "\"v2,0\"");
headers.add(HttpHeaders.IF_MATCH, "W/\"v2,1\", \"v2,2\"");
assertThat(headers.get(HttpHeaders.IF_MATCH)).element(0).as("Invalid If-Match header").isEqualTo("\"v2,0\"");
assertThat(headers.get(HttpHeaders.IF_MATCH)).element(1).as("Invalid If-Match header").isEqualTo("W/\"v2,1\", \"v2,2\"");
assertThat(headers.get(HttpHeaders.IF_MATCH)).containsExactly("\"v2,0\"", "W/\"v2,1\", \"v2,2\"");
assertThat(headers.getIfMatch()).contains("\"v2,0\"", "W/\"v2,1\"", "\"v2,2\"");
}

@Test
void ifNoneMatch() {
String ifNoneMatch = "\"v2.6\"";
headers.setIfNoneMatch(ifNoneMatch);
assertThat(headers.getIfNoneMatch()).element(0).as("Invalid If-None-Match header").isEqualTo(ifNoneMatch);
assertThat(headers.getIfNoneMatch()).containsExactly(ifNoneMatch);
assertThat(headers.getFirst("If-None-Match")).as("Invalid If-None-Match header").isEqualTo("\"v2.6\"");
}

@Test
void ifNoneMatchWildCard() {
String ifNoneMatch = "*";
headers.setIfNoneMatch(ifNoneMatch);
assertThat(headers.getIfNoneMatch()).element(0).as("Invalid If-None-Match header").isEqualTo(ifNoneMatch);
assertThat(headers.getIfNoneMatch()).containsExactly(ifNoneMatch);
assertThat(headers.getFirst("If-None-Match")).as("Invalid If-None-Match header").isEqualTo("*");
}

Expand Down Expand Up @@ -492,7 +490,7 @@ void acceptLanguage() {
}

@Test // SPR-15603
void acceptLanguageWithEmptyValue() throws Exception {
void acceptLanguageWithEmptyValue() {
this.headers.set(HttpHeaders.ACCEPT_LANGUAGE, "");
assertThat(this.headers.getAcceptLanguageAsLocales()).isEqualTo(Collections.emptyList());
}
Expand Down Expand Up @@ -657,7 +655,7 @@ void keySetRemovalChecks() {
assertThat(headers.containsKey("Alpha")).as("Alpha should have been removed").isFalse();
assertThat(headers.containsKey("Bravo")).as("Bravo should be present").isTrue();
assertThat(headers.keySet()).containsOnly("Bravo");
assertThat(headers.entrySet()).containsOnly(entry("Bravo", Arrays.asList("banana")));
assertThat(headers.entrySet()).containsOnly(entry("Bravo", List.of("banana")));
}

@Test
Expand All @@ -671,7 +669,7 @@ void removalFromKeySetRemovesEntryFromUnderlyingMap() {
headers.keySet().removeIf(key -> key.equals(headerName));
assertThat(headers).isEmpty();
headers.add(headerName, headerValue);
assertThat(headers.get(headerName)).element(0).isEqualTo(headerValue);
assertThat(headers.get(headerName)).containsExactly(headerValue);
}

@Test
Expand All @@ -685,7 +683,7 @@ void removalFromEntrySetRemovesEntryFromUnderlyingMap() {
headers.entrySet().removeIf(entry -> entry.getKey().equals(headerName));
assertThat(headers).isEmpty();
headers.add(headerName, headerValue);
assertThat(headers.get(headerName)).element(0).isEqualTo(headerValue);
assertThat(headers.get(headerName)).containsExactly(headerValue);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2024 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 @@ -26,7 +26,7 @@
class HttpMethodTests {

@Test
public void comparison() {
void comparison() {
HttpMethod method1 = HttpMethod.valueOf("FOO");
HttpMethod method2 = HttpMethod.valueOf("FOO");
HttpMethod method3 = HttpMethod.valueOf("BAR");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,63 +38,63 @@
* @author Rossen Stoyanchev
* @author Brian Clozel
*/
public class HttpRangeTests {
class HttpRangeTests {

@Test
public void invalidFirstPosition() {
void invalidFirstPosition() {
assertThatIllegalArgumentException().isThrownBy(() ->
HttpRange.createByteRange(-1));
}

@Test
public void invalidLastLessThanFirst() {
void invalidLastLessThanFirst() {
assertThatIllegalArgumentException().isThrownBy(() ->
HttpRange.createByteRange(10, 9));
}

@Test
public void invalidSuffixLength() {
void invalidSuffixLength() {
assertThatIllegalArgumentException().isThrownBy(() ->
HttpRange.createSuffixRange(-1));
}

@Test
public void byteRange() {
void byteRange() {
HttpRange range = HttpRange.createByteRange(0, 499);
assertThat(range.getRangeStart(1000)).isEqualTo(0);
assertThat(range.getRangeEnd(1000)).isEqualTo(499);
}

@Test
public void byteRangeWithoutLastPosition() {
void byteRangeWithoutLastPosition() {
HttpRange range = HttpRange.createByteRange(9500);
assertThat(range.getRangeStart(10000)).isEqualTo(9500);
assertThat(range.getRangeEnd(10000)).isEqualTo(9999);
}

@Test
public void byteRangeOfZeroLength() {
void byteRangeOfZeroLength() {
HttpRange range = HttpRange.createByteRange(9500, 9500);
assertThat(range.getRangeStart(10000)).isEqualTo(9500);
assertThat(range.getRangeEnd(10000)).isEqualTo(9500);
}

@Test
public void suffixRange() {
void suffixRange() {
HttpRange range = HttpRange.createSuffixRange(500);
assertThat(range.getRangeStart(1000)).isEqualTo(500);
assertThat(range.getRangeEnd(1000)).isEqualTo(999);
}

@Test
public void suffixRangeShorterThanRepresentation() {
void suffixRangeShorterThanRepresentation() {
HttpRange range = HttpRange.createSuffixRange(500);
assertThat(range.getRangeStart(350)).isEqualTo(0);
assertThat(range.getRangeEnd(350)).isEqualTo(349);
}

@Test
public void parseRanges() {
void parseRanges() {
List<HttpRange> ranges = HttpRange.parseRanges("bytes=0-0,500-,-1");
assertThat(ranges).hasSize(3);
assertThat(ranges.get(0).getRangeStart(1000)).isEqualTo(0);
Expand All @@ -106,7 +106,7 @@ public void parseRanges() {
}

@Test
public void parseRangesValidations() {
void parseRangesValidations() {

// 1. At limit..
StringBuilder atLimit = new StringBuilder("bytes=0-0");
Expand All @@ -126,7 +126,7 @@ public void parseRangesValidations() {
}

@Test
public void rangeToString() {
void rangeToString() {
List<HttpRange> ranges = new ArrayList<>();
ranges.add(HttpRange.createByteRange(0, 499));
ranges.add(HttpRange.createByteRange(9500));
Expand All @@ -135,7 +135,7 @@ public void rangeToString() {
}

@Test
public void toResourceRegion() {
void toResourceRegion() {
byte[] bytes = "Spring Framework".getBytes(StandardCharsets.UTF_8);
ByteArrayResource resource = new ByteArrayResource(bytes);
HttpRange range = HttpRange.createByteRange(0, 5);
Expand All @@ -146,23 +146,23 @@ public void toResourceRegion() {
}

@Test
public void toResourceRegionInputStreamResource() {
void toResourceRegionInputStreamResource() {
InputStreamResource resource = mock();
HttpRange range = HttpRange.createByteRange(0, 9);
assertThatIllegalArgumentException().isThrownBy(() ->
range.toResourceRegion(resource));
}

@Test
public void toResourceRegionIllegalLength() {
void toResourceRegionIllegalLength() {
ByteArrayResource resource = mock();
given(resource.contentLength()).willReturn(-1L);
HttpRange range = HttpRange.createByteRange(0, 9);
assertThatIllegalArgumentException().isThrownBy(() -> range.toResourceRegion(resource));
}

@Test
public void toResourceRegionExceptionLength() throws IOException {
void toResourceRegionExceptionLength() throws IOException {
InputStreamResource resource = mock();
given(resource.contentLength()).willThrow(IOException.class);
HttpRange range = HttpRange.createByteRange(0, 9);
Expand All @@ -178,7 +178,7 @@ public void toResourceRegionStartingAtResourceByteCount() {
}

@Test
public void toResourceRegionsValidations() {
void toResourceRegionsValidations() {
byte[] bytes = "12345".getBytes(StandardCharsets.UTF_8);
ByteArrayResource resource = new ByteArrayResource(bytes);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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 @@ -25,18 +25,18 @@
/**
* @author Arjen Poutsma
*/
public class MediaTypeFactoryTests {
class MediaTypeFactoryTests {

@Test
public void getMediaType() {
void getMediaType() {
assertThat(MediaTypeFactory.getMediaType("file.xml")).contains(MediaType.APPLICATION_XML);
assertThat(MediaTypeFactory.getMediaType("file.js")).contains(MediaType.parseMediaType("application/javascript"));
assertThat(MediaTypeFactory.getMediaType("file.css")).contains(MediaType.parseMediaType("text/css"));
assertThat(MediaTypeFactory.getMediaType("file.foobar")).isNotPresent();
}

@Test
public void nullParameter() {
void nullParameter() {
assertThat(MediaTypeFactory.getMediaType((String) null)).isNotPresent();
assertThat(MediaTypeFactory.getMediaType((Resource) null)).isNotPresent();
assertThat(MediaTypeFactory.getMediaTypes(null)).isEmpty();
Expand Down
Loading

0 comments on commit c440510

Please sign in to comment.