Skip to content

Commit d570f82

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 f87a37f commit d570f82

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
@@ -181,14 +181,14 @@ public WebTestClient.ResponseSpec contentTypeCompatibleWith(String mediaType) {
181181
/**
182182
* Expect an "Expires" header with the given value.
183183
*/
184-
public WebTestClient.ResponseSpec expires(int expires) {
184+
public WebTestClient.ResponseSpec expires(long expires) {
185185
return assertHeader("Expires", expires, getHeaders().getExpires());
186186
}
187187

188188
/**
189189
* Expect a "Last-Modified" header with the given value.
190190
*/
191-
public WebTestClient.ResponseSpec lastModified(int lastModified) {
191+
public WebTestClient.ResponseSpec lastModified(long lastModified) {
192192
return assertHeader("Last-Modified", lastModified, getHeaders().getLastModified());
193193
}
194194

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;
@@ -217,6 +219,37 @@ public void cacheControl() {
217219
}
218220
}
219221

222+
@Test
223+
public void expires() {
224+
HttpHeaders headers = new HttpHeaders();
225+
ZonedDateTime expires = ZonedDateTime.of(2018, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC"));
226+
headers.setExpires(expires);
227+
HeaderAssertions assertions = headerAssertions(headers);
228+
assertions.expires(expires.toInstant().toEpochMilli());
229+
try {
230+
assertions.expires(expires.toInstant().toEpochMilli() + 1);
231+
fail("Wrong value expected");
232+
}
233+
catch (AssertionError error) {
234+
// Expected
235+
}
236+
}
237+
238+
@Test
239+
public void lastModified() {
240+
HttpHeaders headers = new HttpHeaders();
241+
ZonedDateTime lastModified = ZonedDateTime.of(2018, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC"));
242+
headers.setLastModified(lastModified.toInstant().toEpochMilli());
243+
HeaderAssertions assertions = headerAssertions(headers);
244+
assertions.lastModified(lastModified.toInstant().toEpochMilli());
245+
try {
246+
assertions.lastModified(lastModified.toInstant().toEpochMilli() + 1);
247+
fail("Wrong value expected");
248+
}
249+
catch (AssertionError error) {
250+
// Expected
251+
}
252+
}
220253

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

0 commit comments

Comments
 (0)