Migrate to AssertJ in Kotlin tests
Closes gh-23475
This commit is contained in:
@@ -21,8 +21,7 @@ import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertNull
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.core.ParameterizedTypeReference
|
||||
import org.springframework.http.HttpStatus
|
||||
@@ -74,7 +73,7 @@ class ClientResponseExtensionsTests {
|
||||
val response = mockk<ClientResponse>()
|
||||
every { response.bodyToMono<String>() } returns Mono.just("foo")
|
||||
runBlocking {
|
||||
assertEquals("foo", response.awaitBody<String>())
|
||||
assertThat(response.awaitBody<String>()).isEqualTo("foo")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +82,7 @@ class ClientResponseExtensionsTests {
|
||||
val response = mockk<ClientResponse>()
|
||||
every { response.bodyToMono<String>() } returns Mono.empty()
|
||||
runBlocking {
|
||||
assertNull(response.awaitBodyOrNull<String>())
|
||||
assertThat(response.awaitBodyOrNull<String>()).isNull()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +92,7 @@ class ClientResponseExtensionsTests {
|
||||
val entity = ResponseEntity("foo", HttpStatus.OK)
|
||||
every { response.toEntity<String>() } returns Mono.just(entity)
|
||||
runBlocking {
|
||||
assertEquals(entity, response.awaitEntity<String>())
|
||||
assertThat(response.awaitEntity<String>()).isEqualTo(entity)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +102,7 @@ class ClientResponseExtensionsTests {
|
||||
val entity = ResponseEntity(listOf("foo"), HttpStatus.OK)
|
||||
every { response.toEntityList<String>() } returns Mono.just(entity)
|
||||
runBlocking {
|
||||
assertEquals(entity, response.awaitEntityList<String>())
|
||||
assertThat(response.awaitEntityList<String>()).isEqualTo(entity)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import io.mockk.verify
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.reactivestreams.Publisher
|
||||
import org.springframework.core.ParameterizedTypeReference
|
||||
@@ -86,7 +86,7 @@ class WebClientExtensionsTests {
|
||||
val response = mockk<ClientResponse>()
|
||||
every { requestBodySpec.exchange() } returns Mono.just(response)
|
||||
runBlocking {
|
||||
assertEquals(response, requestBodySpec.awaitExchange())
|
||||
assertThat(requestBodySpec.awaitExchange()).isEqualTo(response)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ class WebClientExtensionsTests {
|
||||
val spec = mockk<WebClient.ResponseSpec>()
|
||||
every { spec.bodyToMono<String>() } returns Mono.just("foo")
|
||||
runBlocking {
|
||||
assertEquals("foo", spec.awaitBody<String>())
|
||||
assertThat(spec.awaitBody<String>()).isEqualTo("foo")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,10 @@
|
||||
|
||||
package org.springframework.web.reactive.function.server
|
||||
|
||||
import org.junit.jupiter.api.fail
|
||||
import org.assertj.core.api.Assertions
|
||||
import org.assertj.core.api.Assertions.assertThatExceptionOfType
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.fail
|
||||
import org.springframework.core.io.ClassPathResource
|
||||
import org.springframework.http.HttpHeaders.*
|
||||
import org.springframework.http.HttpMethod.*
|
||||
@@ -122,12 +124,8 @@ class CoRouterFunctionDslTests {
|
||||
|
||||
@Test
|
||||
fun emptyRouter() {
|
||||
try {
|
||||
assertThatExceptionOfType(IllegalStateException::class.java).isThrownBy {
|
||||
router { }
|
||||
fail("should have thrown an IllegalStateException")
|
||||
}
|
||||
catch (e: IllegalStateException) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,10 @@
|
||||
|
||||
package org.springframework.web.reactive.function.server
|
||||
|
||||
import org.junit.jupiter.api.fail
|
||||
import org.assertj.core.api.Assertions
|
||||
import org.assertj.core.api.Assertions.assertThatExceptionOfType
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.fail
|
||||
import org.springframework.core.io.ClassPathResource
|
||||
import org.springframework.http.HttpHeaders.*
|
||||
import org.springframework.http.HttpMethod.*
|
||||
@@ -123,12 +125,8 @@ class RouterFunctionDslTests {
|
||||
|
||||
@Test
|
||||
fun emptyRouter() {
|
||||
try {
|
||||
assertThatExceptionOfType(IllegalStateException::class.java).isThrownBy {
|
||||
router { }
|
||||
fail("should have thrown an IllegalStateException")
|
||||
}
|
||||
catch (e: IllegalStateException) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,8 +21,7 @@ import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertNull
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.core.ParameterizedTypeReference
|
||||
import org.springframework.http.codec.multipart.Part
|
||||
@@ -63,7 +62,7 @@ class ServerRequestExtensionsTests {
|
||||
fun awaitBody() {
|
||||
every { request.bodyToMono<String>() } returns Mono.just("foo")
|
||||
runBlocking {
|
||||
assertEquals("foo", request.awaitBody<String>())
|
||||
assertThat(request.awaitBody<String>()).isEqualTo("foo")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +70,7 @@ class ServerRequestExtensionsTests {
|
||||
fun awaitBodyOrNull() {
|
||||
every { request.bodyToMono<String>() } returns Mono.empty()
|
||||
runBlocking {
|
||||
assertNull(request.awaitBodyOrNull<String>())
|
||||
assertThat(request.awaitBodyOrNull<String>()).isNull()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +79,7 @@ class ServerRequestExtensionsTests {
|
||||
val map = mockk<MultiValueMap<String, String>>()
|
||||
every { request.formData() } returns Mono.just(map)
|
||||
runBlocking {
|
||||
assertEquals(map, request.awaitFormData())
|
||||
assertThat(request.awaitFormData()).isEqualTo(map)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +88,7 @@ class ServerRequestExtensionsTests {
|
||||
val map = mockk<MultiValueMap<String, Part>>()
|
||||
every { request.multipartData() } returns Mono.just(map)
|
||||
runBlocking {
|
||||
assertEquals(map, request.awaitMultipartData())
|
||||
assertThat(request.awaitMultipartData()).isEqualTo(map)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +97,7 @@ class ServerRequestExtensionsTests {
|
||||
val principal = mockk<Principal>()
|
||||
every { request.principal() } returns Mono.just(principal)
|
||||
runBlocking {
|
||||
assertEquals(principal, request.awaitPrincipal())
|
||||
assertThat(request.awaitPrincipal()).isEqualTo(principal)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +106,7 @@ class ServerRequestExtensionsTests {
|
||||
val session = mockk<WebSession>()
|
||||
every { request.session() } returns Mono.just(session)
|
||||
runBlocking {
|
||||
assertEquals(session, request.awaitSession())
|
||||
assertThat(request.awaitSession()).isEqualTo(session)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import io.reactivex.Flowable
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.reactivestreams.Publisher
|
||||
import org.springframework.core.ParameterizedTypeReference
|
||||
@@ -145,7 +145,7 @@ class ServerResponseExtensionsTests {
|
||||
val builder = mockk<ServerResponse.HeadersBuilder<*>>()
|
||||
every { builder.build() } returns Mono.just(response)
|
||||
runBlocking {
|
||||
assertEquals(response, builder.buildAndAwait())
|
||||
assertThat(builder.buildAndAwait()).isEqualTo(response)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,9 +19,7 @@ package org.springframework.web.reactive.result
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import kotlinx.coroutines.delay
|
||||
import org.hamcrest.CoreMatchers.`is`
|
||||
import org.hamcrest.MatcherAssert.assertThat
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.http.server.reactive.ServerHttpResponse
|
||||
@@ -83,7 +81,7 @@ class KotlinInvocableHandlerMethodTests {
|
||||
val result = invoke(CoroutinesController(), method)
|
||||
|
||||
assertHandlerResultValue(result, "created")
|
||||
assertThat<HttpStatus>(this.exchange.response.statusCode, `is`(HttpStatus.CREATED))
|
||||
assertThat(this.exchange.response.statusCode).isSameAs(HttpStatus.CREATED)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -96,7 +94,7 @@ class KotlinInvocableHandlerMethodTests {
|
||||
StepVerifier.create(result)
|
||||
.consumeNextWith { StepVerifier.create(it.returnValue as Mono<*>).verifyComplete() }
|
||||
.verifyComplete()
|
||||
assertEquals("bar", this.exchange.response.headers.getFirst("foo"))
|
||||
assertThat(this.exchange.response.headers.getFirst("foo")).isEqualTo("bar")
|
||||
}
|
||||
|
||||
private fun invoke(handler: Any, method: Method, vararg providedArgs: Any?): Mono<HandlerResult> {
|
||||
|
||||
@@ -17,14 +17,12 @@
|
||||
package org.springframework.web.reactive.result.method.annotation
|
||||
|
||||
import kotlinx.coroutines.Deferred
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.fail
|
||||
import org.assertj.core.api.Assertions.*
|
||||
import org.springframework.context.ApplicationContext
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||
import org.springframework.context.annotation.ComponentScan
|
||||
@@ -37,7 +35,6 @@ import org.springframework.web.bind.annotation.RestController
|
||||
import org.springframework.web.client.HttpServerErrorException
|
||||
import org.springframework.web.reactive.config.EnableWebFlux
|
||||
|
||||
@ExperimentalCoroutinesApi
|
||||
class CoroutinesIntegrationTests : AbstractRequestMappingIntegrationTests() {
|
||||
|
||||
override fun initApplicationContext(): ApplicationContext {
|
||||
@@ -53,8 +50,8 @@ class CoroutinesIntegrationTests : AbstractRequestMappingIntegrationTests() {
|
||||
startServer(httpServer)
|
||||
|
||||
val entity = performGet<String>("/suspend", HttpHeaders.EMPTY, String::class.java)
|
||||
assertEquals(HttpStatus.OK, entity.statusCode)
|
||||
assertEquals("foo", entity.body)
|
||||
assertThat(entity.statusCode).isEqualTo(HttpStatus.OK)
|
||||
assertThat(entity.body).isEqualTo("foo")
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
@@ -62,8 +59,8 @@ class CoroutinesIntegrationTests : AbstractRequestMappingIntegrationTests() {
|
||||
startServer(httpServer)
|
||||
|
||||
val entity = performGet<String>("/deferred", HttpHeaders.EMPTY, String::class.java)
|
||||
assertEquals(HttpStatus.OK, entity.statusCode)
|
||||
assertEquals("foo", entity.body)
|
||||
assertThat(entity.statusCode).isEqualTo(HttpStatus.OK)
|
||||
assertThat(entity.body).isEqualTo("foo")
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
@@ -71,8 +68,8 @@ class CoroutinesIntegrationTests : AbstractRequestMappingIntegrationTests() {
|
||||
startServer(httpServer)
|
||||
|
||||
val entity = performGet<String>("/flow", HttpHeaders.EMPTY, String::class.java)
|
||||
assertEquals(HttpStatus.OK, entity.statusCode)
|
||||
assertEquals("foobar", entity.body)
|
||||
assertThat(entity.statusCode).isEqualTo(HttpStatus.OK)
|
||||
assertThat(entity.body).isEqualTo("foobar")
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
@@ -80,19 +77,16 @@ class CoroutinesIntegrationTests : AbstractRequestMappingIntegrationTests() {
|
||||
startServer(httpServer)
|
||||
|
||||
val entity = performGet<String>("/suspending-flow", HttpHeaders.EMPTY, String::class.java)
|
||||
assertEquals(HttpStatus.OK, entity.statusCode)
|
||||
assertEquals("foobar", entity.body)
|
||||
assertThat(entity.statusCode).isEqualTo(HttpStatus.OK)
|
||||
assertThat(entity.body).isEqualTo("foobar")
|
||||
}
|
||||
|
||||
@ParameterizedHttpServerTest
|
||||
fun `Suspending handler method throwing exception`(httpServer: HttpServer) {
|
||||
startServer(httpServer)
|
||||
|
||||
try {
|
||||
assertThatExceptionOfType(HttpServerErrorException.InternalServerError::class.java).isThrownBy {
|
||||
performGet<String>("/error", HttpHeaders.EMPTY, String::class.java)
|
||||
fail("should have thrown an HttpServerErrorException.InternalServerError")
|
||||
} catch (e: HttpServerErrorException.InternalServerError) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,11 +94,8 @@ class CoroutinesIntegrationTests : AbstractRequestMappingIntegrationTests() {
|
||||
fun `Handler method returning Flow throwing exception`(httpServer: HttpServer) {
|
||||
startServer(httpServer)
|
||||
|
||||
try {
|
||||
assertThatExceptionOfType(HttpServerErrorException.InternalServerError::class.java).isThrownBy {
|
||||
performGet<String>("/flow-error", HttpHeaders.EMPTY, String::class.java)
|
||||
fail("should have thrown an HttpServerErrorException.InternalServerError")
|
||||
} catch (e: HttpServerErrorException.InternalServerError) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user