Browse Source

Polish some test classes by using predefined constants

Closes gh-24532
pull/24552/head
Hyunjin Choi 6 years ago committed by GitHub
parent
commit
37ba57a921
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      spring-web/src/test/java/org/springframework/http/RequestEntityTests.java
  2. 16
      spring-web/src/test/java/org/springframework/http/ResponseEntityTests.java

18
spring-web/src/test/java/org/springframework/http/RequestEntityTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@ -86,8 +86,8 @@ public class RequestEntityTests { @@ -86,8 +86,8 @@ public class RequestEntityTests {
assertThat(requestEntity).isNotNull();
assertThat(requestEntity.getMethod()).isEqualTo(HttpMethod.GET);
assertThat(requestEntity.getHeaders().containsKey("Accept")).isTrue();
assertThat(requestEntity.getHeaders().getFirst("Accept")).isEqualTo("image/gif, image/jpeg, image/png");
assertThat(requestEntity.getHeaders().containsKey(HttpHeaders.ACCEPT)).isTrue();
assertThat(requestEntity.getHeaders().getFirst(HttpHeaders.ACCEPT)).isEqualTo("image/gif, image/jpeg, image/png");
assertThat(requestEntity.getBody()).isNull();
}
@ -114,12 +114,12 @@ public class RequestEntityTests { @@ -114,12 +114,12 @@ public class RequestEntityTests {
assertThat(responseEntity.getUrl()).isEqualTo(new URI("https://example.com"));
HttpHeaders responseHeaders = responseEntity.getHeaders();
assertThat(responseHeaders.getFirst("Accept")).isEqualTo("text/plain");
assertThat(responseHeaders.getFirst("Accept-Charset")).isEqualTo("utf-8");
assertThat(responseHeaders.getFirst("If-Modified-Since")).isEqualTo("Thu, 01 Jan 1970 00:00:12 GMT");
assertThat(responseHeaders.getFirst("If-None-Match")).isEqualTo(ifNoneMatch);
assertThat(responseHeaders.getFirst("Content-Length")).isEqualTo(String.valueOf(contentLength));
assertThat(responseHeaders.getFirst("Content-Type")).isEqualTo(contentType.toString());
assertThat(responseHeaders.getFirst(HttpHeaders.ACCEPT)).isEqualTo(MediaType.TEXT_PLAIN_VALUE);
assertThat(responseHeaders.getFirst(HttpHeaders.ACCEPT_CHARSET)).isEqualTo("utf-8");
assertThat(responseHeaders.getFirst(HttpHeaders.IF_MODIFIED_SINCE)).isEqualTo("Thu, 01 Jan 1970 00:00:12 GMT");
assertThat(responseHeaders.getFirst(HttpHeaders.IF_NONE_MATCH)).isEqualTo(ifNoneMatch);
assertThat(responseHeaders.getFirst(HttpHeaders.CONTENT_LENGTH)).isEqualTo(String.valueOf(contentLength));
assertThat(responseHeaders.getFirst(HttpHeaders.CONTENT_TYPE)).isEqualTo(contentType.toString());
assertThat(responseEntity.getBody()).isNull();
}

16
spring-web/src/test/java/org/springframework/http/ResponseEntityTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 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.
@ -98,8 +98,8 @@ public class ResponseEntityTests { @@ -98,8 +98,8 @@ public class ResponseEntityTests {
assertThat(responseEntity).isNotNull();
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.CREATED);
assertThat(responseEntity.getHeaders().containsKey("Location")).isTrue();
assertThat(responseEntity.getHeaders().getFirst("Location")).isEqualTo(location.toString());
assertThat(responseEntity.getHeaders().containsKey(HttpHeaders.LOCATION)).isTrue();
assertThat(responseEntity.getHeaders().getFirst(HttpHeaders.LOCATION)).isEqualTo(location.toString());
assertThat(responseEntity.getBody()).isNull();
ResponseEntity.created(location).header("MyResponseHeader", "MyValue").body("Hello World");
@ -178,11 +178,11 @@ public class ResponseEntityTests { @@ -178,11 +178,11 @@ public class ResponseEntityTests {
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
HttpHeaders responseHeaders = responseEntity.getHeaders();
assertThat(responseHeaders.getFirst("Allow")).isEqualTo("GET");
assertThat(responseHeaders.getFirst("Last-Modified")).isEqualTo("Thu, 01 Jan 1970 00:00:12 GMT");
assertThat(responseHeaders.getFirst("Location")).isEqualTo(location.toASCIIString());
assertThat(responseHeaders.getFirst("Content-Length")).isEqualTo(String.valueOf(contentLength));
assertThat(responseHeaders.getFirst("Content-Type")).isEqualTo(contentType.toString());
assertThat(responseHeaders.getFirst(HttpHeaders.ALLOW)).isEqualTo(HttpMethod.GET.name());
assertThat(responseHeaders.getFirst(HttpHeaders.LAST_MODIFIED)).isEqualTo("Thu, 01 Jan 1970 00:00:12 GMT");
assertThat(responseHeaders.getFirst(HttpHeaders.LOCATION)).isEqualTo(location.toASCIIString());
assertThat(responseHeaders.getFirst(HttpHeaders.CONTENT_LENGTH)).isEqualTo(String.valueOf(contentLength));
assertThat(responseHeaders.getFirst(HttpHeaders.CONTENT_TYPE)).isEqualTo(contentType.toString());
assertThat((Object) responseEntity.getBody()).isNull();
}

Loading…
Cancel
Save