diff --git a/spring-modulith-events/spring-modulith-events-api/src/main/java/org/springframework/modulith/events/externalize/ExternalizationCallback.java b/spring-modulith-events/spring-modulith-events-api/src/main/java/org/springframework/modulith/events/externalize/ExternalizationCallback.java new file mode 100644 index 000000000..9da3fd979 --- /dev/null +++ b/spring-modulith-events/spring-modulith-events-api/src/main/java/org/springframework/modulith/events/externalize/ExternalizationCallback.java @@ -0,0 +1,26 @@ +/* + * Copyright 2023 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.modulith.events.externalize; + +import org.springframework.modulith.events.externalize.EventExternalizationConfiguration.RoutingTarget; + +/** + * @author Oliver Drotbohm + */ +@FunctionalInterface +public interface ExternalizationCallback { + void send(T infrastructure, RoutingTarget target, Object payload); +} diff --git a/spring-modulith-events/spring-modulith-events-core/src/test/java/org/springframework/modulith/events/config/FooTest.java b/spring-modulith-events/spring-modulith-events-core/src/test/java/org/springframework/modulith/events/config/FooTest.java new file mode 100644 index 000000000..47388d2e3 --- /dev/null +++ b/spring-modulith-events/spring-modulith-events-core/src/test/java/org/springframework/modulith/events/config/FooTest.java @@ -0,0 +1,56 @@ +/* + * Copyright 2023 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.modulith.events.config; + +import static org.assertj.core.api.Assertions.*; + +import org.junit.jupiter.api.Test; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.Bean; + +/** + * @author Oliver Drotbohm + */ +public class FooTest { + + @Test + void detectsGenericFromBeanDefinitionForLambdaDeclaration() { + + try (var context = new AnnotationConfigApplicationContext(MyConfiguration.class)) { + + var factory = context.getBeanFactory(); + var names = factory.getBeanNamesForType(MyGeneric.class); + + var definition = factory.getBeanDefinition(names[0]); + var type = definition.getResolvableType(); + + assertThat(type.as(MyGeneric.class).getGeneric(0).resolve(Object.class)) + .isEqualTo(String.class); + } + } + + interface MyGeneric { + void myMethod(T parameter); + } + + static class MyConfiguration { + + @Bean + MyGeneric foo() { + return (parameter) -> {}; + } + } +}