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,14 +16,10 @@
|
||||
|
||||
package org.springframework.web.client
|
||||
|
||||
import com.nhaarman.mockito_kotlin.mock
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import org.junit.Assert
|
||||
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.http.HttpEntity
|
||||
import org.springframework.http.HttpMethod
|
||||
@@ -38,11 +34,9 @@ import kotlin.reflect.jvm.kotlinFunction
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner::class)
|
||||
class RestOperationsExtensionsTests {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_MOCKS)
|
||||
lateinit var template: RestOperations
|
||||
val template = mockk<RestOperations>(relaxed = true)
|
||||
|
||||
@Test
|
||||
fun `getForObject with reified type parameters, String and varargs`() {
|
||||
@@ -50,7 +44,7 @@ class RestOperationsExtensionsTests {
|
||||
val var1 = "var1"
|
||||
val var2 = "var2"
|
||||
template.getForObject<Foo>(url, var1, var2)
|
||||
verify(template, times(1)).getForObject(url, Foo::class.java, var1, var2)
|
||||
verify { template.getForObject(url, Foo::class.java, var1, var2) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -58,21 +52,21 @@ class RestOperationsExtensionsTests {
|
||||
val url = "https://spring.io"
|
||||
val vars = mapOf(Pair("key1", "value1"), Pair("key2", "value2"))
|
||||
template.getForObject<Foo>(url, vars)
|
||||
verify(template, times(1)).getForObject(url, Foo::class.java, vars)
|
||||
verify { template.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, times(1)).getForObject(url, Foo::class.java)
|
||||
verify { template.getForObject(url, Foo::class.java) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getForEntity with reified type parameters, String and URI`() {
|
||||
val url = URI("https://spring.io")
|
||||
template.getForEntity<Foo>(url)
|
||||
verify(template, times(1)).getForEntity(url, Foo::class.java)
|
||||
verify { template.getForEntity(url, Foo::class.java) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -81,7 +75,7 @@ class RestOperationsExtensionsTests {
|
||||
val var1 = "var1"
|
||||
val var2 = "var2"
|
||||
template.getForEntity<Foo>(url, var1, var2)
|
||||
verify(template, times(1)).getForEntity(url, Foo::class.java, var1, var2)
|
||||
verify { template.getForEntity(url, Foo::class.java, var1, var2) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,7 +83,7 @@ class RestOperationsExtensionsTests {
|
||||
val url = "https://spring.io"
|
||||
val vars = mapOf(Pair("key1", "value1"), Pair("key2", "value2"))
|
||||
template.getForEntity<Foo>(url, vars)
|
||||
verify(template, times(1)).getForEntity(url, Foo::class.java, vars)
|
||||
verify { template.getForEntity(url, Foo::class.java, vars) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -99,7 +93,7 @@ class RestOperationsExtensionsTests {
|
||||
val var1 = "var1"
|
||||
val var2 = "var2"
|
||||
template.patchForObject<Foo>(url, body, var1, var2)
|
||||
verify(template, times(1)).patchForObject(url, body, Foo::class.java, var1, var2)
|
||||
verify { template.patchForObject(url, body, Foo::class.java, var1, var2) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -108,7 +102,7 @@ class RestOperationsExtensionsTests {
|
||||
val body: Any = "body"
|
||||
val vars = mapOf(Pair("key1", "value1"), Pair("key2", "value2"))
|
||||
template.patchForObject<Foo>(url, body, vars)
|
||||
verify(template, times(1)).patchForObject(url, body, Foo::class.java, vars)
|
||||
verify { template.patchForObject(url, body, Foo::class.java, vars) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -116,14 +110,14 @@ class RestOperationsExtensionsTests {
|
||||
val url = "https://spring.io"
|
||||
val body: Any = "body"
|
||||
template.patchForObject<Foo>(url, body)
|
||||
verify(template, times(1)).patchForObject(url, body, Foo::class.java)
|
||||
verify { template.patchForObject(url, body, Foo::class.java) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `patchForObject with reified type parameters`() {
|
||||
val url = "https://spring.io"
|
||||
template.patchForObject<Foo>(url)
|
||||
verify(template, times(1)).patchForObject(url, null, Foo::class.java)
|
||||
verify { template.patchForObject(url, null, Foo::class.java) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -133,7 +127,7 @@ class RestOperationsExtensionsTests {
|
||||
val var1 = "var1"
|
||||
val var2 = "var2"
|
||||
template.postForObject<Foo>(url, body, var1, var2)
|
||||
verify(template, times(1)).postForObject(url, body, Foo::class.java, var1, var2)
|
||||
verify { template.postForObject(url, body, Foo::class.java, var1, var2) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -142,7 +136,7 @@ class RestOperationsExtensionsTests {
|
||||
val body: Any = "body"
|
||||
val vars = mapOf(Pair("key1", "value1"), Pair("key2", "value2"))
|
||||
template.postForObject<Foo>(url, body, vars)
|
||||
verify(template, times(1)).postForObject(url, body, Foo::class.java, vars)
|
||||
verify { template.postForObject(url, body, Foo::class.java, vars) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -150,14 +144,14 @@ class RestOperationsExtensionsTests {
|
||||
val url = "https://spring.io"
|
||||
val body: Any = "body"
|
||||
template.postForObject<Foo>(url, body)
|
||||
verify(template, times(1)).postForObject(url, body, Foo::class.java)
|
||||
verify { template.postForObject(url, body, Foo::class.java) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `postForObject with reified type parameters`() {
|
||||
val url = "https://spring.io"
|
||||
template.postForObject<Foo>(url)
|
||||
verify(template, times(1)).postForObject(url, null, Foo::class.java)
|
||||
verify { template.postForObject(url, null, Foo::class.java) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -167,7 +161,7 @@ class RestOperationsExtensionsTests {
|
||||
val var1 = "var1"
|
||||
val var2 = "var2"
|
||||
template.postForEntity<Foo>(url, body, var1, var2)
|
||||
verify(template, times(1)).postForEntity(url, body, Foo::class.java, var1, var2)
|
||||
verify { template.postForEntity(url, body, Foo::class.java, var1, var2) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -176,7 +170,7 @@ class RestOperationsExtensionsTests {
|
||||
val body: Any = "body"
|
||||
val vars = mapOf(Pair("key1", "value1"), Pair("key2", "value2"))
|
||||
template.postForEntity<Foo>(url, body, vars)
|
||||
verify(template, times(1)).postForEntity(url, body, Foo::class.java, vars)
|
||||
verify { template.postForEntity(url, body, Foo::class.java, vars) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -184,47 +178,47 @@ class RestOperationsExtensionsTests {
|
||||
val url = "https://spring.io"
|
||||
val body: Any = "body"
|
||||
template.postForEntity<Foo>(url, body)
|
||||
verify(template, times(1)).postForEntity(url, body, Foo::class.java)
|
||||
verify { template.postForEntity(url, body, Foo::class.java) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `postForEntity with reified type parameters`() {
|
||||
val url = "https://spring.io"
|
||||
template.postForEntity<Foo>(url)
|
||||
verify(template, times(1)).postForEntity(url, null, Foo::class.java)
|
||||
verify { template.postForEntity(url, null, 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 entity = mockk<HttpEntity<Foo>>()
|
||||
val var1 = "var1"
|
||||
val var2 = "var2"
|
||||
template.exchange<List<Foo>>(url, method, entity, var1, var2)
|
||||
verify(template, times(1)).exchange(url, method, entity,
|
||||
object : ParameterizedTypeReference<List<Foo>>() {}, var1, var2)
|
||||
verify { template.exchange(url, method, entity,
|
||||
object : ParameterizedTypeReference<List<Foo>>() {}, 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 entity = mockk<HttpEntity<Foo>>()
|
||||
val vars = mapOf(Pair("key1", "value1"), Pair("key2", "value2"))
|
||||
template.exchange<List<Foo>>(url, method, entity, vars)
|
||||
verify(template, times(1)).exchange(url, method, entity,
|
||||
object : ParameterizedTypeReference<List<Foo>>() {}, vars)
|
||||
verify { template.exchange(url, method, entity,
|
||||
object : ParameterizedTypeReference<List<Foo>>() {}, vars) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `exchange with reified type parameters, String, HttpMethod and HttpEntity`() {
|
||||
val url = "https://spring.io"
|
||||
val method = HttpMethod.GET
|
||||
val entity = mock<HttpEntity<Foo>>()
|
||||
val entity = mockk<HttpEntity<Foo>>()
|
||||
template.exchange<List<Foo>>(url, method, entity)
|
||||
verify(template, times(1)).exchange(url, method, entity,
|
||||
object : ParameterizedTypeReference<List<Foo>>() {})
|
||||
verify { template.exchange(url, method, entity,
|
||||
object : ParameterizedTypeReference<List<Foo>>() {}) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -232,16 +226,16 @@ class RestOperationsExtensionsTests {
|
||||
val url = "https://spring.io"
|
||||
val method = HttpMethod.GET
|
||||
template.exchange<List<Foo>>(url, method)
|
||||
verify(template, times(1)).exchange(url, method, null,
|
||||
object : ParameterizedTypeReference<List<Foo>>() {})
|
||||
verify { template.exchange(url, method, null,
|
||||
object : ParameterizedTypeReference<List<Foo>>() {}) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `exchange with reified type parameters, String and HttpEntity`() {
|
||||
val entity = mock<RequestEntity<Foo>>()
|
||||
val entity = mockk<RequestEntity<Foo>>()
|
||||
template.exchange<List<Foo>>(entity)
|
||||
verify(template, times(1)).exchange(entity,
|
||||
object : ParameterizedTypeReference<List<Foo>>() {})
|
||||
verify { template.exchange(entity,
|
||||
object : ParameterizedTypeReference<List<Foo>>() {}) }
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user