Migrate CacheControl to use java.time.Duration for durations

This commit is contained in:
Lars Grefer
2019-03-08 01:30:55 +01:00
committed by Juergen Hoeller
parent 238286caaf
commit a98e3f0481
2 changed files with 102 additions and 18 deletions

View File

@@ -21,6 +21,7 @@ import org.junit.Test;
import static org.junit.Assert.*;
import java.time.Duration;
import java.util.concurrent.TimeUnit;
/**
@@ -40,6 +41,12 @@ public class CacheControlTests {
assertThat(cc.getHeaderValue(), Matchers.equalTo("max-age=3600"));
}
@Test
public void maxAge_duration() throws Exception {
CacheControl cc = CacheControl.maxAge(Duration.ofHours(1));
assertThat(cc.getHeaderValue(), Matchers.equalTo("max-age=3600"));
}
@Test
public void maxAgeAndDirectives() throws Exception {
CacheControl cc = CacheControl.maxAge(3600, TimeUnit.SECONDS).cachePublic().noTransform();
@@ -52,6 +59,12 @@ public class CacheControlTests {
assertThat(cc.getHeaderValue(), Matchers.equalTo("max-age=3600, s-maxage=1800"));
}
@Test
public void maxAgeAndSMaxAge_duration() throws Exception {
CacheControl cc = CacheControl.maxAge(Duration.ofHours(1)).sMaxAge(Duration.ofMinutes(30));
assertThat(cc.getHeaderValue(), Matchers.equalTo("max-age=3600, s-maxage=1800"));
}
@Test
public void noCachePrivate() throws Exception {
CacheControl cc = CacheControl.noCache().cachePrivate();
@@ -70,10 +83,22 @@ public class CacheControlTests {
assertThat(cc.getHeaderValue(), Matchers.equalTo("max-age=3600, stale-if-error=7200"));
}
@Test
public void staleIfError_duration() throws Exception {
CacheControl cc = CacheControl.maxAge(Duration.ofHours(1)).staleIfError(2, TimeUnit.HOURS);
assertThat(cc.getHeaderValue(), Matchers.equalTo("max-age=3600, stale-if-error=7200"));
}
@Test
public void staleWhileRevalidate() throws Exception {
CacheControl cc = CacheControl.maxAge(1, TimeUnit.HOURS).staleWhileRevalidate(2, TimeUnit.HOURS);
assertThat(cc.getHeaderValue(), Matchers.equalTo("max-age=3600, stale-while-revalidate=7200"));
}
@Test
public void staleWhileRevalidate_duration() throws Exception {
CacheControl cc = CacheControl.maxAge(Duration.ofHours(1)).staleWhileRevalidate(2, TimeUnit.HOURS);
assertThat(cc.getHeaderValue(), Matchers.equalTo("max-age=3600, stale-while-revalidate=7200"));
}
}