Browse Source

Polishing

pull/23019/head
Sam Brannen 6 years ago
parent
commit
9ca7354146
  1. 31
      spring-web/src/test/java/org/springframework/http/HttpHeadersTests.java

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

@ -34,11 +34,12 @@ import java.util.List; @@ -34,11 +34,12 @@ import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
import org.hamcrest.Matchers;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.emptyCollectionOf;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@ -182,8 +183,7 @@ public class HttpHeadersTests { @@ -182,8 +183,7 @@ public class HttpHeadersTests {
@Test
public void illegalETag() {
String eTag = "v2.6";
assertThatIllegalArgumentException().isThrownBy(() ->
headers.setETag(eTag));
assertThatIllegalArgumentException().isThrownBy(() -> headers.setETag(eTag));
}
@Test
@ -197,8 +197,7 @@ public class HttpHeadersTests { @@ -197,8 +197,7 @@ public class HttpHeadersTests {
@Test
public void ifMatchIllegalHeader() {
headers.setIfMatch("Illegal");
assertThatIllegalArgumentException().isThrownBy(
headers::getIfMatch);
assertThatIllegalArgumentException().isThrownBy(headers::getIfMatch);
}
@Test
@ -207,7 +206,7 @@ public class HttpHeadersTests { @@ -207,7 +206,7 @@ public class HttpHeadersTests {
headers.add(HttpHeaders.IF_MATCH, "W/\"v2,1\", \"v2,2\"");
assertEquals("Invalid If-Match header", "\"v2,0\"", headers.get(HttpHeaders.IF_MATCH).get(0));
assertEquals("Invalid If-Match header", "W/\"v2,1\", \"v2,2\"", headers.get(HttpHeaders.IF_MATCH).get(1));
assertThat(headers.getIfMatch(), Matchers.contains("\"v2,0\"", "W/\"v2,1\"", "\"v2,2\""));
assertThat(headers.getIfMatch(), contains("\"v2,0\"", "W/\"v2,1\"", "\"v2,2\""));
}
@Test
@ -234,7 +233,7 @@ public class HttpHeadersTests { @@ -234,7 +233,7 @@ public class HttpHeadersTests {
ifNoneMatchList.add(ifNoneMatch1);
ifNoneMatchList.add(ifNoneMatch2);
headers.setIfNoneMatch(ifNoneMatchList);
assertThat(headers.getIfNoneMatch(), Matchers.contains("\"v2.6\"", "\"v2.7\"", "\"v2.8\""));
assertThat(headers.getIfNoneMatch(), contains("\"v2.6\"", "\"v2.7\"", "\"v2.8\""));
assertEquals("Invalid If-None-Match header", "\"v2.6\", \"v2.7\", \"v2.8\"", headers.getFirst("If-None-Match"));
}
@ -255,8 +254,7 @@ public class HttpHeadersTests { @@ -255,8 +254,7 @@ public class HttpHeadersTests {
@Test
public void dateInvalid() {
headers.set("Date", "Foo Bar Baz");
assertThatIllegalArgumentException().isThrownBy(
headers::getDate);
assertThatIllegalArgumentException().isThrownBy(headers::getDate);
}
@Test
@ -384,7 +382,7 @@ public class HttpHeadersTests { @@ -384,7 +382,7 @@ public class HttpHeadersTests {
@Test // SPR-11917
public void getAllowEmptySet() {
headers.setAllow(Collections.emptySet());
assertThat(headers.getAllow(), Matchers.emptyCollectionOf(HttpMethod.class));
assertThat(headers.getAllow(), is(emptyCollectionOf(HttpMethod.class)));
}
@Test
@ -399,7 +397,7 @@ public class HttpHeadersTests { @@ -399,7 +397,7 @@ public class HttpHeadersTests {
@Test
public void accessControlAllowHeaders() {
List<String> allowedHeaders = headers.getAccessControlAllowHeaders();
assertThat(allowedHeaders, Matchers.emptyCollectionOf(String.class));
assertThat(allowedHeaders, is(emptyCollectionOf(String.class)));
headers.setAccessControlAllowHeaders(Arrays.asList("header1", "header2"));
allowedHeaders = headers.getAccessControlAllowHeaders();
assertEquals(allowedHeaders, Arrays.asList("header1", "header2"));
@ -408,7 +406,7 @@ public class HttpHeadersTests { @@ -408,7 +406,7 @@ public class HttpHeadersTests {
@Test
public void accessControlAllowHeadersMultipleValues() {
List<String> allowedHeaders = headers.getAccessControlAllowHeaders();
assertThat(allowedHeaders, Matchers.emptyCollectionOf(String.class));
assertThat(allowedHeaders, is(emptyCollectionOf(String.class)));
headers.add(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS, "header1, header2");
headers.add(HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS, "header3");
allowedHeaders = headers.getAccessControlAllowHeaders();
@ -418,7 +416,7 @@ public class HttpHeadersTests { @@ -418,7 +416,7 @@ public class HttpHeadersTests {
@Test
public void accessControlAllowMethods() {
List<HttpMethod> allowedMethods = headers.getAccessControlAllowMethods();
assertThat(allowedMethods, Matchers.emptyCollectionOf(HttpMethod.class));
assertThat(allowedMethods, is(emptyCollectionOf(HttpMethod.class)));
headers.setAccessControlAllowMethods(Arrays.asList(HttpMethod.GET, HttpMethod.POST));
allowedMethods = headers.getAccessControlAllowMethods();
assertEquals(allowedMethods, Arrays.asList(HttpMethod.GET, HttpMethod.POST));
@ -434,7 +432,7 @@ public class HttpHeadersTests { @@ -434,7 +432,7 @@ public class HttpHeadersTests {
@Test
public void accessControlExposeHeaders() {
List<String> exposedHeaders = headers.getAccessControlExposeHeaders();
assertThat(exposedHeaders, Matchers.emptyCollectionOf(String.class));
assertThat(exposedHeaders, is(emptyCollectionOf(String.class)));
headers.setAccessControlExposeHeaders(Arrays.asList("header1", "header2"));
exposedHeaders = headers.getAccessControlExposeHeaders();
assertEquals(exposedHeaders, Arrays.asList("header1", "header2"));
@ -450,7 +448,7 @@ public class HttpHeadersTests { @@ -450,7 +448,7 @@ public class HttpHeadersTests {
@Test
public void accessControlRequestHeaders() {
List<String> requestHeaders = headers.getAccessControlRequestHeaders();
assertThat(requestHeaders, Matchers.emptyCollectionOf(String.class));
assertThat(requestHeaders, is(emptyCollectionOf(String.class)));
headers.setAccessControlRequestHeaders(Arrays.asList("header1", "header2"));
requestHeaders = headers.getAccessControlRequestHeaders();
assertEquals(requestHeaders, Arrays.asList("header1", "header2"));
@ -555,8 +553,7 @@ public class HttpHeadersTests { @@ -555,8 +553,7 @@ public class HttpHeadersTests {
public void basicAuthIllegalChar() {
String username = "foo";
String password = "\u03BB";
assertThatIllegalArgumentException().isThrownBy(() ->
headers.setBasicAuth(username, password));
assertThatIllegalArgumentException().isThrownBy(() -> headers.setBasicAuth(username, password));
}
@Test

Loading…
Cancel
Save