Migrate Kotlin Mockito tests to Mockk
Closes gh-22345
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,13 +16,9 @@
|
||||
|
||||
package org.springframework.web.reactive.function.client
|
||||
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Answers
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.times
|
||||
import org.mockito.Mockito.verify
|
||||
import org.mockito.junit.MockitoJUnitRunner
|
||||
import org.springframework.core.ParameterizedTypeReference
|
||||
|
||||
/**
|
||||
@@ -30,34 +26,32 @@ import org.springframework.core.ParameterizedTypeReference
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner::class)
|
||||
class ClientResponseExtensionsTests {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_MOCKS)
|
||||
lateinit var response: ClientResponse
|
||||
val response = mockk<ClientResponse>(relaxed = true)
|
||||
|
||||
@Test
|
||||
fun `bodyToMono with reified type parameters`() {
|
||||
response.bodyToMono<List<Foo>>()
|
||||
verify(response, times(1)).bodyToMono(object : ParameterizedTypeReference<List<Foo>>() {})
|
||||
verify { response.bodyToMono(object : ParameterizedTypeReference<List<Foo>>() {}) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `bodyToFlux with reified type parameters`() {
|
||||
response.bodyToFlux<List<Foo>>()
|
||||
verify(response, times(1)).bodyToFlux(object : ParameterizedTypeReference<List<Foo>>() {})
|
||||
verify { response.bodyToFlux(object : ParameterizedTypeReference<List<Foo>>() {}) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `toEntity with reified type parameters`() {
|
||||
response.toEntity<List<Foo>>()
|
||||
verify(response, times(1)).toEntity(object : ParameterizedTypeReference<List<Foo>>() {})
|
||||
verify { response.toEntity(object : ParameterizedTypeReference<List<Foo>>() {}) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ResponseSpec#toEntityList with reified type parameters`() {
|
||||
response.toEntityList<List<Foo>>()
|
||||
verify(response, times(1)).toEntityList(object : ParameterizedTypeReference<List<Foo>>() {})
|
||||
verify { response.toEntityList(object : ParameterizedTypeReference<List<Foo>>() {}) }
|
||||
}
|
||||
|
||||
class Foo
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,14 +16,9 @@
|
||||
|
||||
package org.springframework.web.reactive.function.client
|
||||
|
||||
import com.nhaarman.mockito_kotlin.mock
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Answers
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.times
|
||||
import org.mockito.Mockito.verify
|
||||
import org.mockito.junit.MockitoJUnitRunner
|
||||
import org.reactivestreams.Publisher
|
||||
import org.springframework.core.ParameterizedTypeReference
|
||||
|
||||
@@ -32,33 +27,30 @@ import org.springframework.core.ParameterizedTypeReference
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner::class)
|
||||
class WebClientExtensionsTests {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_MOCKS)
|
||||
lateinit var requestBodySpec: WebClient.RequestBodySpec
|
||||
val requestBodySpec = mockk<WebClient.RequestBodySpec>(relaxed = true)
|
||||
|
||||
@Mock(answer = Answers.RETURNS_MOCKS)
|
||||
lateinit var responseSpec: WebClient.ResponseSpec
|
||||
val responseSpec = mockk<WebClient.ResponseSpec>(relaxed = true)
|
||||
|
||||
|
||||
@Test
|
||||
fun `RequestBodySpec#body with Publisher and reified type parameters`() {
|
||||
val body = mock<Publisher<List<Foo>>>()
|
||||
val body = mockk<Publisher<List<Foo>>>()
|
||||
requestBodySpec.body(body)
|
||||
verify(requestBodySpec, times(1)).body(body, object : ParameterizedTypeReference<List<Foo>>() {})
|
||||
verify { requestBodySpec.body(body, object : ParameterizedTypeReference<List<Foo>>() {}) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ResponseSpec#bodyToMono with reified type parameters`() {
|
||||
responseSpec.bodyToMono<List<Foo>>()
|
||||
verify(responseSpec, times(1)).bodyToMono(object : ParameterizedTypeReference<List<Foo>>() {})
|
||||
verify { responseSpec.bodyToMono(object : ParameterizedTypeReference<List<Foo>>() {}) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ResponseSpec#bodyToFlux with reified type parameters`() {
|
||||
responseSpec.bodyToFlux<List<Foo>>()
|
||||
verify(responseSpec, times(1)).bodyToFlux(object : ParameterizedTypeReference<List<Foo>>() {})
|
||||
verify { responseSpec.bodyToFlux(object : ParameterizedTypeReference<List<Foo>>() {}) }
|
||||
}
|
||||
|
||||
class Foo
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,12 +16,9 @@
|
||||
|
||||
package org.springframework.web.reactive.function.client
|
||||
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Answers
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.*
|
||||
import org.mockito.junit.MockitoJUnitRunner
|
||||
import org.springframework.core.ParameterizedTypeReference
|
||||
import org.springframework.web.reactive.function.server.ServerRequest
|
||||
import org.springframework.web.reactive.function.server.bodyToFlux
|
||||
@@ -32,22 +29,20 @@ import org.springframework.web.reactive.function.server.bodyToMono
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner::class)
|
||||
class ServerRequestExtensionsTests {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_MOCKS)
|
||||
lateinit var request: ServerRequest
|
||||
val request = mockk<ServerRequest>(relaxed = true)
|
||||
|
||||
@Test
|
||||
fun `bodyToMono with reified type parameters`() {
|
||||
request.bodyToMono<List<Foo>>()
|
||||
verify(request, times(1)).bodyToMono(object : ParameterizedTypeReference<List<Foo>>() {})
|
||||
verify { request.bodyToMono(object : ParameterizedTypeReference<List<Foo>>() {}) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `bodyToFlux with reified type parameters`() {
|
||||
request.bodyToFlux<List<Foo>>()
|
||||
verify(request, times(1)).bodyToFlux(object : ParameterizedTypeReference<List<Foo>>() {})
|
||||
verify { request.bodyToFlux(object : ParameterizedTypeReference<List<Foo>>() {}) }
|
||||
}
|
||||
|
||||
class Foo
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,13 +16,9 @@
|
||||
|
||||
package org.springframework.web.reactive.function.server
|
||||
|
||||
import com.nhaarman.mockito_kotlin.mock
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Answers
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.*
|
||||
import org.mockito.junit.MockitoJUnitRunner
|
||||
import org.reactivestreams.Publisher
|
||||
import org.springframework.core.ParameterizedTypeReference
|
||||
import org.springframework.http.MediaType.*
|
||||
@@ -32,43 +28,41 @@ import org.springframework.http.MediaType.*
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner::class)
|
||||
class ServerResponseExtensionsTests {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_MOCKS)
|
||||
lateinit var bodyBuilder: ServerResponse.BodyBuilder
|
||||
val bodyBuilder = mockk<ServerResponse.BodyBuilder>(relaxed = true)
|
||||
|
||||
|
||||
@Test
|
||||
fun `BodyBuilder#body with Publisher and reified type parameters`() {
|
||||
val body = mock<Publisher<List<Foo>>>()
|
||||
val body = mockk<Publisher<List<Foo>>>()
|
||||
bodyBuilder.body(body)
|
||||
verify(bodyBuilder, times(1)).body(body, object : ParameterizedTypeReference<List<Foo>>() {})
|
||||
verify { bodyBuilder.body(body, object : ParameterizedTypeReference<List<Foo>>() {}) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `BodyBuilder#bodyToServerSentEvents with Publisher and reified type parameters`() {
|
||||
val body = mock<Publisher<List<Foo>>>()
|
||||
val body = mockk<Publisher<List<Foo>>>()
|
||||
bodyBuilder.bodyToServerSentEvents(body)
|
||||
verify(bodyBuilder, times(1)).contentType(TEXT_EVENT_STREAM)
|
||||
verify { bodyBuilder.contentType(TEXT_EVENT_STREAM) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `BodyBuilder#json`() {
|
||||
bodyBuilder.json()
|
||||
verify(bodyBuilder, times(1)).contentType(APPLICATION_JSON_UTF8)
|
||||
verify { bodyBuilder.contentType(APPLICATION_JSON_UTF8) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `BodyBuilder#xml`() {
|
||||
bodyBuilder.xml()
|
||||
verify(bodyBuilder, times(1)).contentType(APPLICATION_XML)
|
||||
verify { bodyBuilder.contentType(APPLICATION_XML) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `BodyBuilder#html`() {
|
||||
bodyBuilder.html()
|
||||
verify(bodyBuilder, times(1)).contentType(TEXT_HTML)
|
||||
verify { bodyBuilder.contentType(TEXT_HTML) }
|
||||
}
|
||||
|
||||
class Foo
|
||||
|
||||
Reference in New Issue
Block a user