23 changed files with 766 additions and 158 deletions
@ -0,0 +1,58 @@
@@ -0,0 +1,58 @@
|
||||
package org.springframework.beans.factory |
||||
|
||||
import org.junit.Test |
||||
import org.junit.runner.RunWith |
||||
import org.mockito.Answers |
||||
import org.mockito.Mock |
||||
import org.mockito.Mockito |
||||
import org.mockito.Mockito.verify |
||||
import org.mockito.junit.MockitoJUnitRunner |
||||
|
||||
/** |
||||
* Mock object based tests for BeanFactory Kotlin extensions |
||||
* |
||||
* @author Sebastien Deleuze |
||||
*/ |
||||
@RunWith(MockitoJUnitRunner::class) |
||||
class BeanFactoryExtensionsTests { |
||||
|
||||
@Mock(answer = Answers.RETURNS_MOCKS) |
||||
lateinit var bf: BeanFactory |
||||
|
||||
@Test |
||||
fun `getBean with KClass`() { |
||||
bf.getBean(Foo::class) |
||||
verify(bf, Mockito.times(1)).getBean(Foo::class.java) |
||||
} |
||||
|
||||
@Test |
||||
fun `getBean with reified type parameters`() { |
||||
bf.getBean<Foo>() |
||||
verify(bf, Mockito.times(1)).getBean(Foo::class.java) |
||||
} |
||||
|
||||
@Test |
||||
fun `getBean with String and reified type parameters`() { |
||||
val name = "foo" |
||||
bf.getBean<Foo>(name) |
||||
verify(bf, Mockito.times(1)).getBean(name, Foo::class.java) |
||||
} |
||||
|
||||
@Test |
||||
fun `getBean with KClass and varargs`() { |
||||
val arg1 = "arg1" |
||||
val arg2 = "arg2" |
||||
bf.getBean(Foo::class, arg1, arg2) |
||||
verify(bf, Mockito.times(1)).getBean(Foo::class.java, arg1, arg2) |
||||
} |
||||
|
||||
@Test |
||||
fun `getBean with reified type parameters and varargs`() { |
||||
val arg1 = "arg1" |
||||
val arg2 = "arg2" |
||||
bf.getBean<Foo>(arg1, arg2) |
||||
verify(bf, Mockito.times(1)).getBean(Foo::class.java, arg1, arg2) |
||||
} |
||||
|
||||
class Foo |
||||
} |
||||
@ -0,0 +1,134 @@
@@ -0,0 +1,134 @@
|
||||
package org.springframework.beans.factory |
||||
|
||||
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 |
||||
|
||||
/** |
||||
* Mock object based tests for ListableBeanFactory Kotlin extensions |
||||
* |
||||
* @author Sebastien Deleuze |
||||
*/ |
||||
@RunWith(MockitoJUnitRunner::class) |
||||
class ListenableBeanFactoryExtensionsTests { |
||||
|
||||
@Mock(answer = Answers.RETURNS_MOCKS) |
||||
lateinit var lbf: ListableBeanFactory |
||||
|
||||
@Test |
||||
fun `getBeanNamesForType with KClass`() { |
||||
lbf.getBeanNamesForType(Foo::class) |
||||
Mockito.verify(lbf, Mockito.times(1)).getBeanNamesForType(Foo::class.java, true , true) |
||||
} |
||||
|
||||
@Test |
||||
fun `getBeanNamesForType with KClass and Boolean`() { |
||||
lbf.getBeanNamesForType(Foo::class, false) |
||||
Mockito.verify(lbf, Mockito.times(1)).getBeanNamesForType(Foo::class.java, false , true) |
||||
} |
||||
|
||||
@Test |
||||
fun `getBeanNamesForType with KClass, Boolean and Boolean`() { |
||||
lbf.getBeanNamesForType(Foo::class, false, false) |
||||
Mockito.verify(lbf, Mockito.times(1)).getBeanNamesForType(Foo::class.java, false , false) |
||||
} |
||||
|
||||
@Test |
||||
fun `getBeanNamesForType with reified type parameters`() { |
||||
lbf.getBeanNamesForType<Foo>() |
||||
Mockito.verify(lbf, Mockito.times(1)).getBeanNamesForType(Foo::class.java, true , true) |
||||
} |
||||
|
||||
@Test |
||||
fun `getBeanNamesForType with reified type parameters and Boolean`() { |
||||
lbf.getBeanNamesForType<Foo>(false) |
||||
Mockito.verify(lbf, Mockito.times(1)).getBeanNamesForType(Foo::class.java, false , true) |
||||
} |
||||
|
||||
@Test |
||||
fun `getBeanNamesForType with reified type parameters, Boolean and Boolean`() { |
||||
lbf.getBeanNamesForType<Foo>(false, false) |
||||
Mockito.verify(lbf, Mockito.times(1)).getBeanNamesForType(Foo::class.java, false , false) |
||||
} |
||||
|
||||
@Test |
||||
fun `getBeansOfType with KClass`() { |
||||
lbf.getBeansOfType(Foo::class) |
||||
Mockito.verify(lbf, Mockito.times(1)).getBeansOfType(Foo::class.java, true , true) |
||||
} |
||||
|
||||
@Test |
||||
fun `getBeansOfType with KClass and Boolean`() { |
||||
lbf.getBeansOfType(Foo::class, false) |
||||
Mockito.verify(lbf, Mockito.times(1)).getBeansOfType(Foo::class.java, false , true) |
||||
} |
||||
|
||||
@Test |
||||
fun `getBeansOfType with KClass, Boolean and Boolean`() { |
||||
lbf.getBeansOfType(Foo::class, false, false) |
||||
Mockito.verify(lbf, Mockito.times(1)).getBeansOfType(Foo::class.java, false , false) |
||||
} |
||||
|
||||
@Test |
||||
fun `getBeansOfType with reified type parameters`() { |
||||
lbf.getBeansOfType<Foo>() |
||||
Mockito.verify(lbf, Mockito.times(1)).getBeansOfType(Foo::class.java, true , true) |
||||
} |
||||
|
||||
@Test |
||||
fun `getBeansOfType with reified type parameters and Boolean`() { |
||||
lbf.getBeansOfType<Foo>(false) |
||||
Mockito.verify(lbf, Mockito.times(1)).getBeansOfType(Foo::class.java, false , true) |
||||
} |
||||
|
||||
@Test |
||||
fun `getBeansOfType with reified type parameters, Boolean and Boolean`() { |
||||
lbf.getBeansOfType<Foo>(false, false) |
||||
Mockito.verify(lbf, Mockito.times(1)).getBeansOfType(Foo::class.java, false , false) |
||||
} |
||||
|
||||
@Test |
||||
fun `getBeanNamesForAnnotation with KClass`() { |
||||
lbf.getBeanNamesForAnnotation(Bar::class) |
||||
Mockito.verify(lbf, Mockito.times(1)).getBeanNamesForAnnotation(Bar::class.java) |
||||
} |
||||
|
||||
@Test |
||||
fun `getBeanNamesForAnnotation with reified type parameters`() { |
||||
lbf.getBeanNamesForAnnotation<Bar>() |
||||
Mockito.verify(lbf, Mockito.times(1)).getBeanNamesForAnnotation(Bar::class.java) |
||||
} |
||||
|
||||
@Test |
||||
fun `getBeansWithAnnotation with KClass`() { |
||||
lbf.getBeansWithAnnotation(Bar::class) |
||||
Mockito.verify(lbf, Mockito.times(1)).getBeansWithAnnotation(Bar::class.java) |
||||
} |
||||
|
||||
@Test |
||||
fun `getBeansWithAnnotation with reified type parameters`() { |
||||
lbf.getBeansWithAnnotation<Bar>() |
||||
Mockito.verify(lbf, Mockito.times(1)).getBeansWithAnnotation(Bar::class.java) |
||||
} |
||||
|
||||
@Test |
||||
fun `findAnnotationOnBean with String and KClass`() { |
||||
val name = "bar" |
||||
lbf.findAnnotationOnBean(name, Bar::class) |
||||
Mockito.verify(lbf, Mockito.times(1)).findAnnotationOnBean(name, Bar::class.java) |
||||
} |
||||
|
||||
@Test |
||||
fun `findAnnotationOnBean with String and reified type parameters`() { |
||||
val name = "bar" |
||||
lbf.findAnnotationOnBean<Bar>(name) |
||||
Mockito.verify(lbf, Mockito.times(1)).findAnnotationOnBean(name, Bar::class.java) |
||||
} |
||||
|
||||
class Foo |
||||
|
||||
annotation class Bar |
||||
} |
||||
@ -0,0 +1,26 @@
@@ -0,0 +1,26 @@
|
||||
package org.springframework.context.annotation |
||||
|
||||
import org.junit.Assert.assertNotNull |
||||
import org.junit.Test |
||||
import org.springframework.beans.factory.getBean |
||||
import org.springframework.context.support.registerBean |
||||
|
||||
/** |
||||
* Tests for [AnnotationConfigApplicationContext] Kotlin extensions |
||||
* |
||||
* @author Sebastien Deleuze |
||||
*/ |
||||
class AnnotationConfigApplicationContextExtensionsTests { |
||||
|
||||
@Test |
||||
fun `Instantiate AnnotationConfigApplicationContext`() { |
||||
val applicationContext = AnnotationConfigApplicationContext { |
||||
registerBean<Foo>() |
||||
} |
||||
applicationContext.refresh() |
||||
assertNotNull(applicationContext) |
||||
assertNotNull(applicationContext.getBean<Foo>()) |
||||
} |
||||
|
||||
class Foo |
||||
} |
||||
@ -0,0 +1,154 @@
@@ -0,0 +1,154 @@
|
||||
package org.springframework.web.client |
||||
|
||||
import com.nhaarman.mockito_kotlin.mock |
||||
import org.junit.Test |
||||
import org.junit.runner.RunWith |
||||
import org.mockito.Answers |
||||
import org.mockito.Mock |
||||
import org.mockito.Mockito |
||||
import org.mockito.Mockito.verify |
||||
import org.mockito.junit.MockitoJUnitRunner |
||||
import org.springframework.http.HttpEntity |
||||
import org.springframework.http.HttpMethod |
||||
import org.springframework.http.RequestEntity |
||||
import java.net.URI |
||||
|
||||
/** |
||||
* Mock object based tests for [RestOperations] Kotlin extensions |
||||
* |
||||
* @author Sebastien Deleuze |
||||
*/ |
||||
@RunWith(MockitoJUnitRunner::class) |
||||
class RestOperationsExtensionsTests { |
||||
|
||||
@Mock(answer = Answers.RETURNS_MOCKS) |
||||
lateinit var template: RestOperations |
||||
|
||||
@Test |
||||
fun `getForObject with reified type parameters, String and varargs`() { |
||||
val url = "https://spring.io" |
||||
val var1 = "var1" |
||||
val var2 = "var2" |
||||
template.getForObject<Foo>(url, var1, var2) |
||||
verify(template, Mockito.times(1)).getForObject(url, Foo::class.java, var1, var2) |
||||
} |
||||
|
||||
@Test |
||||
fun `getForObject with reified type parameters, String and Map`() { |
||||
val url = "https://spring.io" |
||||
val vars = mapOf(Pair("key1", "value1"), Pair("key2", "value2")) |
||||
template.getForObject<Foo>(url, vars) |
||||
verify(template, Mockito.times(1)).getForObject(url, Foo::class.java, vars) |
||||
} |
||||
|
||||
@Test |
||||
fun `getForObject with reified type parameters and URI`() { |
||||
val url = URI("https://spring.io") |
||||
template.getForObject<Foo>(url) |
||||
verify(template, Mockito.times(1)).getForObject(url, Foo::class.java) |
||||
} |
||||
|
||||
@Test |
||||
fun `getForEntity with reified type parameters, String and varargs`() { |
||||
val url = "https://spring.io" |
||||
val var1 = "var1" |
||||
val var2 = "var2" |
||||
template.getForEntity<Foo>(url, var1, var2) |
||||
verify(template, Mockito.times(1)).getForEntity(url, Foo::class.java, var1, var2) |
||||
} |
||||
|
||||
@Test |
||||
fun `postForObject with reified type parameters, String and varargs`() { |
||||
val url = "https://spring.io" |
||||
val body: Any = "body" |
||||
val var1 = "var1" |
||||
val var2 = "var2" |
||||
template.postForObject<Foo>(url, body, var1, var2) |
||||
verify(template, Mockito.times(1)).postForObject(url, body, Foo::class.java, var1, var2) |
||||
} |
||||
|
||||
@Test |
||||
fun `postForObject with reified type parameters, String and Map`() { |
||||
val url = "https://spring.io" |
||||
val body: Any = "body" |
||||
val vars = mapOf(Pair("key1", "value1"), Pair("key2", "value2")) |
||||
template.postForObject<Foo>(url, body, vars) |
||||
verify(template, Mockito.times(1)).postForObject(url, body, Foo::class.java, vars) |
||||
} |
||||
|
||||
@Test |
||||
fun `postForObject with reified type parameters`() { |
||||
val url = "https://spring.io" |
||||
val body: Any = "body" |
||||
template.postForObject<Foo>(url, body) |
||||
verify(template, Mockito.times(1)).postForObject(url, body, Foo::class.java) |
||||
} |
||||
|
||||
@Test |
||||
fun `postForEntity with reified type parameters, String and varargs`() { |
||||
val url = "https://spring.io" |
||||
val body: Any = "body" |
||||
val var1 = "var1" |
||||
val var2 = "var2" |
||||
template.postForEntity<Foo>(url, body, var1, var2) |
||||
verify(template, Mockito.times(1)).postForEntity(url, body, Foo::class.java, var1, var2) |
||||
} |
||||
|
||||
@Test |
||||
fun `postForEntity with reified type parameters, String and Map`() { |
||||
val url = "https://spring.io" |
||||
val body: Any = "body" |
||||
val vars = mapOf(Pair("key1", "value1"), Pair("key2", "value2")) |
||||
template.postForEntity<Foo>(url, body, vars) |
||||
verify(template, Mockito.times(1)).postForEntity(url, body, Foo::class.java, vars) |
||||
} |
||||
|
||||
@Test |
||||
fun `postForEntity with reified type parameters`() { |
||||
val url = "https://spring.io" |
||||
val body: Any = "body" |
||||
template.postForEntity<Foo>(url, body) |
||||
verify(template, Mockito.times(1)).postForEntity(url, body, Foo::class.java) |
||||
} |
||||
|
||||
@Test |
||||
fun `exchange with reified type parameters, String, HttpMethod, HttpEntity and varargs`() { |
||||
val url = "https://spring.io" |
||||
val method = HttpMethod.GET |
||||
val entity = mock<HttpEntity<Foo>>() |
||||
val var1 = "var1" |
||||
val var2 = "var2" |
||||
template.exchange<Foo>(url, method, entity, var1, var2) |
||||
verify(template, Mockito.times(1)).exchange(url, method, entity, Foo::class.java, var1, var2) |
||||
} |
||||
|
||||
@Test |
||||
fun `exchange with reified type parameters, String, HttpMethod, HttpEntity and Map`() { |
||||
val url = "https://spring.io" |
||||
val method = HttpMethod.GET |
||||
val entity = mock<HttpEntity<Foo>>() |
||||
val vars = mapOf(Pair("key1", "value1"), Pair("key2", "value2")) |
||||
template.exchange<Foo>(url, method, entity, vars) |
||||
verify(template, Mockito.times(1)).exchange(url, method, entity, Foo::class.java, vars) |
||||
} |
||||
|
||||
@Test |
||||
fun `exchange with reified type parameters, String, HttpMethod, HttpEntity`() { |
||||
val url = "https://spring.io" |
||||
val method = HttpMethod.GET |
||||
val entity = mock<HttpEntity<Foo>>() |
||||
template.exchange<Foo>(url, method, entity) |
||||
verify(template, Mockito.times(1)).exchange(url, method, entity, Foo::class.java) |
||||
} |
||||
|
||||
@Test |
||||
fun `exchange with reified type parameters, String, HttpEntity`() { |
||||
val url = "https://spring.io" |
||||
val entity = mock<RequestEntity<Foo>>() |
||||
template.exchange<Foo>(entity) |
||||
verify(template, Mockito.times(1)).exchange(entity, Foo::class.java) |
||||
} |
||||
|
||||
class Foo |
||||
|
||||
} |
||||
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
package org.springframework.web.reactive.function |
||||
|
||||
import org.junit.Assert.assertNotNull |
||||
import org.junit.Test |
||||
import org.junit.runner.RunWith |
||||
import org.mockito.junit.MockitoJUnitRunner |
||||
|
||||
|
||||
/** |
||||
* Tests for [BodyExtractors] Kotlin extensions |
||||
* |
||||
* @author Sebastien Deleuze |
||||
*/ |
||||
@RunWith(MockitoJUnitRunner::class) |
||||
class BodyExtractorsExtensionsTests { |
||||
|
||||
@Test |
||||
fun `toMono with KClass`() { |
||||
assertNotNull(toMono(Foo::class)) |
||||
} |
||||
|
||||
@Test |
||||
fun `toMono with reified type parameter`() { |
||||
assertNotNull(toMono<Foo>()) |
||||
} |
||||
|
||||
@Test |
||||
fun `toFlux with KClass`() { |
||||
assertNotNull(toFlux(Foo::class)) |
||||
} |
||||
|
||||
@Test |
||||
fun `toFlux with reified type parameter`() { |
||||
assertNotNull(toFlux<Foo>()) |
||||
} |
||||
|
||||
class Foo |
||||
} |
||||
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
package org.springframework.web.reactive.function |
||||
|
||||
import com.nhaarman.mockito_kotlin.mock |
||||
import org.junit.Assert.assertNotNull |
||||
import org.junit.Test |
||||
import org.junit.runner.RunWith |
||||
import org.mockito.junit.MockitoJUnitRunner |
||||
import org.reactivestreams.Publisher |
||||
|
||||
|
||||
/** |
||||
* Tests for [BodyExtractors] Kotlin extensions |
||||
* |
||||
* @author Sebastien Deleuze |
||||
*/ |
||||
@RunWith(MockitoJUnitRunner::class) |
||||
class BodyInsertersExtensionsTests { |
||||
|
||||
@Test |
||||
fun `fromPublisher with reified type parameters`() { |
||||
val publisher = mock<Publisher<Foo>>() |
||||
assertNotNull(fromPublisher(publisher)) |
||||
} |
||||
|
||||
@Test |
||||
fun `fromServerSentEvents with reified type parameters`() { |
||||
val publisher = mock<Publisher<Foo>>() |
||||
assertNotNull(fromServerSentEvents(publisher)) |
||||
} |
||||
|
||||
class Foo |
||||
} |
||||
@ -0,0 +1,47 @@
@@ -0,0 +1,47 @@
|
||||
package org.springframework.web.reactive.function.client |
||||
|
||||
import org.junit.Test |
||||
import org.junit.runner.RunWith |
||||
import org.mockito.Answers |
||||
import org.mockito.Mock |
||||
import org.mockito.Mockito |
||||
import org.mockito.Mockito.verify |
||||
import org.mockito.junit.MockitoJUnitRunner |
||||
|
||||
/** |
||||
* Mock object based tests for [ClientResponse] Kotlin extensions |
||||
* |
||||
* @author Sebastien Deleuze |
||||
*/ |
||||
@RunWith(MockitoJUnitRunner::class) |
||||
class ClientResponseExtensionsTests { |
||||
|
||||
@Mock(answer = Answers.RETURNS_MOCKS) |
||||
lateinit var response: ClientResponse |
||||
|
||||
@Test |
||||
fun `bodyToMono with KClass`() { |
||||
response.bodyToMono(Foo::class) |
||||
verify(response, Mockito.times(1)).bodyToMono(Foo::class.java) |
||||
} |
||||
|
||||
@Test |
||||
fun `bodyToMono with reified type parameters`() { |
||||
response.bodyToMono<Foo>() |
||||
verify(response, Mockito.times(1)).bodyToMono(Foo::class.java) |
||||
} |
||||
|
||||
@Test |
||||
fun `bodyToFlux with KClass`() { |
||||
response.bodyToFlux(Foo::class) |
||||
verify(response, Mockito.times(1)).bodyToFlux(Foo::class.java) |
||||
} |
||||
|
||||
@Test |
||||
fun `bodyToFlux with reified type parameters`() { |
||||
response.bodyToFlux<Foo>() |
||||
verify(response, Mockito.times(1)).bodyToFlux(Foo::class.java) |
||||
} |
||||
|
||||
class Foo |
||||
} |
||||
@ -0,0 +1,84 @@
@@ -0,0 +1,84 @@
|
||||
package org.springframework.web.reactive.function.client |
||||
|
||||
import com.nhaarman.mockito_kotlin.mock |
||||
import org.junit.Test |
||||
import org.junit.runner.RunWith |
||||
import org.mockito.Answers |
||||
import org.mockito.Mock |
||||
import org.mockito.Mockito |
||||
import org.mockito.Mockito.verify |
||||
import org.mockito.junit.MockitoJUnitRunner |
||||
import org.reactivestreams.Publisher |
||||
|
||||
/** |
||||
* Mock object based tests for [WebClient] Kotlin extensions |
||||
* |
||||
* @author Sebastien Deleuze |
||||
*/ |
||||
@RunWith(MockitoJUnitRunner::class) |
||||
class WebClientExtensionsTests { |
||||
|
||||
@Mock(answer = Answers.RETURNS_MOCKS) |
||||
lateinit var requestBodySpec: WebClient.RequestBodySpec |
||||
|
||||
@Mock(answer = Answers.RETURNS_MOCKS) |
||||
lateinit var responseSpec: WebClient.ResponseSpec |
||||
|
||||
|
||||
@Test |
||||
fun `RequestBodySpec#body with Publisher and reified type parameters`() { |
||||
val body = mock<Publisher<Foo>>() |
||||
requestBodySpec.body(body) |
||||
verify(requestBodySpec, Mockito.times(1)).body(body, Foo::class.java) |
||||
} |
||||
|
||||
@Test |
||||
fun `ResponseSpec#bodyToMono with KClass`() { |
||||
responseSpec.bodyToMono(Foo::class) |
||||
verify(responseSpec, Mockito.times(1)).bodyToMono(Foo::class.java) |
||||
} |
||||
|
||||
@Test |
||||
fun `ResponseSpec#bodyToMono with reified type parameters`() { |
||||
responseSpec.bodyToMono<Foo>() |
||||
verify(responseSpec, Mockito.times(1)).bodyToMono(Foo::class.java) |
||||
} |
||||
|
||||
@Test |
||||
fun `ResponseSpec#bodyToFlux with KClass`() { |
||||
responseSpec.bodyToFlux(Foo::class) |
||||
verify(responseSpec, Mockito.times(1)).bodyToFlux(Foo::class.java) |
||||
} |
||||
|
||||
@Test |
||||
fun `ResponseSpec#bodyToFlux with reified type parameters`() { |
||||
responseSpec.bodyToFlux<Foo>() |
||||
verify(responseSpec, Mockito.times(1)).bodyToFlux(Foo::class.java) |
||||
} |
||||
|
||||
@Test |
||||
fun `ResponseSpec#toEntity with KClass`() { |
||||
responseSpec.toEntity(Foo::class) |
||||
verify(responseSpec, Mockito.times(1)).toEntity(Foo::class.java) |
||||
} |
||||
|
||||
@Test |
||||
fun `ResponseSpec#toEntity with reified type parameters`() { |
||||
responseSpec.toEntity<Foo>() |
||||
verify(responseSpec, Mockito.times(1)).toEntity(Foo::class.java) |
||||
} |
||||
|
||||
@Test |
||||
fun `ResponseSpec#toEntityList with KClass`() { |
||||
responseSpec.toEntityList(Foo::class) |
||||
verify(responseSpec, Mockito.times(1)).toEntityList(Foo::class.java) |
||||
} |
||||
|
||||
@Test |
||||
fun `ResponseSpec#toEntityList with reified type parameters`() { |
||||
responseSpec.toEntityList<Foo>() |
||||
verify(responseSpec, Mockito.times(1)).toEntityList(Foo::class.java) |
||||
} |
||||
|
||||
class Foo |
||||
} |
||||
@ -0,0 +1,50 @@
@@ -0,0 +1,50 @@
|
||||
package org.springframework.web.reactive.function.client |
||||
|
||||
import org.junit.Test |
||||
import org.junit.runner.RunWith |
||||
import org.mockito.Answers |
||||
import org.mockito.Mock |
||||
import org.mockito.Mockito |
||||
import org.mockito.Mockito.verify |
||||
import org.mockito.junit.MockitoJUnitRunner |
||||
import org.springframework.web.reactive.function.server.ServerRequest |
||||
import org.springframework.web.reactive.function.server.bodyToFlux |
||||
import org.springframework.web.reactive.function.server.bodyToMono |
||||
|
||||
/** |
||||
* Mock object based tests for [ServerRequest] Kotlin extensions |
||||
* |
||||
* @author Sebastien Deleuze |
||||
*/ |
||||
@RunWith(MockitoJUnitRunner::class) |
||||
class ServerRequestExtensionsTests { |
||||
|
||||
@Mock(answer = Answers.RETURNS_MOCKS) |
||||
lateinit var request: ServerRequest |
||||
|
||||
@Test |
||||
fun `bodyToMono with KClass`() { |
||||
request.bodyToMono(Foo::class) |
||||
verify(request, Mockito.times(1)).bodyToMono(Foo::class.java) |
||||
} |
||||
|
||||
@Test |
||||
fun `bodyToMono with reified type parameters`() { |
||||
request.bodyToMono<Foo>() |
||||
verify(request, Mockito.times(1)).bodyToMono(Foo::class.java) |
||||
} |
||||
|
||||
@Test |
||||
fun `bodyToFlux with KClass`() { |
||||
request.bodyToFlux(Foo::class) |
||||
verify(request, Mockito.times(1)).bodyToFlux(Foo::class.java) |
||||
} |
||||
|
||||
@Test |
||||
fun `bodyToFlux with reified type parameters`() { |
||||
request.bodyToFlux<Foo>() |
||||
verify(request, Mockito.times(1)).bodyToFlux(Foo::class.java) |
||||
} |
||||
|
||||
class Foo |
||||
} |
||||
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
package org.springframework.web.reactive.function.server |
||||
|
||||
import com.nhaarman.mockito_kotlin.mock |
||||
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 |
||||
|
||||
/** |
||||
* Mock object based tests for [ServerResponse] Kotlin extensions |
||||
* |
||||
* @author Sebastien Deleuze |
||||
*/ |
||||
@RunWith(MockitoJUnitRunner::class) |
||||
class ServerResponseExtensionsTests { |
||||
|
||||
@Mock(answer = Answers.RETURNS_MOCKS) |
||||
lateinit var bodyBuilder: ServerResponse.BodyBuilder |
||||
|
||||
|
||||
@Test |
||||
fun `BodyBuilder#body with Publisher and reified type parameters`() { |
||||
val body = mock<Publisher<Foo>>() |
||||
bodyBuilder.body(body) |
||||
Mockito.verify(bodyBuilder, Mockito.times(1)).body(body, Foo::class.java) |
||||
} |
||||
|
||||
class Foo |
||||
} |
||||
Loading…
Reference in new issue