Make ResponseSpec.expectBody Kotlin extension usable

Prior to this commit, due to KT-5464 type inference issue there was not
proper way to provide body expectations with WebTestClient. This commit
provides a workaround by updating the existing Kotlin extension to
return a Kotlin compatible API.

Issue: SPR-15692
This commit is contained in:
sdeleuze
2018-04-17 14:32:53 +02:00
parent 9d37c099a8
commit 91c8b62817
3 changed files with 76 additions and 9 deletions

View File

@@ -19,12 +19,15 @@ package org.springframework.test.web.reactive.server
import com.nhaarman.mockito_kotlin.mock
import com.nhaarman.mockito_kotlin.times
import com.nhaarman.mockito_kotlin.verify
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Answers
import org.mockito.Mock
import org.mockito.junit.MockitoJUnitRunner
import org.reactivestreams.Publisher
import org.springframework.web.reactive.function.server.ServerResponse.*
import org.springframework.web.reactive.function.server.router
/**
* Mock object based tests for [WebTestClient] Kotlin extensions
@@ -54,6 +57,30 @@ class WebTestClientExtensionsTests {
verify(responseSpec, times(1)).expectBody(Foo::class.java)
}
@Test
fun `KotlinBodySpec#isEqualTo`() {
WebTestClient
.bindToRouterFunction( router { GET("/") { ok().syncBody("foo") } } )
.build()
.get().uri("/").exchange().expectBody<String>().isEqualTo("foo")
}
@Test
fun `KotlinBodySpec#consumeWith`() {
WebTestClient
.bindToRouterFunction( router { GET("/") { ok().syncBody("foo") } } )
.build()
.get().uri("/").exchange().expectBody<String>().consumeWith { assertEquals("foo", it.responseBody) }
}
@Test
fun `KotlinBodySpec#returnResult`() {
WebTestClient
.bindToRouterFunction( router { GET("/") { ok().syncBody("foo") } } )
.build()
.get().uri("/").exchange().expectBody<String>().returnResult().apply { assertEquals("foo", responseBody) }
}
@Test
fun `ResponseSpec#expectBodyList with reified type parameters`() {
responseSpec.expectBodyList<Foo>()