@@ -76,6 +76,13 @@ public class ContextFunctionCatalogAutoConfigurationKotlinTests {
|
||||
assertThat(functionType.getRawType().getTypeName()).isEqualTo(Supplier.class.getName());
|
||||
assertThat(functionType.getActualTypeArguments().length).isEqualTo(1);
|
||||
assertThat(functionType.getActualTypeArguments()[0].getTypeName()).isEqualTo(String.class.getName());
|
||||
|
||||
function = this.context.getBean("kotlinPojoFunction");
|
||||
functionType = (ParameterizedType) FunctionTypeUtils.discoverFunctionType(function, "kotlinPojoFunction", this.context);
|
||||
assertThat(functionType.getRawType().getTypeName()).isEqualTo(Function.class.getName());
|
||||
assertThat(functionType.getActualTypeArguments().length).isEqualTo(2);
|
||||
assertThat(functionType.getActualTypeArguments()[0].getTypeName()).isEqualTo(Person.class.getName());
|
||||
assertThat(functionType.getActualTypeArguments()[1].getTypeName()).isEqualTo(String.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -27,24 +27,29 @@ import java.util.function.Function
|
||||
*/
|
||||
@EnableAutoConfiguration
|
||||
@Configuration
|
||||
open class KotlinLambdasConfiguration {
|
||||
class KotlinLambdasConfiguration {
|
||||
@Bean
|
||||
open fun kotlinFunction(): (String) -> String {
|
||||
fun kotlinFunction(): (String) -> String {
|
||||
return { it.toUpperCase() }
|
||||
}
|
||||
|
||||
@Bean
|
||||
fun kotlinPojoFunction(): (Person) -> String {
|
||||
return { it.name.toString()}
|
||||
}
|
||||
|
||||
@Bean
|
||||
open fun kotlinConsumer(): (String) -> Unit {
|
||||
fun kotlinConsumer(): (String) -> Unit {
|
||||
return { println(it) }
|
||||
}
|
||||
|
||||
@Bean
|
||||
open fun kotlinSupplier(): () -> String {
|
||||
fun kotlinSupplier(): () -> String {
|
||||
return { "Hello" }
|
||||
}
|
||||
|
||||
@Bean
|
||||
open fun javaFunction(): Function<String, String> {
|
||||
fun javaFunction(): Function<String, String> {
|
||||
return Function { x -> x }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2012-2021 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.function.kotlin
|
||||
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import java.util.function.Function
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
*/
|
||||
class Person {
|
||||
|
||||
var name:String? = null;
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user