From 17daa8c97946c43dabd1bac5338d7b934032b5c2 Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Tue, 1 Aug 2023 16:10:21 +0200 Subject: [PATCH] Hacking. --- .../externalize/ExternalizationCallback.java | 26 +++++++++ .../modulith/events/config/FooTest.java | 56 +++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 spring-modulith-events/spring-modulith-events-api/src/main/java/org/springframework/modulith/events/externalize/ExternalizationCallback.java create mode 100644 spring-modulith-events/spring-modulith-events-core/src/test/java/org/springframework/modulith/events/config/FooTest.java 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 00000000..9da3fd97 --- /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 00000000..47388d2e --- /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) -> {}; + } + } +}