GH-420 Fix discovery of function type from class

Fix introspection over ScannedGenericBeanDefinition

Resolves #420
This commit is contained in:
Oleg Zhurakousky
2019-10-29 19:49:32 +01:00
parent 69c158c766
commit 00ec268aca
3 changed files with 41 additions and 3 deletions

View File

@@ -17,6 +17,7 @@
package org.springframework.cloud.function.context.catalog;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.sql.Date;
import java.util.List;
@@ -44,6 +45,23 @@ import static org.assertj.core.api.Assertions.assertThat;
@SuppressWarnings("unused")
public class FunctionTypeUtilsTests {
@Test
public void testFunctionTypeFrom() throws Exception {
Type type = FunctionTypeUtils.discoverFunctionTypeFromClass(SimpleConsumer.class);
assertThat(type).isInstanceOf(ParameterizedType.class);
Type wrapperType = ((ParameterizedType) type).getActualTypeArguments()[0];
assertThat(wrapperType).isInstanceOf(ParameterizedType.class);
assertThat(wrapperType.getTypeName()).contains("Flux");
Type innerWrapperType = ((ParameterizedType) wrapperType).getActualTypeArguments()[0];
assertThat(innerWrapperType).isInstanceOf(ParameterizedType.class);
assertThat(innerWrapperType.getTypeName()).contains("Message");
Type targetType = ((ParameterizedType) innerWrapperType).getActualTypeArguments()[0];
assertThat(targetType).isEqualTo(String.class);
System.out.println();
}
@Test
public void testInputCount() throws Exception {
int inputCount = FunctionTypeUtils.getInputCount(getReturnType("function"));
@@ -205,4 +223,10 @@ public class FunctionTypeUtilsTests {
private interface MyMessageConsumer extends MessageConsumer<Date> {
}
public static class SimpleConsumer implements Consumer<Flux<Message<String>>> {
@Override
public void accept(Flux<Message<String>> messageFlux) {
}
}
}