parent
223315f96b
commit
04d5a2951c
|
|
@ -1,15 +1,5 @@
|
|||
package org.springframework.beans.factory
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
|
||||
/**
|
||||
* Extension for [BeanFactory.getBean] providing a [KClass] based variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Any> BeanFactory.getBean(requiredType: KClass<T>): T = getBean(requiredType.java)
|
||||
|
||||
/**
|
||||
* Extension for [BeanFactory.getBean] providing a `getBean<Foo>()` variant.
|
||||
|
|
@ -30,16 +20,6 @@ inline fun <reified T : Any> BeanFactory.getBean(): T = getBean(T::class.java)
|
|||
inline fun <reified T : Any> BeanFactory.getBean(name: String): T =
|
||||
getBean(name, T::class.java)
|
||||
|
||||
/**
|
||||
* Extension for [BeanFactory.getBean] providing a [KClass] based variant.
|
||||
*
|
||||
* @see BeanFactory.getBean(Class<T>, Object...)
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Any> BeanFactory.getBean(requiredType: KClass<T>, vararg args:Any): T =
|
||||
getBean(requiredType.java, *args)
|
||||
|
||||
/**
|
||||
* Extension for [BeanFactory.getBean] providing a `getBean<Foo>(arg1, arg2)` variant.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,18 +1,5 @@
|
|||
package org.springframework.beans.factory
|
||||
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
|
||||
/**
|
||||
* Extension for [ListableBeanFactory.getBeanNamesForType] providing a [KClass] based variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Any> ListableBeanFactory.getBeanNamesForType(type: KClass<T>,
|
||||
includeNonSingletons: Boolean = true, allowEagerInit: Boolean = true): Array<out String> =
|
||||
getBeanNamesForType(type.java, includeNonSingletons, allowEagerInit)
|
||||
|
||||
/**
|
||||
* Extension for [ListableBeanFactory.getBeanNamesForType] providing a `getBeanNamesForType<Foo>()` variant.
|
||||
*
|
||||
|
|
@ -22,15 +9,6 @@ fun <T : Any> ListableBeanFactory.getBeanNamesForType(type: KClass<T>,
|
|||
inline fun <reified T : Any> ListableBeanFactory.getBeanNamesForType(includeNonSingletons: Boolean = true, allowEagerInit: Boolean = true): Array<out String> =
|
||||
getBeanNamesForType(T::class.java, includeNonSingletons, allowEagerInit)
|
||||
|
||||
/**
|
||||
* Extension for [ListableBeanFactory.getBeansOfType] providing a [KClass] based variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Any> ListableBeanFactory.getBeansOfType(type: KClass<T>, includeNonSingletons: Boolean = true, allowEagerInit: Boolean = true): Map<String, Any> =
|
||||
getBeansOfType(type.java, includeNonSingletons, allowEagerInit)
|
||||
|
||||
/**
|
||||
* Extension for [ListableBeanFactory.getBeansOfType] providing a `getBeansOfType<Foo>()` variant.
|
||||
*
|
||||
|
|
@ -40,15 +18,6 @@ fun <T : Any> ListableBeanFactory.getBeansOfType(type: KClass<T>, includeNonSing
|
|||
inline fun <reified T : Any> ListableBeanFactory.getBeansOfType(includeNonSingletons: Boolean = true, allowEagerInit: Boolean = true): Map<String, Any> =
|
||||
getBeansOfType(T::class.java, includeNonSingletons, allowEagerInit)
|
||||
|
||||
/**
|
||||
* Extension for [ListableBeanFactory.getBeanNamesForAnnotation] providing a [KClass] based variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Annotation> ListableBeanFactory.getBeanNamesForAnnotation(type: KClass<T>): Array<out String> =
|
||||
getBeanNamesForAnnotation(type.java)
|
||||
|
||||
/**
|
||||
* Extension for [ListableBeanFactory.getBeanNamesForAnnotation] providing a `getBeansOfType<Foo>()` variant.
|
||||
*
|
||||
|
|
@ -58,15 +27,6 @@ fun <T : Annotation> ListableBeanFactory.getBeanNamesForAnnotation(type: KClass<
|
|||
inline fun <reified T : Annotation> ListableBeanFactory.getBeanNamesForAnnotation(): Array<out String> =
|
||||
getBeanNamesForAnnotation(T::class.java)
|
||||
|
||||
/**
|
||||
* Extension for [ListableBeanFactory.getBeansWithAnnotation] providing a [KClass] based variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Annotation> ListableBeanFactory.getBeansWithAnnotation(type: KClass<T>): MutableMap<String, Any> =
|
||||
getBeansWithAnnotation(type.java)
|
||||
|
||||
/**
|
||||
* Extension for [ListableBeanFactory.getBeansWithAnnotation] providing a `getBeansWithAnnotation<Foo>()` variant.
|
||||
*
|
||||
|
|
@ -76,15 +36,6 @@ fun <T : Annotation> ListableBeanFactory.getBeansWithAnnotation(type: KClass<T>)
|
|||
inline fun <reified T : Annotation> ListableBeanFactory.getBeansWithAnnotation(): MutableMap<String, Any> =
|
||||
getBeansWithAnnotation(T::class.java)
|
||||
|
||||
/**
|
||||
* Extension for [ListableBeanFactory.findAnnotationOnBean] providing a [KClass] based variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Annotation> ListableBeanFactory.findAnnotationOnBean(beanName:String, type: KClass<T>): Annotation? =
|
||||
findAnnotationOnBean(beanName, type.java)
|
||||
|
||||
/**
|
||||
* Extension for [ListableBeanFactory.findAnnotationOnBean] providing a `findAnnotationOnBean<Foo>("foo")` variant.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -18,12 +18,6 @@ class BeanFactoryExtensionsTests {
|
|||
@Mock(answer = Answers.RETURNS_MOCKS)
|
||||
lateinit var bf: BeanFactory
|
||||
|
||||
@Test
|
||||
fun `getBean with KClass`() {
|
||||
bf.getBean(Foo::class)
|
||||
verify(bf, times(1)).getBean(Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBean with reified type parameters`() {
|
||||
bf.getBean<Foo>()
|
||||
|
|
@ -37,14 +31,6 @@ class BeanFactoryExtensionsTests {
|
|||
verify(bf, 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, times(1)).getBean(Foo::class.java, arg1, arg2)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBean with reified type parameters and varargs`() {
|
||||
val arg1 = "arg1"
|
||||
|
|
|
|||
|
|
@ -18,24 +18,6 @@ class ListableBeanFactoryExtensionsTests {
|
|||
@Mock(answer = Answers.RETURNS_MOCKS)
|
||||
lateinit var lbf: ListableBeanFactory
|
||||
|
||||
@Test
|
||||
fun `getBeanNamesForType with KClass`() {
|
||||
lbf.getBeanNamesForType(Foo::class)
|
||||
verify(lbf, times(1)).getBeanNamesForType(Foo::class.java, true , true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeanNamesForType with KClass and Boolean`() {
|
||||
lbf.getBeanNamesForType(Foo::class, false)
|
||||
verify(lbf, times(1)).getBeanNamesForType(Foo::class.java, false , true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeanNamesForType with KClass, Boolean and Boolean`() {
|
||||
lbf.getBeanNamesForType(Foo::class, false, false)
|
||||
verify(lbf, times(1)).getBeanNamesForType(Foo::class.java, false , false)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeanNamesForType with reified type parameters`() {
|
||||
lbf.getBeanNamesForType<Foo>()
|
||||
|
|
@ -54,24 +36,6 @@ class ListableBeanFactoryExtensionsTests {
|
|||
verify(lbf, times(1)).getBeanNamesForType(Foo::class.java, false , false)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeansOfType with KClass`() {
|
||||
lbf.getBeansOfType(Foo::class)
|
||||
verify(lbf, times(1)).getBeansOfType(Foo::class.java, true , true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeansOfType with KClass and Boolean`() {
|
||||
lbf.getBeansOfType(Foo::class, false)
|
||||
verify(lbf, times(1)).getBeansOfType(Foo::class.java, false , true)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeansOfType with KClass, Boolean and Boolean`() {
|
||||
lbf.getBeansOfType(Foo::class, false, false)
|
||||
verify(lbf, times(1)).getBeansOfType(Foo::class.java, false , false)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeansOfType with reified type parameters`() {
|
||||
lbf.getBeansOfType<Foo>()
|
||||
|
|
@ -90,37 +54,18 @@ class ListableBeanFactoryExtensionsTests {
|
|||
verify(lbf, times(1)).getBeansOfType(Foo::class.java, false , false)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeanNamesForAnnotation with KClass`() {
|
||||
lbf.getBeanNamesForAnnotation(Bar::class)
|
||||
verify(lbf, times(1)).getBeanNamesForAnnotation(Bar::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeanNamesForAnnotation with reified type parameters`() {
|
||||
lbf.getBeanNamesForAnnotation<Bar>()
|
||||
verify(lbf, times(1)).getBeanNamesForAnnotation(Bar::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeansWithAnnotation with KClass`() {
|
||||
lbf.getBeansWithAnnotation(Bar::class)
|
||||
verify(lbf, times(1)).getBeansWithAnnotation(Bar::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeansWithAnnotation with reified type parameters`() {
|
||||
lbf.getBeansWithAnnotation<Bar>()
|
||||
verify(lbf, times(1)).getBeansWithAnnotation(Bar::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `findAnnotationOnBean with String and KClass`() {
|
||||
val name = "bar"
|
||||
lbf.findAnnotationOnBean(name, Bar::class)
|
||||
verify(lbf, times(1)).findAnnotationOnBean(name, Bar::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `findAnnotationOnBean with String and reified type parameters`() {
|
||||
val name = "bar"
|
||||
|
|
|
|||
|
|
@ -3,19 +3,8 @@ package org.springframework.context.support
|
|||
import org.springframework.beans.factory.config.BeanDefinitionCustomizer
|
||||
import org.springframework.context.ApplicationContext
|
||||
import java.util.function.Supplier
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
|
||||
/**
|
||||
* Extension for [GenericApplicationContext.registerBean] providing a [KClass] based variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Any> GenericApplicationContext.registerBean(beanClass: KClass<T>, vararg customizers: BeanDefinitionCustomizer) {
|
||||
registerBean(beanClass.java, *customizers)
|
||||
}
|
||||
|
||||
/**
|
||||
* Extension for [GenericApplicationContext.registerBean] providing a `registerBean<Foo>()` variant.
|
||||
*
|
||||
|
|
@ -26,16 +15,6 @@ inline fun <reified T : Any> GenericApplicationContext.registerBean(vararg custo
|
|||
registerBean(T::class.java, *customizers)
|
||||
}
|
||||
|
||||
/**
|
||||
* Extension for [GenericApplicationContext.registerBean] providing a [KClass] based variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Any> GenericApplicationContext.registerBean(beanName: String, beanClass: KClass<T>, vararg customizers: BeanDefinitionCustomizer) {
|
||||
registerBean(beanName, beanClass.java, *customizers)
|
||||
}
|
||||
|
||||
/**
|
||||
* Extension for [GenericApplicationContext.registerBean] providing a `registerBean<Foo>("foo")` variant.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -14,15 +14,15 @@ class GenericApplicationContextExtensionsTests {
|
|||
@Test
|
||||
fun registerBeanWithClass() {
|
||||
val context = GenericApplicationContext()
|
||||
context.registerBean(BeanA::class)
|
||||
context.registerBean<BeanA>()
|
||||
context.refresh()
|
||||
assertNotNull(context.getBean(BeanA::class))
|
||||
assertNotNull(context.getBean<BeanA>())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun registerBeanWithNameAndClass() {
|
||||
val context = GenericApplicationContext()
|
||||
context.registerBean("a", BeanA::class)
|
||||
context.registerBean<BeanA>("a")
|
||||
context.refresh()
|
||||
assertNotNull(context.getBean("a"))
|
||||
}
|
||||
|
|
@ -32,7 +32,7 @@ class GenericApplicationContextExtensionsTests {
|
|||
val context = GenericApplicationContext()
|
||||
context.registerBean { BeanA() }
|
||||
context.refresh()
|
||||
assertNotNull(context.getBean(BeanA::class))
|
||||
assertNotNull(context.getBean<BeanA>())
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -46,34 +46,23 @@ class GenericApplicationContextExtensionsTests {
|
|||
@Test
|
||||
fun registerBeanWithFunction() {
|
||||
val context = GenericApplicationContext()
|
||||
context.registerBean(BeanA::class)
|
||||
context.registerBean { BeanB(it.getBean(BeanA::class)) }
|
||||
context.registerBean<BeanA>()
|
||||
context.registerBean { BeanB(it.getBean<BeanA>()) }
|
||||
context.refresh()
|
||||
assertNotNull(context.getBean(BeanA::class))
|
||||
assertNotNull(context.getBean(BeanB::class))
|
||||
assertNotNull(context.getBean<BeanA>())
|
||||
assertNotNull(context.getBean<BeanB>())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun registerBeanWithNameAndFunction() {
|
||||
val context = GenericApplicationContext()
|
||||
context.registerBean("a", BeanA::class)
|
||||
context.registerBean("b") { BeanB(it.getBean(BeanA::class)) }
|
||||
context.registerBean<BeanA>("a")
|
||||
context.registerBean("b") { BeanB(it.getBean<BeanA>()) }
|
||||
context.refresh()
|
||||
assertNotNull(context.getBean("a"))
|
||||
assertNotNull(context.getBean("b"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun registerBeanWithGradleStyleApi() {
|
||||
val context = GenericApplicationContext {
|
||||
registerBean<BeanA>()
|
||||
registerBean { BeanB(it.getBean<BeanA>()) }
|
||||
}
|
||||
context.refresh()
|
||||
assertNotNull(context.getBean<BeanA>())
|
||||
assertNotNull(context.getBean<BeanB>())
|
||||
}
|
||||
|
||||
class BeanA
|
||||
|
||||
class BeanB(val a: BeanA)
|
||||
|
|
|
|||
|
|
@ -17,17 +17,8 @@
|
|||
package org.springframework.jdbc.core
|
||||
|
||||
import java.sql.ResultSet
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
|
||||
/**
|
||||
* Extension for [JdbcOperations.queryForObject] providing a [KClass] based variant
|
||||
*
|
||||
* @author Mario Arias
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Any> JdbcOperations.queryForObject(sql: String, elementType: KClass<T>): T? = queryForObject(sql, elementType.java)
|
||||
|
||||
/**
|
||||
* Extension for [JdbcOperations.queryForObject] providing a `queryForObject<Foo>("...")` variant
|
||||
*
|
||||
|
|
@ -45,15 +36,6 @@ inline fun <reified T : Any> JdbcOperations.queryForObject(sql: String): T? = qu
|
|||
fun <T : Any> JdbcOperations.queryForObject(sql: String, vararg args: Any, function: (ResultSet, Int) -> T): T =
|
||||
queryForObject(sql, RowMapper { resultSet, i -> function(resultSet, i) }, *args)
|
||||
|
||||
/**
|
||||
* Extension for [JdbcOperations.queryForObject] providing a [KClass] based variant
|
||||
*
|
||||
* @author Mario Arias
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Any> JdbcOperations.queryForObject(sql: String, args: Array<out Any>, argTypes: IntArray, requiredType: KClass<T>): T? =
|
||||
queryForObject(sql, args, argTypes, requiredType.java)
|
||||
|
||||
/**
|
||||
* Extension for [JdbcOperations.queryForObject] providing a `queryForObject<Foo>("...", arrayOf(arg1, argN), intArray(type1, typeN))` variant
|
||||
*
|
||||
|
|
@ -63,15 +45,6 @@ fun <T : Any> JdbcOperations.queryForObject(sql: String, args: Array<out Any>, a
|
|||
inline fun <reified T : Any> JdbcOperations.queryForObject(sql: String, args: Array<out Any>, argTypes: IntArray): T? =
|
||||
queryForObject(sql, args, argTypes, T::class.java)
|
||||
|
||||
/**
|
||||
* Extension for [JdbcOperations.queryForObject] providing a [KClass] based variant
|
||||
*
|
||||
* @author Mario Arias
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Any> JdbcOperations.queryForObject(sql: String, args: Array<out Any>, requiredType: KClass<T>): T? =
|
||||
queryForObject(sql, args, requiredType.java)
|
||||
|
||||
/**
|
||||
* Extension for [JdbcOperations.queryForObject] providing a `queryForObject<Foo>("...", arrayOf(arg1, argN))` variant
|
||||
*
|
||||
|
|
@ -81,15 +54,6 @@ fun <T : Any> JdbcOperations.queryForObject(sql: String, args: Array<out Any>, r
|
|||
inline fun <reified T : Any> JdbcOperations.queryForObject(sql: String, args: Array<out Any>): T? =
|
||||
queryForObject(sql, args, T::class.java)
|
||||
|
||||
/**
|
||||
* Extension for [JdbcOperations.queryForObject] providing a [KClass] based variant
|
||||
*
|
||||
* @author Mario Arias
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Any> JdbcOperations.queryForObject(sql: String, requiredType: KClass<T>, vararg args: Any): T? =
|
||||
queryForObject(sql, requiredType.java, *args)
|
||||
|
||||
|
||||
/**
|
||||
* Extension for [JdbcOperations.queryForList] providing a `queryForList<Foo>("...")` variant.
|
||||
|
|
|
|||
|
|
@ -38,14 +38,6 @@ class JdbcOperationsExtensionsTests {
|
|||
@Mock(answer = Answers.RETURNS_MOCKS)
|
||||
lateinit var template: JdbcTemplate
|
||||
|
||||
@Test
|
||||
fun `queryForObject with KClass`() {
|
||||
val sql = "select age from customer where id = 3"
|
||||
val requiredType = Int::class
|
||||
template.queryForObject(sql, requiredType)
|
||||
verify(template, times(1)).queryForObject(sql, requiredType)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `queryForObject with reified type parameters`() {
|
||||
val sql = "select age from customer where id = 3"
|
||||
|
|
@ -60,16 +52,6 @@ class JdbcOperationsExtensionsTests {
|
|||
verify(template, times(1)).queryForObject(eq(sql), any<RowMapper<Int>>(), eq(3))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `queryForObject with argTypes`() {
|
||||
val sql = "select age from customer where id = ?"
|
||||
val args = arrayOf(3)
|
||||
val argTypes = intArrayOf(JDBCType.INTEGER.vendorTypeNumber)
|
||||
val requiredType = Int::class
|
||||
template.queryForObject(sql, args, argTypes, requiredType)
|
||||
verify(template, times(1)).queryForObject(sql, args, argTypes, requiredType)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `queryForObject with reified type parameters and argTypes`() {
|
||||
val sql = "select age from customer where id = ?"
|
||||
|
|
@ -79,14 +61,6 @@ class JdbcOperationsExtensionsTests {
|
|||
verify(template, times(1)).queryForObject(sql, args, argTypes, Integer::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `queryForObject with args`() {
|
||||
val sql = "select age from customer where id = ?"
|
||||
val args = arrayOf(3)
|
||||
template.queryForObject(sql, args, Int::class)
|
||||
verify(template, times(1)).queryForObject(sql, args, Int::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `queryForObject with reified type parameters and args`() {
|
||||
val sql = "select age from customer where id = ?"
|
||||
|
|
@ -95,13 +69,6 @@ class JdbcOperationsExtensionsTests {
|
|||
verify(template, times(1)).queryForObject(sql, args, Integer::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `queryForObject with varargs`() {
|
||||
val sql = "select age from customer where id = ?"
|
||||
template.queryForObject(sql, Int::class, 3)
|
||||
verify(template, times(1)).queryForObject(sql, Int::class.java, 3)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `queryForList with reified type parameters`() {
|
||||
val sql = "select age from customer where id = 3"
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
package org.springframework.test.web.reactive.server
|
||||
|
||||
import org.reactivestreams.Publisher
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
/**
|
||||
* Extension for [WebTestClient.RequestBodySpec.body] providing a variant without explicit class
|
||||
|
|
@ -29,15 +28,6 @@ import kotlin.reflect.KClass
|
|||
inline fun <reified T : Any, S : Publisher<T>> WebTestClient.RequestBodySpec.body(publisher: S): WebTestClient.RequestHeadersSpec<*>
|
||||
= body(publisher, T::class.java)
|
||||
|
||||
/**
|
||||
* Extension for [WebTestClient.ResponseSpec.expectBody] providing a [KClass] based variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <B : Any> WebTestClient.ResponseSpec.expectBody(type: KClass<B>): WebTestClient.BodySpec<B, *> =
|
||||
expectBody(type.java)
|
||||
|
||||
/**
|
||||
* Extension for [WebTestClient.ResponseSpec.expectBody] providing a `expectBody<Foo>()` variant.
|
||||
*
|
||||
|
|
@ -47,15 +37,6 @@ fun <B : Any> WebTestClient.ResponseSpec.expectBody(type: KClass<B>): WebTestCli
|
|||
inline fun <reified B : Any> WebTestClient.ResponseSpec.expectBody(): WebTestClient.BodySpec<B, *> =
|
||||
expectBody(B::class.java)
|
||||
|
||||
/**
|
||||
* Extension for [WebTestClient.ResponseSpec.expectBodyList] providing a [KClass] based variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <E : Any> WebTestClient.ResponseSpec.expectBodyList(type: KClass<E>): WebTestClient.ListBodySpec<E> =
|
||||
expectBodyList(type.java)
|
||||
|
||||
/**
|
||||
* Extension for [WebTestClient.ResponseSpec.expectBodyList] providing a `expectBodyList<Foo>()` variant.
|
||||
*
|
||||
|
|
@ -65,15 +46,6 @@ fun <E : Any> WebTestClient.ResponseSpec.expectBodyList(type: KClass<E>): WebTes
|
|||
inline fun <reified E : Any> WebTestClient.ResponseSpec.expectBodyList(): WebTestClient.ListBodySpec<E> =
|
||||
expectBodyList(E::class.java)
|
||||
|
||||
/**
|
||||
* Extension for [WebTestClient.ResponseSpec.returnResult] providing a [KClass] based variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Any> WebTestClient.ResponseSpec.returnResult(type: KClass<T>): FluxExchangeResult<T> =
|
||||
returnResult(type.java)
|
||||
|
||||
/**
|
||||
* Extension for [WebTestClient.ResponseSpec.returnResult] providing a `returnResult<Foo>()` variant.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -33,36 +33,18 @@ class WebTestClientExtensionsTests {
|
|||
verify(requestBodySpec, times(1)).body(body, Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ResponseSpec#expectBody with KClass`() {
|
||||
responseSpec.expectBody(Foo::class)
|
||||
verify(responseSpec, times(1)).expectBody(Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ResponseSpec#expectBody with reified type parameters`() {
|
||||
responseSpec.expectBody<Foo>()
|
||||
verify(responseSpec, times(1)).expectBody(Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ResponseSpec#expectBodyList with KClass`() {
|
||||
responseSpec.expectBodyList(Foo::class)
|
||||
verify(responseSpec, times(1)).expectBodyList(Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ResponseSpec#expectBodyList with reified type parameters`() {
|
||||
responseSpec.expectBodyList<Foo>()
|
||||
verify(responseSpec, times(1)).expectBodyList(Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ResponseSpec#returnResult with KClass`() {
|
||||
responseSpec.returnResult(Foo::class)
|
||||
verify(responseSpec, times(1)).returnResult(Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ResponseSpec#returnResult with reified type parameters`() {
|
||||
responseSpec.returnResult<Foo>()
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package org.springframework.web.reactive.function
|
|||
import org.springframework.http.ReactiveHttpInputMessage
|
||||
import reactor.core.publisher.Flux
|
||||
import reactor.core.publisher.Mono
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
/**
|
||||
* Function for providing a `bodyToMono()` alternative to `BodyExtractors.toMono(Foo::class.java)`.
|
||||
|
|
@ -15,16 +14,6 @@ import kotlin.reflect.KClass
|
|||
inline fun <reified T : Any> bodyToMono(): BodyExtractor<Mono<T>, ReactiveHttpInputMessage> =
|
||||
BodyExtractors.toMono(T::class.java)
|
||||
|
||||
/**
|
||||
* Function for providing a `bodyToMono(Foo::class)` alternative to `BodyExtractors.toMono(Foo::class.java)`.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
* @see [KT-11968](https://youtrack.jetbrains.com/issue/KT-11968)
|
||||
*/
|
||||
fun <T : Any> bodyToMono(elementClass: KClass<T>): BodyExtractor<Mono<T>, ReactiveHttpInputMessage> =
|
||||
BodyExtractors.toMono(elementClass.java)
|
||||
|
||||
/**
|
||||
* Function for providing a `bodyToFlux()` alternative to `BodyExtractors.toFlux(Foo::class.java)`.
|
||||
*
|
||||
|
|
@ -35,12 +24,3 @@ fun <T : Any> bodyToMono(elementClass: KClass<T>): BodyExtractor<Mono<T>, Reacti
|
|||
inline fun <reified T : Any> bodyToFlux(): BodyExtractor<Flux<T>, ReactiveHttpInputMessage> =
|
||||
BodyExtractors.toFlux(T::class.java)
|
||||
|
||||
/**
|
||||
* Function for providing a `bodyToFlux(Foo::class)` alternative to `BodyExtractors.toFlux(Foo::class.java)`.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
* @see [KT-11968](https://youtrack.jetbrains.com/issue/KT-11968)
|
||||
*/
|
||||
fun <T : Any> bodyToFlux(elementClass: KClass<T>): BodyExtractor<Flux<T>, ReactiveHttpInputMessage> =
|
||||
BodyExtractors.toFlux(elementClass.java)
|
||||
|
|
|
|||
|
|
@ -2,17 +2,8 @@ package org.springframework.web.reactive.function.client
|
|||
|
||||
import reactor.core.publisher.Flux
|
||||
import reactor.core.publisher.Mono
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
|
||||
/**
|
||||
* Extension for [ClientResponse.bodyToMono] providing a [KClass] based variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Any> ClientResponse.bodyToMono(type: KClass<T>): Mono<T> = bodyToMono(type.java)
|
||||
|
||||
/**
|
||||
* Extension for [ClientResponse.bodyToMono] providing a `bodyToMono<Foo>()` variant.
|
||||
*
|
||||
|
|
@ -21,15 +12,6 @@ fun <T : Any> ClientResponse.bodyToMono(type: KClass<T>): Mono<T> = bodyToMono(t
|
|||
*/
|
||||
inline fun <reified T : Any> ClientResponse.bodyToMono(): Mono<T> = bodyToMono(T::class.java)
|
||||
|
||||
|
||||
/**
|
||||
* Extension for [ClientResponse.bodyToFlux] providing a [KClass] based variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Any> ClientResponse.bodyToFlux(type: KClass<T>): Flux<T> = bodyToFlux(type.java)
|
||||
|
||||
/**
|
||||
* Extension for [ClientResponse.bodyToFlux] providing a `bodyToFlux<Foo>()` variant.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import org.reactivestreams.Publisher
|
|||
import org.springframework.http.ResponseEntity
|
||||
import reactor.core.publisher.Flux
|
||||
import reactor.core.publisher.Mono
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
|
||||
/**
|
||||
* Extension for [WebClient.RequestBodySpec.body] providing a variant without explicit class
|
||||
|
|
@ -33,14 +33,6 @@ import kotlin.reflect.KClass
|
|||
inline fun <reified T : Any, S : Publisher<T>> WebClient.RequestBodySpec.body(publisher: S): WebClient.RequestHeadersSpec<*>
|
||||
= body(publisher, T::class.java)
|
||||
|
||||
/**
|
||||
* Extension for [WebClient.ResponseSpec.bodyToMono] providing a [KClass] based variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Any> WebClient.ResponseSpec.bodyToMono(type: KClass<T>): Mono<T> = bodyToMono(type.java)
|
||||
|
||||
/**
|
||||
* Extension for [WebClient.ResponseSpec.bodyToMono] providing a `bodyToMono<Foo>()` variant.
|
||||
*
|
||||
|
|
@ -50,14 +42,6 @@ fun <T : Any> WebClient.ResponseSpec.bodyToMono(type: KClass<T>): Mono<T> = body
|
|||
inline fun <reified T : Any> WebClient.ResponseSpec.bodyToMono(): Mono<T> = bodyToMono(T::class.java)
|
||||
|
||||
|
||||
/**
|
||||
* Extension for [WebClient.ResponseSpec.bodyToFlux] providing a [KClass] based variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Any> WebClient.ResponseSpec.bodyToFlux(type: KClass<T>): Flux<T> = bodyToFlux(type.java)
|
||||
|
||||
/**
|
||||
* Extension for [WebClient.ResponseSpec.bodyToFlux] providing a `bodyToFlux<Foo>()` variant.
|
||||
*
|
||||
|
|
@ -66,14 +50,6 @@ fun <T : Any> WebClient.ResponseSpec.bodyToFlux(type: KClass<T>): Flux<T> = body
|
|||
*/
|
||||
inline fun <reified T : Any> WebClient.ResponseSpec.bodyToFlux(): Flux<T> = bodyToFlux(T::class.java)
|
||||
|
||||
/**
|
||||
* Extension for [WebClient.ResponseSpec.toEntity] providing a [KClass] based variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Any> WebClient.ResponseSpec.toEntity(type: KClass<T>): Mono<ResponseEntity<T>> = toEntity(type.java)
|
||||
|
||||
/**
|
||||
* Extension for [WebClient.ResponseSpec.toEntity] providing a `bodyToEntity<Foo>()` variant.
|
||||
*
|
||||
|
|
@ -82,14 +58,6 @@ fun <T : Any> WebClient.ResponseSpec.toEntity(type: KClass<T>): Mono<ResponseEnt
|
|||
*/
|
||||
inline fun <reified T : Any> WebClient.ResponseSpec.toEntity(): Mono<ResponseEntity<T>> = toEntity(T::class.java)
|
||||
|
||||
/**
|
||||
* Extension for [WebClient.ResponseSpec.toEntityList] providing a [KClass] based variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Any> WebClient.ResponseSpec.toEntityList(type: KClass<T>): Mono<ResponseEntity<List<T>>> = toEntityList(type.java)
|
||||
|
||||
/**
|
||||
* Extension for [WebClient.ResponseSpec.toEntityList] providing a `bodyToEntityList<Foo>()` variant.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -2,17 +2,8 @@ package org.springframework.web.reactive.function.server
|
|||
|
||||
import reactor.core.publisher.Flux
|
||||
import reactor.core.publisher.Mono
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
|
||||
/**
|
||||
* Extension for [ServerRequest.bodyToMono] providing a [KClass] based variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Any> ServerRequest.bodyToMono(type: KClass<T>): Mono<T> = bodyToMono(type.java)
|
||||
|
||||
/**
|
||||
* Extension for [ServerRequest.bodyToMono] providing a `bodyToMono<Foo>()` variant.
|
||||
*
|
||||
|
|
@ -21,14 +12,6 @@ fun <T : Any> ServerRequest.bodyToMono(type: KClass<T>): Mono<T> = bodyToMono(ty
|
|||
*/
|
||||
inline fun <reified T : Any> ServerRequest.bodyToMono(): Mono<T> = bodyToMono(T::class.java)
|
||||
|
||||
/**
|
||||
* Extension for [ServerRequest.bodyToFlux] providing a [KClass] based variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
fun <T : Any> ServerRequest.bodyToFlux(type: KClass<T>): Flux<T> = bodyToFlux(type.java)
|
||||
|
||||
/**
|
||||
* Extension for [ServerRequest.bodyToFlux] providing a `bodyToFlux<Foo>()` variant.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -14,21 +14,11 @@ import org.mockito.junit.MockitoJUnitRunner
|
|||
@RunWith(MockitoJUnitRunner::class)
|
||||
class BodyExtractorsExtensionsTests {
|
||||
|
||||
@Test
|
||||
fun `bodyToMono with KClass`() {
|
||||
assertNotNull(bodyToMono(Foo::class))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `bodyToMono with reified type parameter`() {
|
||||
assertNotNull(bodyToMono<Foo>())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `bodyToFlux with KClass`() {
|
||||
assertNotNull(bodyToFlux(Foo::class))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `bodyToFlux with reified type parameter`() {
|
||||
assertNotNull(bodyToFlux<Foo>())
|
||||
|
|
|
|||
|
|
@ -18,24 +18,12 @@ class ClientResponseExtensionsTests {
|
|||
@Mock(answer = Answers.RETURNS_MOCKS)
|
||||
lateinit var response: ClientResponse
|
||||
|
||||
@Test
|
||||
fun `bodyToMono with KClass`() {
|
||||
response.bodyToMono(Foo::class)
|
||||
verify(response, times(1)).bodyToMono(Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `bodyToMono with reified type parameters`() {
|
||||
response.bodyToMono<Foo>()
|
||||
verify(response, times(1)).bodyToMono(Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `bodyToFlux with KClass`() {
|
||||
response.bodyToFlux(Foo::class)
|
||||
verify(response, times(1)).bodyToFlux(Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `bodyToFlux with reified type parameters`() {
|
||||
response.bodyToFlux<Foo>()
|
||||
|
|
|
|||
|
|
@ -31,48 +31,24 @@ class WebClientExtensionsTests {
|
|||
verify(requestBodySpec, times(1)).body(body, Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ResponseSpec#bodyToMono with KClass`() {
|
||||
responseSpec.bodyToMono(Foo::class)
|
||||
verify(responseSpec, times(1)).bodyToMono(Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ResponseSpec#bodyToMono with reified type parameters`() {
|
||||
responseSpec.bodyToMono<Foo>()
|
||||
verify(responseSpec, times(1)).bodyToMono(Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ResponseSpec#bodyToFlux with KClass`() {
|
||||
responseSpec.bodyToFlux(Foo::class)
|
||||
verify(responseSpec, times(1)).bodyToFlux(Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ResponseSpec#bodyToFlux with reified type parameters`() {
|
||||
responseSpec.bodyToFlux<Foo>()
|
||||
verify(responseSpec, times(1)).bodyToFlux(Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ResponseSpec#toEntity with KClass`() {
|
||||
responseSpec.toEntity(Foo::class)
|
||||
verify(responseSpec, times(1)).toEntity(Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ResponseSpec#toEntity with reified type parameters`() {
|
||||
responseSpec.toEntity<Foo>()
|
||||
verify(responseSpec, times(1)).toEntity(Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ResponseSpec#toEntityList with KClass`() {
|
||||
responseSpec.toEntityList(Foo::class)
|
||||
verify(responseSpec, times(1)).toEntityList(Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ResponseSpec#toEntityList with reified type parameters`() {
|
||||
responseSpec.toEntityList<Foo>()
|
||||
|
|
|
|||
|
|
@ -21,24 +21,12 @@ class ServerRequestExtensionsTests {
|
|||
@Mock(answer = Answers.RETURNS_MOCKS)
|
||||
lateinit var request: ServerRequest
|
||||
|
||||
@Test
|
||||
fun `bodyToMono with KClass`() {
|
||||
request.bodyToMono(Foo::class)
|
||||
verify(request, times(1)).bodyToMono(Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `bodyToMono with reified type parameters`() {
|
||||
request.bodyToMono<Foo>()
|
||||
verify(request, times(1)).bodyToMono(Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `bodyToFlux with KClass`() {
|
||||
request.bodyToFlux(Foo::class)
|
||||
verify(request, times(1)).bodyToFlux(Foo::class.java)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `bodyToFlux with reified type parameters`() {
|
||||
request.bodyToFlux<Foo>()
|
||||
|
|
|
|||
Loading…
Reference in New Issue