Skip to content

Commit ee559bb

Browse files
makingrstoyanchev
authored andcommitted
Use long for expires and lastModified in HeaderAssertions
This commit changes the type of parameters so that HeaderAssertions can assert expires and lastModified properly. Issue: SPR-17194
1 parent 1371cfe commit ee559bb

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

spring-test/src/main/java/org/springframework/test/web/reactive/server/HeaderAssertions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,14 @@ public WebTestClient.ResponseSpec contentTypeCompatibleWith(String mediaType) {
152152
/**
153153
* Expect an "Expires" header with the given value.
154154
*/
155-
public WebTestClient.ResponseSpec expires(int expires) {
155+
public WebTestClient.ResponseSpec expires(long expires) {
156156
return assertHeader("Expires", expires, getHeaders().getExpires());
157157
}
158158

159159
/**
160160
* Expect a "Last-Modified" header with the given value.
161161
*/
162-
public WebTestClient.ResponseSpec lastModified(int lastModified) {
162+
public WebTestClient.ResponseSpec lastModified(long lastModified) {
163163
return assertHeader("Last-Modified", lastModified, getHeaders().getLastModified());
164164
}
165165

spring-test/src/test/java/org/springframework/test/web/reactive/server/HeaderAssertionTests.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package org.springframework.test.web.reactive.server;
1818

1919
import java.net.URI;
20+
import java.time.ZoneId;
21+
import java.time.ZonedDateTime;
2022
import java.util.concurrent.TimeUnit;
2123

2224
import org.junit.Test;
@@ -207,6 +209,37 @@ public void cacheControl() {
207209
}
208210
}
209211

212+
@Test
213+
public void expires() {
214+
HttpHeaders headers = new HttpHeaders();
215+
ZonedDateTime expires = ZonedDateTime.of(2018, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC"));
216+
headers.setExpires(expires);
217+
HeaderAssertions assertions = headerAssertions(headers);
218+
assertions.expires(expires.toInstant().toEpochMilli());
219+
try {
220+
assertions.expires(expires.toInstant().toEpochMilli() + 1);
221+
fail("Wrong value expected");
222+
}
223+
catch (AssertionError error) {
224+
// Expected
225+
}
226+
}
227+
228+
@Test
229+
public void lastModified() {
230+
HttpHeaders headers = new HttpHeaders();
231+
ZonedDateTime lastModified = ZonedDateTime.of(2018, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC"));
232+
headers.setLastModified(lastModified.toInstant().toEpochMilli());
233+
HeaderAssertions assertions = headerAssertions(headers);
234+
assertions.lastModified(lastModified.toInstant().toEpochMilli());
235+
try {
236+
assertions.lastModified(lastModified.toInstant().toEpochMilli() + 1);
237+
fail("Wrong value expected");
238+
}
239+
catch (AssertionError error) {
240+
// Expected
241+
}
242+
}
210243

211244
private HeaderAssertions headerAssertions(HttpHeaders responseHeaders) {
212245
MockClientHttpRequest request = new MockClientHttpRequest(HttpMethod.GET, URI.create("/"));

0 commit comments

Comments
 (0)