Polish Kotlin source code style
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.beans.factory
|
||||
|
||||
|
||||
/**
|
||||
* Extension for [BeanFactory.getBean] providing a `getBean<Foo>()` variant.
|
||||
*
|
||||
|
||||
@@ -17,13 +17,15 @@
|
||||
package org.springframework.beans.factory
|
||||
|
||||
/**
|
||||
* Extension for [ListableBeanFactory.getBeanNamesForType] providing a `getBeanNamesForType<Foo>()` variant.
|
||||
* Extension for [ListableBeanFactory.getBeanNamesForType] providing a
|
||||
* `getBeanNamesForType<Foo>()` variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
inline fun <reified T : Any> ListableBeanFactory.getBeanNamesForType(includeNonSingletons: Boolean = true, allowEagerInit: Boolean = true): Array<out String> =
|
||||
getBeanNamesForType(T::class.java, includeNonSingletons, allowEagerInit)
|
||||
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 `getBeansOfType<Foo>()` variant.
|
||||
@@ -31,11 +33,13 @@ inline fun <reified T : Any> ListableBeanFactory.getBeanNamesForType(includeNonS
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
inline fun <reified T : Any> ListableBeanFactory.getBeansOfType(includeNonSingletons: Boolean = true, allowEagerInit: Boolean = true): Map<String, T> =
|
||||
getBeansOfType(T::class.java, includeNonSingletons, allowEagerInit)
|
||||
inline fun <reified T : Any> ListableBeanFactory.getBeansOfType(includeNonSingletons: Boolean = true,
|
||||
allowEagerInit: Boolean = true): Map<String, T> =
|
||||
getBeansOfType(T::class.java, includeNonSingletons, allowEagerInit)
|
||||
|
||||
/**
|
||||
* Extension for [ListableBeanFactory.getBeanNamesForAnnotation] providing a `getBeansOfType<Foo>()` variant.
|
||||
* Extension for [ListableBeanFactory.getBeanNamesForAnnotation] providing a
|
||||
* `getBeansOfType<Foo>()` variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
@@ -44,7 +48,8 @@ inline fun <reified T : Annotation> ListableBeanFactory.getBeanNamesForAnnotatio
|
||||
getBeanNamesForAnnotation(T::class.java)
|
||||
|
||||
/**
|
||||
* Extension for [ListableBeanFactory.getBeansWithAnnotation] providing a `getBeansWithAnnotation<Foo>()` variant.
|
||||
* Extension for [ListableBeanFactory.getBeansWithAnnotation] providing a
|
||||
* `getBeansWithAnnotation<Foo>()` variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
@@ -53,7 +58,8 @@ inline fun <reified T : Annotation> ListableBeanFactory.getBeansWithAnnotation()
|
||||
getBeansWithAnnotation(T::class.java)
|
||||
|
||||
/**
|
||||
* Extension for [ListableBeanFactory.findAnnotationOnBean] providing a `findAnnotationOnBean<Foo>("foo")` variant.
|
||||
* Extension for [ListableBeanFactory.findAnnotationOnBean] providing a
|
||||
* `findAnnotationOnBean<Foo>("foo")` variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
|
||||
/**
|
||||
* Kotlin tests for {@link BeanUtils}
|
||||
* Kotlin tests for {@link BeanUtils}.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.mockito.Mockito.*
|
||||
import org.mockito.junit.MockitoJUnitRunner
|
||||
|
||||
/**
|
||||
* Mock object based tests for BeanFactory Kotlin extensions
|
||||
* Mock object based tests for BeanFactory Kotlin extensions.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
|
||||
@@ -231,7 +231,8 @@ class KotlinAutowiredTests {
|
||||
val optional: String = "foo",
|
||||
val injectedFromConstructor: TestBean
|
||||
) {
|
||||
@Autowired constructor(injectedFromSecondaryConstructor: Colour, injectedFromConstructor: TestBean, optional: String = "bar") : this(optional, injectedFromConstructor) {
|
||||
@Autowired constructor(injectedFromSecondaryConstructor: Colour, injectedFromConstructor: TestBean,
|
||||
optional: String = "bar") : this(optional, injectedFromConstructor) {
|
||||
this.injectedFromSecondaryConstructor = injectedFromSecondaryConstructor
|
||||
}
|
||||
|
||||
@@ -247,7 +248,8 @@ class KotlinAutowiredTests {
|
||||
val optional: String = "foo",
|
||||
val injectedFromConstructor: TestBean
|
||||
) {
|
||||
constructor(injectedFromSecondaryConstructor: Colour, injectedFromConstructor: TestBean, optional: String = "bar") : this(optional, injectedFromConstructor) {
|
||||
constructor(injectedFromSecondaryConstructor: Colour, injectedFromConstructor: TestBean,
|
||||
optional: String = "bar") : this(optional, injectedFromConstructor) {
|
||||
this.injectedFromSecondaryConstructor = injectedFromSecondaryConstructor
|
||||
}
|
||||
|
||||
|
||||
@@ -71,11 +71,13 @@ fun beans(init: BeanDefinitionDsl.() -> Unit): BeanDefinitionDsl {
|
||||
* Class implementing functional bean definition Kotlin DSL.
|
||||
*
|
||||
* @constructor Create a new bean definition DSL.
|
||||
* @param condition the predicate to fulfill in order to take in account the inner bean definition block
|
||||
* @param condition the predicate to fulfill in order to take in account the inner
|
||||
* bean definition block
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
open class BeanDefinitionDsl(private val condition: (ConfigurableEnvironment) -> Boolean = { true }) : ApplicationContextInitializer<GenericApplicationContext> {
|
||||
open class BeanDefinitionDsl(private val condition: (ConfigurableEnvironment) -> Boolean = { true })
|
||||
: ApplicationContextInitializer<GenericApplicationContext> {
|
||||
|
||||
@PublishedApi
|
||||
internal val registrations = arrayListOf<(GenericApplicationContext) -> Unit>()
|
||||
@@ -131,7 +133,8 @@ open class BeanDefinitionDsl(private val condition: (ConfigurableEnvironment) ->
|
||||
/**
|
||||
* Provide read access to some application context facilities.
|
||||
* @constructor Create a new bean definition context.
|
||||
* @param context the `ApplicationContext` instance to use for retrieving bean references, `Environment`, etc.
|
||||
* @param context the `ApplicationContext` instance to use for retrieving bean
|
||||
* references, `Environment`, etc.
|
||||
*/
|
||||
inner class BeanDefinitionContext(@PublishedApi internal val context: GenericApplicationContext) {
|
||||
|
||||
@@ -163,7 +166,8 @@ open class BeanDefinitionDsl(private val condition: (ConfigurableEnvironment) ->
|
||||
* @param isLazyInit Set whether this bean should be lazily initialized.
|
||||
* @param isPrimary Set whether this bean is a primary autowire candidate.
|
||||
* @param autowireMode Set the autowire mode, `Autowire.CONSTRUCTOR` by default
|
||||
* @param isAutowireCandidate Set whether this bean is a candidate for getting autowired into some other bean.
|
||||
* @param isAutowireCandidate Set whether this bean is a candidate for getting
|
||||
* autowired into some other bean.
|
||||
* @see GenericApplicationContext.registerBean
|
||||
* @see org.springframework.beans.factory.config.BeanDefinition
|
||||
*/
|
||||
@@ -200,7 +204,8 @@ open class BeanDefinitionDsl(private val condition: (ConfigurableEnvironment) ->
|
||||
* @param isLazyInit Set whether this bean should be lazily initialized.
|
||||
* @param isPrimary Set whether this bean is a primary autowire candidate.
|
||||
* @param autowireMode Set the autowire mode, `Autowire.NO` by default
|
||||
* @param isAutowireCandidate Set whether this bean is a candidate for getting autowired into some other bean.
|
||||
* @param isAutowireCandidate Set whether this bean is a candidate for getting
|
||||
* autowired into some other bean.
|
||||
* @param function the bean supplier function
|
||||
* @see GenericApplicationContext.registerBean
|
||||
* @see org.springframework.beans.factory.config.BeanDefinition
|
||||
@@ -226,8 +231,10 @@ open class BeanDefinitionDsl(private val condition: (ConfigurableEnvironment) ->
|
||||
registrations.add {
|
||||
val beanContext = BeanDefinitionContext(it)
|
||||
when (name) {
|
||||
null -> it.registerBean(T::class.java, Supplier { function.invoke(beanContext) }, customizer)
|
||||
else -> it.registerBean(name, T::class.java, Supplier { function.invoke(beanContext) }, customizer)
|
||||
null -> it.registerBean(T::class.java,
|
||||
Supplier { function.invoke(beanContext) }, customizer)
|
||||
else -> it.registerBean(name, T::class.java,
|
||||
Supplier { function.invoke(beanContext) }, customizer)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -246,9 +253,11 @@ open class BeanDefinitionDsl(private val condition: (ConfigurableEnvironment) ->
|
||||
/**
|
||||
* Take in account bean definitions enclosed in the provided lambda only when the
|
||||
* specified environment-based predicate is true.
|
||||
* @param condition the predicate to fulfill in order to take in account the inner bean definition block
|
||||
* @param condition the predicate to fulfill in order to take in account the inner
|
||||
* bean definition block
|
||||
*/
|
||||
fun environment(condition: ConfigurableEnvironment.() -> Boolean, init: BeanDefinitionDsl.() -> Unit): BeanDefinitionDsl {
|
||||
fun environment(condition: ConfigurableEnvironment.() -> Boolean,
|
||||
init: BeanDefinitionDsl.() -> Unit): BeanDefinitionDsl {
|
||||
val beans = BeanDefinitionDsl(condition::invoke)
|
||||
beans.init()
|
||||
children.add(beans)
|
||||
|
||||
@@ -20,9 +20,9 @@ import org.springframework.beans.factory.config.BeanDefinitionCustomizer
|
||||
import org.springframework.context.ApplicationContext
|
||||
import java.util.function.Supplier
|
||||
|
||||
|
||||
/**
|
||||
* Extension for [GenericApplicationContext.registerBean] providing a `registerBean<Foo>()` variant.
|
||||
* Extension for [GenericApplicationContext.registerBean] providing a
|
||||
* `registerBean<Foo>()` variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
@@ -32,12 +32,14 @@ inline fun <reified T : Any> GenericApplicationContext.registerBean(vararg custo
|
||||
}
|
||||
|
||||
/**
|
||||
* Extension for [GenericApplicationContext.registerBean] providing a `registerBean<Foo>("foo")` variant.
|
||||
* Extension for [GenericApplicationContext.registerBean] providing a
|
||||
* `registerBean<Foo>("foo")` variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
inline fun <reified T : Any> GenericApplicationContext.registerBean(beanName: String, vararg customizers: BeanDefinitionCustomizer) {
|
||||
inline fun <reified T : Any> GenericApplicationContext.registerBean(beanName: String,
|
||||
vararg customizers: BeanDefinitionCustomizer) {
|
||||
registerBean(beanName, T::class.java, *customizers)
|
||||
}
|
||||
|
||||
@@ -53,7 +55,8 @@ inline fun <reified T : Any> GenericApplicationContext.registerBean(
|
||||
}
|
||||
|
||||
/**
|
||||
* Extension for [GenericApplicationContext.registerBean] providing a `registerBean("foo") { Foo() }` variant.
|
||||
* Extension for [GenericApplicationContext.registerBean] providing a
|
||||
* `registerBean("foo") { Foo() }` variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
@@ -64,10 +67,12 @@ inline fun <reified T : Any> GenericApplicationContext.registerBean(name: String
|
||||
}
|
||||
|
||||
/**
|
||||
* Extension for [GenericApplicationContext] allowing `GenericApplicationContext { ... }` style initialization.
|
||||
* Extension for [GenericApplicationContext] allowing `GenericApplicationContext { ... }`
|
||||
* style initialization.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
fun GenericApplicationContext(configure: GenericApplicationContext.() -> Unit) = GenericApplicationContext().apply(configure)
|
||||
fun GenericApplicationContext(configure: GenericApplicationContext.() -> Unit) =
|
||||
GenericApplicationContext().apply(configure)
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.springframework.beans.factory.getBean
|
||||
import org.springframework.context.support.registerBean
|
||||
|
||||
/**
|
||||
* Tests for [AnnotationConfigApplicationContext] Kotlin extensions
|
||||
* Tests for [AnnotationConfigApplicationContext] Kotlin extensions.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
|
||||
@@ -20,9 +20,8 @@ import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
|
||||
/**
|
||||
* Tests for [Model] Kotlin extensions
|
||||
* Tests for [Model] Kotlin extensions.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
|
||||
@@ -20,9 +20,8 @@ import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
|
||||
/**
|
||||
* Tests for [ModelMap] Kotlin extensions
|
||||
* Tests for [ModelMap] Kotlin extensions.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.mockito.Mockito
|
||||
import org.mockito.junit.MockitoJUnitRunner
|
||||
|
||||
/**
|
||||
* Mock object based tests for PropertyResolver Kotlin extensions
|
||||
* Mock object based tests for PropertyResolver Kotlin extensions.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
|
||||
@@ -18,17 +18,18 @@ package org.springframework.jdbc.core
|
||||
|
||||
import java.sql.ResultSet
|
||||
|
||||
|
||||
/**
|
||||
* Extension for [JdbcOperations.queryForObject] providing a `queryForObject<Foo>("...")` variant
|
||||
* Extension for [JdbcOperations.queryForObject] providing a `queryForObject<Foo>("...")` variant.
|
||||
*
|
||||
* @author Mario Arias
|
||||
* @since 5.0
|
||||
*/
|
||||
inline fun <reified T : Any> JdbcOperations.queryForObject(sql: String): T? = queryForObject(sql, T::class.java)
|
||||
inline fun <reified T : Any> JdbcOperations.queryForObject(sql: String): T? =
|
||||
queryForObject(sql, T::class.java)
|
||||
|
||||
/**
|
||||
* Extensions for [JdbcOperations.queryForObject] providing a RowMapper-like function variant: `queryForObject("...", arg1, argN){ rs, i -> }`.
|
||||
* Extensions for [JdbcOperations.queryForObject] providing a RowMapper-like function
|
||||
* variant: `queryForObject("...", arg1, argN){ rs, i -> }`.
|
||||
*
|
||||
* @author Mario Arias
|
||||
* @since 5.0
|
||||
@@ -37,7 +38,8 @@ fun <T : Any> JdbcOperations.queryForObject(sql: String, vararg args: Any, funct
|
||||
queryForObject(sql, RowMapper { resultSet, i -> function(resultSet, i) }, *args)
|
||||
|
||||
/**
|
||||
* Extension for [JdbcOperations.queryForObject] providing a `queryForObject<Foo>("...", arrayOf(arg1, argN), intArray(type1, typeN))` variant
|
||||
* Extension for [JdbcOperations.queryForObject] providing a
|
||||
* `queryForObject<Foo>("...", arrayOf(arg1, argN), intArray(type1, typeN))` variant.
|
||||
*
|
||||
* @author Mario Arias
|
||||
* @since 5.0
|
||||
@@ -46,7 +48,8 @@ inline fun <reified T : Any> JdbcOperations.queryForObject(sql: String, args: Ar
|
||||
queryForObject(sql, args, argTypes, T::class.java)
|
||||
|
||||
/**
|
||||
* Extension for [JdbcOperations.queryForObject] providing a `queryForObject<Foo>("...", arrayOf(arg1, argN))` variant
|
||||
* Extension for [JdbcOperations.queryForObject] providing a
|
||||
* `queryForObject<Foo>("...", arrayOf(arg1, argN))` variant.
|
||||
*
|
||||
* @author Mario Arias
|
||||
* @since 5.0
|
||||
@@ -54,7 +57,6 @@ inline fun <reified T : Any> JdbcOperations.queryForObject(sql: String, args: Ar
|
||||
inline fun <reified T : Any> JdbcOperations.queryForObject(sql: String, args: Array<out Any>): T? =
|
||||
queryForObject(sql, args, T::class.java)
|
||||
|
||||
|
||||
/**
|
||||
* Extension for [JdbcOperations.queryForList] providing a `queryForList<Foo>("...")` variant.
|
||||
*
|
||||
@@ -66,17 +68,20 @@ inline fun <reified T : Any> JdbcOperations.queryForList(sql: String): List<T> =
|
||||
queryForList(sql, T::class.java)
|
||||
|
||||
/**
|
||||
* Extension for [JdbcOperations.queryForList] providing a `queryForList<Foo>("...", arrayOf(arg1, argN), intArray(type1, typeN))` variant
|
||||
* Extension for [JdbcOperations.queryForList] providing a
|
||||
* `queryForList<Foo>("...", arrayOf(arg1, argN), intArray(type1, typeN))` variant.
|
||||
*
|
||||
* @author Mario Arias
|
||||
* @since 5.0
|
||||
*/
|
||||
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
|
||||
inline fun <reified T : Any> JdbcOperations.queryForList(sql: String, args: Array<out Any>, argTypes: IntArray): List<T> =
|
||||
inline fun <reified T : Any> JdbcOperations.queryForList(sql: String, args: Array<out Any>,
|
||||
argTypes: IntArray): List<T> =
|
||||
queryForList(sql, args, argTypes, T::class.java)
|
||||
|
||||
/**
|
||||
* Extension for [JdbcOperations.queryForList] providing a `queryForList<Foo>("...", arrayOf(arg1, argN))` variant
|
||||
* Extension for [JdbcOperations.queryForList] providing a
|
||||
* `queryForList<Foo>("...", arrayOf(arg1, argN))` variant.
|
||||
*
|
||||
* @author Mario Arias
|
||||
* @since 5.0
|
||||
@@ -84,18 +89,20 @@ inline fun <reified T : Any> JdbcOperations.queryForList(sql: String, args: Arra
|
||||
inline fun <reified T : Any> JdbcOperations.queryForList(sql: String, args: Array<out Any>): List<T> =
|
||||
queryForList(sql, args, T::class.java)
|
||||
|
||||
|
||||
/**
|
||||
* Extension for [JdbcOperations.query] providing a ResultSetExtractor-like function variant: `query<Foo>("...", arg1, argN){ rs -> }`
|
||||
* Extension for [JdbcOperations.query] providing a ResultSetExtractor-like function
|
||||
* variant: `query<Foo>("...", arg1, argN){ rs -> }`.
|
||||
*
|
||||
* @author Mario Arias
|
||||
* @since 5.0
|
||||
*/
|
||||
inline fun <reified T : Any> JdbcOperations.query(sql: String, vararg args: Any, crossinline function: (ResultSet) -> T): T? =
|
||||
inline fun <reified T : Any> JdbcOperations.query(sql: String, vararg args: Any,
|
||||
crossinline function: (ResultSet) -> T): T? =
|
||||
query(sql, ResultSetExtractor { function(it) }, *args)
|
||||
|
||||
/**
|
||||
* Extension for [JdbcOperations.query] providing a RowCallbackHandler-like function variant: `query("...", arg1, argN){ rs -> }`
|
||||
* Extension for [JdbcOperations.query] providing a RowCallbackHandler-like function
|
||||
* variant: `query("...", arg1, argN){ rs -> }`.
|
||||
*
|
||||
* @author Mario Arias
|
||||
* @since 5.0
|
||||
@@ -104,7 +111,8 @@ fun JdbcOperations.query(sql: String, vararg args: Any, function: (ResultSet) ->
|
||||
query(sql, RowCallbackHandler { function(it) }, *args)
|
||||
|
||||
/**
|
||||
* Extensions for [JdbcOperations.query] providing a RowMapper-like function variant: `query("...", arg1, argN){ rs, i -> }`.
|
||||
* Extensions for [JdbcOperations.query] providing a RowMapper-like function variant:
|
||||
* `query("...", arg1, argN){ rs, i -> }`.
|
||||
*
|
||||
* @author Mario Arias
|
||||
* @since 5.0
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.springframework.jdbc.core.namedparam
|
||||
|
||||
/**
|
||||
* Extension for [MapSqlParameterSource.addValue] providing Array like setter
|
||||
* Extension for [MapSqlParameterSource.addValue] providing Array like setter.
|
||||
*
|
||||
* ```kotlin
|
||||
* source["age"] = 3
|
||||
@@ -31,7 +31,7 @@ operator fun MapSqlParameterSource.set(paramName: String, value: Any) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Extension for [MapSqlParameterSource.addValue] providing Array like setter
|
||||
* Extension for [MapSqlParameterSource.addValue] providing Array like setter.
|
||||
*
|
||||
* ```kotlin
|
||||
* source["age", JDBCType.INTEGER.vendorTypeNumber] = 3
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.jdbc.core
|
||||
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.junit.Test
|
||||
import java.sql.JDBCType
|
||||
|
||||
/**
|
||||
* Tests for [MapSqlParameterSource] Kotlin extensions
|
||||
* Tests for [MapSqlParameterSource] Kotlin extensions.
|
||||
*
|
||||
* @author Mario Arias
|
||||
*/
|
||||
|
||||
@@ -17,42 +17,43 @@
|
||||
package org.springframework.test.web.reactive.server
|
||||
|
||||
import org.reactivestreams.Publisher
|
||||
import org.springframework.test.web.reactive.server.WebTestClient.*
|
||||
|
||||
/**
|
||||
* Extension for [WebTestClient.RequestBodySpec.body] providing a variant without explicit class
|
||||
* Extension for [RequestBodySpec.body] providing a variant without explicit class
|
||||
* parameter thanks to Kotlin reified type parameters.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
inline fun <reified T : Any, S : Publisher<T>> WebTestClient.RequestBodySpec.body(publisher: S): WebTestClient.RequestHeadersSpec<*>
|
||||
inline fun <reified T : Any, S : Publisher<T>> RequestBodySpec.body(publisher: S): RequestHeadersSpec<*>
|
||||
= body(publisher, T::class.java)
|
||||
|
||||
/**
|
||||
* Extension for [WebTestClient.ResponseSpec.expectBody] providing a `expectBody<Foo>()` variant.
|
||||
* Extension for [ResponseSpec.expectBody] providing a `expectBody<Foo>()` variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
|
||||
inline fun <reified B : Any> WebTestClient.ResponseSpec.expectBody(): WebTestClient.BodySpec<B, *> =
|
||||
inline fun <reified B : Any> ResponseSpec.expectBody(): BodySpec<B, *> =
|
||||
expectBody(B::class.java)
|
||||
|
||||
/**
|
||||
* Extension for [WebTestClient.ResponseSpec.expectBodyList] providing a `expectBodyList<Foo>()` variant.
|
||||
* Extension for [ResponseSpec.expectBodyList] providing a `expectBodyList<Foo>()` variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
inline fun <reified E : Any> WebTestClient.ResponseSpec.expectBodyList(): WebTestClient.ListBodySpec<E> =
|
||||
inline fun <reified E : Any> ResponseSpec.expectBodyList(): ListBodySpec<E> =
|
||||
expectBodyList(E::class.java)
|
||||
|
||||
/**
|
||||
* Extension for [WebTestClient.ResponseSpec.returnResult] providing a `returnResult<Foo>()` variant.
|
||||
* Extension for [ResponseSpec.returnResult] providing a `returnResult<Foo>()` variant.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 5.0
|
||||
*/
|
||||
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
|
||||
inline fun <reified T : Any> WebTestClient.ResponseSpec.returnResult(): FluxExchangeResult<T> =
|
||||
inline fun <reified T : Any> ResponseSpec.returnResult(): FluxExchangeResult<T> =
|
||||
returnResult(T::class.java)
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.mockito.Mock
|
||||
import org.mockito.junit.MockitoJUnitRunner
|
||||
import org.reactivestreams.Publisher
|
||||
|
||||
|
||||
/**
|
||||
* Mock object based tests for [WebTestClient] Kotlin extensions
|
||||
*
|
||||
|
||||
@@ -23,7 +23,6 @@ import org.springframework.http.RequestEntity
|
||||
import org.springframework.http.ResponseEntity
|
||||
import java.net.URI
|
||||
|
||||
|
||||
/**
|
||||
* Extension for [RestOperations.getForObject] avoiding specifying the type
|
||||
* parameter thanks to Kotlin reified type parameters.
|
||||
@@ -117,7 +116,8 @@ inline fun <reified T: Any> RestOperations.postForObject(url: URI, request: Any)
|
||||
* @since 5.0
|
||||
*/
|
||||
@Throws(RestClientException::class)
|
||||
inline fun <reified T: Any> RestOperations.postForEntity(url: String, request: Any, vararg uriVariables: Any): ResponseEntity<T> =
|
||||
inline fun <reified T: Any> RestOperations.postForEntity(url: String, request: Any,
|
||||
vararg uriVariables: Any): ResponseEntity<T> =
|
||||
postForEntity(url, request, T::class.java, *uriVariables)
|
||||
|
||||
/**
|
||||
@@ -129,7 +129,8 @@ inline fun <reified T: Any> RestOperations.postForEntity(url: String, request: A
|
||||
* @since 5.0
|
||||
*/
|
||||
@Throws(RestClientException::class)
|
||||
inline fun <reified T: Any> RestOperations.postForEntity(url: String, request: Any, uriVariables: Map<String, *>): ResponseEntity<T> =
|
||||
inline fun <reified T: Any> RestOperations.postForEntity(url: String, request: Any,
|
||||
uriVariables: Map<String, *>): ResponseEntity<T> =
|
||||
postForEntity(url, request, T::class.java, uriVariables)
|
||||
|
||||
/**
|
||||
@@ -153,7 +154,8 @@ inline fun <reified T: Any> RestOperations.postForEntity(url: URI, request: Any)
|
||||
* @since 5.0
|
||||
*/
|
||||
@Throws(RestClientException::class)
|
||||
inline fun <reified T: Any> RestOperations.exchange(url: String, method: HttpMethod, requestEntity: HttpEntity<*>, vararg uriVariables: Any): ResponseEntity<T> =
|
||||
inline fun <reified T: Any> RestOperations.exchange(url: String, method: HttpMethod,
|
||||
requestEntity: HttpEntity<*>, vararg uriVariables: Any): ResponseEntity<T> =
|
||||
exchange(url, method, requestEntity, object : ParameterizedTypeReference<T>() {}, *uriVariables)
|
||||
|
||||
/**
|
||||
@@ -165,7 +167,8 @@ inline fun <reified T: Any> RestOperations.exchange(url: String, method: HttpMet
|
||||
* @since 5.0
|
||||
*/
|
||||
@Throws(RestClientException::class)
|
||||
inline fun <reified T: Any> RestOperations.exchange(url: String, method: HttpMethod, requestEntity: HttpEntity<*>, uriVariables: Map<String, *>): ResponseEntity<T> =
|
||||
inline fun <reified T: Any> RestOperations.exchange(url: String, method: HttpMethod,
|
||||
requestEntity: HttpEntity<*>, uriVariables: Map<String, *>): ResponseEntity<T> =
|
||||
exchange(url, method, requestEntity, object : ParameterizedTypeReference<T>() {}, uriVariables)
|
||||
|
||||
/**
|
||||
@@ -177,7 +180,8 @@ inline fun <reified T: Any> RestOperations.exchange(url: String, method: HttpMet
|
||||
* @since 5.0
|
||||
*/
|
||||
@Throws(RestClientException::class)
|
||||
inline fun <reified T: Any> RestOperations.exchange(url: URI, method: HttpMethod, requestEntity: HttpEntity<*>): ResponseEntity<T> =
|
||||
inline fun <reified T: Any> RestOperations.exchange(url: URI, method: HttpMethod,
|
||||
requestEntity: HttpEntity<*>): ResponseEntity<T> =
|
||||
exchange(url, method, requestEntity, object : ParameterizedTypeReference<T>() {})
|
||||
|
||||
/**
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.springframework.http.RequestEntity
|
||||
import java.net.URI
|
||||
|
||||
/**
|
||||
* Mock object based tests for [RestOperations] Kotlin extensions
|
||||
* Mock object based tests for [RestOperations] Kotlin extensions.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
@@ -135,7 +135,8 @@ class RestOperationsExtensionsTests {
|
||||
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, times(1)).exchange(url, method, entity,
|
||||
object : ParameterizedTypeReference<List<Foo>>() {}, var1, var2)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -145,7 +146,8 @@ class RestOperationsExtensionsTests {
|
||||
val entity = mock<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, times(1)).exchange(url, method, entity,
|
||||
object : ParameterizedTypeReference<List<Foo>>() {}, vars)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -154,14 +156,16 @@ class RestOperationsExtensionsTests {
|
||||
val method = HttpMethod.GET
|
||||
val entity = mock<HttpEntity<Foo>>()
|
||||
template.exchange<List<Foo>>(url, method, entity)
|
||||
verify(template, times(1)).exchange(url, method, entity, object : ParameterizedTypeReference<List<Foo>>() {})
|
||||
verify(template, times(1)).exchange(url, method, entity,
|
||||
object : ParameterizedTypeReference<List<Foo>>() {})
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `exchange with reified type parameters, String, HttpEntity`() {
|
||||
val entity = mock<RequestEntity<Foo>>()
|
||||
template.exchange<List<Foo>>(entity)
|
||||
verify(template, times(1)).exchange(entity, object : ParameterizedTypeReference<List<Foo>>() {})
|
||||
verify(template, times(1)).exchange(entity,
|
||||
object : ParameterizedTypeReference<List<Foo>>() {})
|
||||
}
|
||||
|
||||
class Foo
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.web.method.annotation
|
||||
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Before
|
||||
|
||||
@@ -21,7 +21,6 @@ import org.springframework.http.ResponseEntity
|
||||
import reactor.core.publisher.Flux
|
||||
import reactor.core.publisher.Mono
|
||||
|
||||
|
||||
/**
|
||||
* Extension for [ClientResponse.bodyToMono] providing a `bodyToMono<Foo>()` variant
|
||||
* leveraging Kotlin reified type parameters.
|
||||
|
||||
@@ -18,10 +18,11 @@ package org.springframework.web.reactive.function.client
|
||||
|
||||
import org.reactivestreams.Publisher
|
||||
import org.springframework.core.ParameterizedTypeReference
|
||||
import org.springframework.web.reactive.function.client.WebClient.RequestBodySpec
|
||||
import org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec
|
||||
import reactor.core.publisher.Flux
|
||||
import reactor.core.publisher.Mono
|
||||
|
||||
|
||||
/**
|
||||
* Extension for [WebClient.RequestBodySpec.body] providing a `body<Foo>()` variant
|
||||
* leveraging Kotlin reified type parameters.
|
||||
@@ -30,7 +31,7 @@ import reactor.core.publisher.Mono
|
||||
* @since 5.0
|
||||
*/
|
||||
@Suppress("EXTENSION_SHADOWED_BY_MEMBER")
|
||||
inline fun <reified T : Any, S : Publisher<T>> WebClient.RequestBodySpec.body(publisher: S): WebClient.RequestHeadersSpec<*> =
|
||||
inline fun <reified T : Any, S : Publisher<T>> RequestBodySpec.body(publisher: S): RequestHeadersSpec<*> =
|
||||
body(publisher, object : ParameterizedTypeReference<T>() {})
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,10 +21,10 @@ import org.springframework.http.HttpMethod
|
||||
import org.springframework.http.MediaType
|
||||
import reactor.core.publisher.Mono
|
||||
|
||||
|
||||
/**
|
||||
* Allow to create easily a `RouterFunction<ServerResponse>` from a Kotlin router DSL based
|
||||
* on the same building blocks than the Java one ([RouterFunction], [RequestPredicate], [HandlerFunction]).
|
||||
* on the same building blocks than the Java one ([RouterFunction], [RequestPredicate],
|
||||
* [HandlerFunction]).
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
@@ -126,9 +126,9 @@ open class RouterFunctionDsl {
|
||||
operator fun RequestPredicate.not(): RequestPredicate = this.negate()
|
||||
|
||||
/**
|
||||
* Route to the given router function if the given request predicate applies. This method can be
|
||||
* used to create *nested routes*, where a group of routes share a common path (prefix),
|
||||
* header, or other request predicate.
|
||||
* Route to the given router function if the given request predicate applies. This
|
||||
* method can be used to create *nested routes*, where a group of routes share a
|
||||
* common path (prefix), header, or other request predicate.
|
||||
* @see RouterFunctions.nest
|
||||
*/
|
||||
fun RequestPredicate.nest(r: RouterFunctionDsl.() -> Unit) {
|
||||
@@ -305,7 +305,8 @@ open class RouterFunctionDsl {
|
||||
* @param headersPredicate a predicate that tests against the request headers
|
||||
* @return a predicate that tests against the given header predicate
|
||||
*/
|
||||
fun headers(headersPredicate: (ServerRequest.Headers) -> Boolean): RequestPredicate = RequestPredicates.headers(headersPredicate)
|
||||
fun headers(headersPredicate: (ServerRequest.Headers) -> Boolean): RequestPredicate =
|
||||
RequestPredicates.headers(headersPredicate)
|
||||
|
||||
/**
|
||||
* Route to the given handler function if the given method predicate applies.
|
||||
@@ -364,7 +365,8 @@ open class RouterFunctionDsl {
|
||||
* predicate.
|
||||
* @see RequestPredicates.pathExtension
|
||||
*/
|
||||
fun pathExtension(predicate: (String) -> Boolean): RequestPredicate = RequestPredicates.pathExtension(predicate)
|
||||
fun pathExtension(predicate: (String) -> Boolean): RequestPredicate =
|
||||
RequestPredicates.pathExtension(predicate)
|
||||
|
||||
/**
|
||||
* Route to the given handler function if the given queryParam predicate applies.
|
||||
@@ -382,7 +384,8 @@ open class RouterFunctionDsl {
|
||||
* @return a predicate that matches the given predicate against the query parameter of the given name
|
||||
* @see ServerRequest#queryParam(String)
|
||||
*/
|
||||
fun queryParam(name: String, predicate: (String) -> Boolean): RequestPredicate = RequestPredicates.queryParam(name, predicate)
|
||||
fun queryParam(name: String, predicate: (String) -> Boolean): RequestPredicate =
|
||||
RequestPredicates.queryParam(name, predicate)
|
||||
|
||||
/**
|
||||
* Route to the given handler function if the given request predicate applies.
|
||||
|
||||
@@ -20,7 +20,6 @@ import org.springframework.core.ParameterizedTypeReference
|
||||
import reactor.core.publisher.Flux
|
||||
import reactor.core.publisher.Mono
|
||||
|
||||
|
||||
/**
|
||||
* Extension for [ServerRequest.bodyToMono] providing a `bodyToMono<Foo>()` variant
|
||||
* leveraging Kotlin reified type parameters.
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.mockito.junit.MockitoJUnitRunner
|
||||
import org.springframework.core.ParameterizedTypeReference
|
||||
|
||||
/**
|
||||
* Mock object based tests for [ClientResponse] Kotlin extensions
|
||||
* Mock object based tests for [ClientResponse] Kotlin extensions.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
|
||||
@@ -28,7 +28,7 @@ import reactor.test.StepVerifier
|
||||
import java.net.URI
|
||||
|
||||
/**
|
||||
* Tests for [RouterFunction] Kotlin DSL
|
||||
* Tests for [RouterFunction] Kotlin DSL.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
@@ -52,7 +52,11 @@ class RouterFunctionDslTests {
|
||||
|
||||
@Test
|
||||
fun acceptAndPOST() {
|
||||
val request = builder().method(POST).uri(URI("/api/foo/")).header(ACCEPT, APPLICATION_JSON_VALUE).build()
|
||||
val request = builder()
|
||||
.method(POST)
|
||||
.uri(URI("/api/foo/"))
|
||||
.header(ACCEPT, APPLICATION_JSON_VALUE)
|
||||
.build()
|
||||
StepVerifier.create(sampleRouter().route(request))
|
||||
.expectNextCount(1)
|
||||
.verifyComplete()
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.springframework.web.reactive.function.server.bodyToFlux
|
||||
import org.springframework.web.reactive.function.server.bodyToMono
|
||||
|
||||
/**
|
||||
* Mock object based tests for [ServerRequest] Kotlin extensions
|
||||
* Mock object based tests for [ServerRequest] Kotlin extensions.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user