Skip to content

Commit 7635108

Browse files
committed
Add test case for Cache-Control directive.
1 parent f4e81f3 commit 7635108

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/test/kotlin/io/github/nstdio/http/ext/CacheControlTest.kt

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
@file:Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN")
1716

1817
package io.github.nstdio.http.ext
1918

@@ -26,15 +25,14 @@ import org.junit.jupiter.api.Test
2625
import org.junit.jupiter.params.ParameterizedTest
2726
import org.junit.jupiter.params.provider.ValueSource
2827
import java.net.http.HttpHeaders
29-
import java.util.Map
28+
import java.util.concurrent.TimeUnit.MILLISECONDS
3029

3130
internal class CacheControlTest {
3231
@ParameterizedTest
3332
@ValueSource(strings = ["max-age=92233720368547758070,max-stale=92233720368547758070,min-fresh=92233720368547758070", "max-age= ,max-stale=,min-fresh=abc"])
3433
fun shouldNotFailWhenLongOverflow(value: String) {
3534
//given
36-
val httpHeaders =
37-
HttpHeaders.of(Map.of(Headers.HEADER_CACHE_CONTROL, listOf(value))) { _: String?, _: String? -> true }
35+
val httpHeaders = HttpHeaders.of(mapOf(Headers.HEADER_CACHE_CONTROL to listOf(value))) { _, _ -> true }
3836

3937
//when
4038
val actual = CacheControl.of(httpHeaders)
@@ -47,20 +45,20 @@ internal class CacheControlTest {
4745
@ValueSource(strings = ["max-age=32,max-stale=64,min-fresh=128,stale-if-error=256,stale-while-revalidate=512", "max-age=\"32\" ,max-stale=\"64\",min-fresh=\"128\",stale-if-error=\"256\",stale-while-revalidate=\"512\""])
4846
fun shouldParseValues(value: String) {
4947
//given
50-
val httpHeaders =
51-
HttpHeaders.of(Map.of(Headers.HEADER_CACHE_CONTROL, listOf(value))) { _: String?, _: String? -> true }
48+
val httpHeaders = HttpHeaders.of(mapOf(Headers.HEADER_CACHE_CONTROL to listOf(value))) { _, _ -> true }
5249

5350
//when
5451
val actual = CacheControl.of(httpHeaders)
5552

5653
//then
57-
assertThat(actual.maxAge()).isEqualTo(32)
58-
assertThat(actual.maxStale()).isEqualTo(64)
59-
assertThat(actual.minFresh()).isEqualTo(128)
60-
assertThat(actual.staleIfError()).isEqualTo(256)
61-
assertThat(actual.staleWhileRevalidate()).isEqualTo(512)
62-
assertThat(actual)
63-
.hasToString("max-age=32, max-stale=64, min-fresh=128, stale-if-error=256, stale-while-revalidate=512")
54+
actual.maxAge() shouldBe 32
55+
actual.maxStale() shouldBe 64
56+
actual.minFresh() shouldBe 128
57+
actual.staleIfError() shouldBe 256
58+
actual.staleWhileRevalidate() shouldBe 512
59+
actual.staleWhileRevalidate(MILLISECONDS) shouldBe 512000
60+
61+
actual.toString() shouldBe "max-age=32, max-stale=64, min-fresh=128, stale-if-error=256, stale-while-revalidate=512"
6462
}
6563

6664
@Test
@@ -92,7 +90,7 @@ internal class CacheControlTest {
9290
""".trimIndent().replace("\n", " ")
9391

9492
//when + then
95-
cc.toString().shouldBe(expected)
93+
cc.toString() shouldBe expected
9694
assertThat(CacheControl.parse(expected))
9795
.usingRecursiveComparison()
9896
.isEqualTo(cc)

0 commit comments

Comments
 (0)