Skip to content

Commit

Permalink
refactor(core): simplify OperationsInClassScanner interface (#1120)
Browse files Browse the repository at this point in the history
Possible because Operation@operationId added.
Continuation of 0eaa374
  • Loading branch information
timonback authored Dec 13, 2024
1 parent 4861d50 commit 399e2e1
Show file tree
Hide file tree
Showing 16 changed files with 69 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public class DefaultOperationsService implements OperationsService {
*/
@Override
public Map<String, Operation> findOperations() {
List<Map.Entry<String, Operation>> foundOperations = new ArrayList<>();
List<Operation> foundOperations = new ArrayList<>();

for (OperationsScanner scanner : operationScanners) {
try {
Map<String, Operation> channels = scanner.scan();
foundOperations.addAll(channels.entrySet());
foundOperations.addAll(channels.values());
} catch (Exception e) {
log.error("An error was encountered during operation scanning with {}: {}", scanner, e.getMessage(), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ private OperationMerger() {}
* If an operation is null, the next non-null operation is used
* Messages within operations are merged
*
* @param operationEntries Ordered pairs of operation name to Operation
* @param operations Ordered pairs of operation name to Operation
* @return A map of operationId to a single Operation
*/
public static Map<String, Operation> mergeOperations(List<Map.Entry<String, Operation>> operationEntries) {
public static Map<String, Operation> mergeOperations(List<Operation> operations) {
Map<String, Operation> mergedOperations = new HashMap<>();

for (Map.Entry<String, Operation> entry : operationEntries) {
if (!mergedOperations.containsKey(entry.getKey())) {
mergedOperations.put(entry.getKey(), entry.getValue());
for (Operation operation : operations) {
if (!mergedOperations.containsKey(operation.getOperationId())) {
mergedOperations.put(operation.getOperationId(), operation);
} else {
Operation operation = mergeOperation(mergedOperations.get(entry.getKey()), entry.getValue());
mergedOperations.put(entry.getKey(), operation);
Operation mergedOperation = mergeOperation(mergedOperations.get(operation.getOperationId()), operation);
mergedOperations.put(operation.getOperationId(), mergedOperation);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@

import io.github.springwolf.asyncapi.v3.model.operation.Operation;

import java.util.Map;
import java.util.stream.Stream;

public interface OperationsInClassScanner {
Stream<Map.Entry<String, Operation>> scan(Class<?> clazz);
Stream<Operation> scan(Class<?> clazz);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public class OperationsInClassScannerAdapter implements OperationsScanner {
public Map<String, Operation> scan() {
Set<Class<?>> components = classScanner.scan();

List<Map.Entry<String, Operation>> operations = mapToOperations(components);
List<Operation> operations = mapToOperations(components);

return OperationMerger.mergeOperations(operations);
}

private List<Map.Entry<String, Operation>> mapToOperations(Set<Class<?>> components) {
private List<Operation> mapToOperations(Set<Class<?>> components) {
return components.stream().flatMap(classProcessor::scan).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand All @@ -32,7 +31,7 @@ public class AsyncAnnotationClassLevelOperationsScanner<ClassAnnotation extends
private final List<OperationCustomizer> customizers;

@Override
public Stream<Map.Entry<String, Operation>> scan(Class<?> clazz) {
public Stream<Operation> scan(Class<?> clazz) {
Set<MethodAndAnnotation<ClassAnnotation>> methodAndAnnotation = AnnotationScannerUtil.findAnnotatedMethods(
clazz, classAnnotationClass, AllMethods.class, (cl, m) -> {
ClassAnnotation classAnnotation =
Expand All @@ -48,7 +47,7 @@ public Stream<Map.Entry<String, Operation>> scan(Class<?> clazz) {
return mapClassToOperation(clazz, methodAndAnnotation);
}

private Stream<Map.Entry<String, Operation>> mapClassToOperation(
private Stream<Operation> mapClassToOperation(
Class<?> component, Set<MethodAndAnnotation<ClassAnnotation>> annotatedMethods) {
ClassAnnotation classAnnotation = AnnotationUtil.findFirstAnnotationOrThrow(classAnnotationClass, component);
AsyncOperation asyncOperation = asyncAnnotationProvider.getAsyncOperation(classAnnotation);
Expand All @@ -58,6 +57,6 @@ private Stream<Map.Entry<String, Operation>> mapClassToOperation(
Operation operation = asyncAnnotationOperationsService.buildOperation(asyncOperation, methods);
annotatedMethods.forEach(
method -> customizers.forEach(customizer -> customizer.customize(operation, method.method())));
return Stream.of(Map.entry(operation.getOperationId(), operation));
return Stream.of(operation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import java.lang.annotation.Annotation;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;

Expand All @@ -27,19 +26,18 @@ public class AsyncAnnotationMethodLevelOperationsScanner<MethodAnnotation extend
private final List<OperationCustomizer> customizers;

@Override
public Stream<Map.Entry<String, Operation>> scan(Class<?> clazz) {
public Stream<Operation> scan(Class<?> clazz) {
return AnnotationScannerUtil.findAnnotatedMethods(clazz, this.asyncAnnotationProvider.getAnnotation())
.map(this::mapMethodToOperation);
}

private Map.Entry<String, Operation> mapMethodToOperation(
MethodAndAnnotation<MethodAnnotation> methodAndAnnotation) {
private Operation mapMethodToOperation(MethodAndAnnotation<MethodAnnotation> methodAndAnnotation) {
AsyncOperation operationAnnotation =
this.asyncAnnotationProvider.getAsyncOperation(methodAndAnnotation.annotation());

Operation operation = asyncAnnotationOperationService.buildOperation(
operationAnnotation, Set.of(methodAndAnnotation.method()));
customizers.forEach(customizer -> customizer.customize(operation, methodAndAnnotation.method()));
return Map.entry(operation.getOperationId(), operation);
return operation;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand All @@ -30,12 +29,12 @@ public class SpringAnnotationClassLevelOperationsScanner<
private final List<OperationCustomizer> customizers;

@Override
public Stream<Map.Entry<String, Operation>> scan(Class<?> clazz) {
public Stream<Operation> scan(Class<?> clazz) {
return AnnotationScannerUtil.findAnnotatedMethods(
clazz, classAnnotationClass, methodAnnotationClass, this::mapClassToOperation);
}

private Stream<Map.Entry<String, Operation>> mapClassToOperation(
private Stream<Operation> mapClassToOperation(
Class<?> component, Set<MethodAndAnnotation<MethodAnnotation>> annotatedMethods) {
ClassAnnotation classAnnotation = AnnotationUtil.findFirstAnnotationOrThrow(classAnnotationClass, component);

Expand All @@ -44,6 +43,6 @@ private Stream<Map.Entry<String, Operation>> mapClassToOperation(
Operation operation = springAnnotationOperationsService.buildOperation(classAnnotation, component, methods);
annotatedMethods.forEach(
method -> customizers.forEach(customizer -> customizer.customize(operation, method.method())));
return Stream.of(Map.entry(operation.getOperationId(), operation));
return Stream.of(operation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import java.lang.annotation.Annotation;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

@Slf4j
Expand All @@ -30,17 +29,17 @@ public class SpringAnnotationMethodLevelOperationsScanner<MethodAnnotation exten
private final List<OperationCustomizer> customizers;

@Override
public Stream<Map.Entry<String, Operation>> scan(Class<?> clazz) {
public Stream<Operation> scan(Class<?> clazz) {
return AnnotationScannerUtil.findAnnotatedMethods(clazz, methodAnnotationClass)
.map(this::mapMethodToOperation);
}

private Map.Entry<String, Operation> mapMethodToOperation(MethodAndAnnotation<MethodAnnotation> method) {
private Operation mapMethodToOperation(MethodAndAnnotation<MethodAnnotation> method) {
PayloadSchemaObject payloadSchema = payloadMethodParameterService.extractSchema(method.method());
SchemaObject headerSchema = headerClassExtractor.extractHeader(method.method(), payloadSchema);

Operation operation = springAnnotationOperationService.buildOperation(method, payloadSchema, headerSchema);
customizers.forEach(customizer -> customizer.customize(operation, method.method()));
return Map.entry(operation.getOperationId(), operation);
return operation;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ void getOperations() {
static class SimpleOperationScanner implements OperationsScanner {
@Override
public Map<String, Operation> scan() {
return Map.of(
"foo",
Operation.builder()
.channel(ChannelReference.fromChannel("foo"))
.action(OperationAction.RECEIVE)
.build());
Operation operation = Operation.builder()
.operationId("foo")
.channel(ChannelReference.fromChannel("foo"))
.action(OperationAction.RECEIVE)
.build();

return Map.of(operation.getOperationId(), operation);
}
}

Expand All @@ -61,26 +62,28 @@ static class SameTopic {
@Component
static class SendOperationScanner implements OperationsScanner {
static final Operation sentOperation = Operation.builder()
.operationId("send")
.channel(ChannelReference.fromChannel(topicName))
.action(OperationAction.SEND)
.build();

@Override
public Map<String, Operation> scan() {
return Map.of("send", sentOperation);
return Map.of(sentOperation.getOperationId(), sentOperation);
}
}

@Component
static class ReceiveOperationScanner implements OperationsScanner {
static final Operation receiveOperation = Operation.builder()
.operationId("receive")
.channel(ChannelReference.fromChannel(topicName))
.action(OperationAction.RECEIVE)
.build();

@Override
public Map<String, Operation> scan() {
return Map.of("receive", receiveOperation);
return Map.of(receiveOperation.getOperationId(), receiveOperation);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ class OperationMergerTest {
@Test
void shouldNotMergeDifferentoperationIds() {
// given
String operationId1 = "operation1";
String operationId2 = "operation2";
Operation publisherOperation = Operation.builder().build();
Operation subscriberOperation = Operation.builder().build();
Operation publisherOperation =
Operation.builder().operationId("operation1").build();
Operation subscriberOperation =
Operation.builder().operationId("operation2").build();

// when
Map<String, Operation> mergedOperations = OperationMerger.mergeOperations(Arrays.asList(
Map.entry(operationId1, publisherOperation), Map.entry(operationId2, subscriberOperation)));
Map<String, Operation> mergedOperations =
OperationMerger.mergeOperations(Arrays.asList(publisherOperation, subscriberOperation));

// then
assertThat(mergedOperations).hasSize(2);
Expand All @@ -49,9 +49,8 @@ void shouldMergeEqualOperationIdsIntoOneOperation() {
.build();

// when
Map<String, Operation> mergedOperations = OperationMerger.mergeOperations(Arrays.asList(
Map.entry(publishOperation.getOperationId(), publishOperation),
Map.entry(subscribeOperation.getOperationId(), subscribeOperation)));
Map<String, Operation> mergedOperations =
OperationMerger.mergeOperations(Arrays.asList(publishOperation, subscribeOperation));

// then
assertThat(mergedOperations).hasSize(1);
Expand All @@ -71,9 +70,8 @@ void shouldUseFirstOperationFound() {
.build();

// when
Map<String, Operation> mergedOperations = OperationMerger.mergeOperations(Arrays.asList(
Map.entry(senderOperation.getOperationId(), senderOperation),
Map.entry(receiverOperation.getOperationId(), receiverOperation)));
Map<String, Operation> mergedOperations =
OperationMerger.mergeOperations(Arrays.asList(senderOperation, receiverOperation));

// then
assertThat(mergedOperations).hasSize(1).hasEntrySatisfying(operationId, it -> {
Expand Down Expand Up @@ -122,10 +120,8 @@ void shouldMergeDifferentMessageForSameOperation() {
.build();

// when
Map<String, Operation> mergedOperations = OperationMerger.mergeOperations(List.of(
Map.entry(senderOperation1.getOperationId(), senderOperation1),
Map.entry(senderOperation2.getOperationId(), senderOperation2),
Map.entry(senderOperation3.getOperationId(), senderOperation3)));
Map<String, Operation> mergedOperations =
OperationMerger.mergeOperations(List.of(senderOperation1, senderOperation2, senderOperation3));

// then expectedMessage only includes message1 and message2.
// Message3 is not included as it is identical in terms of payload type (Message#name) to message 2
Expand Down Expand Up @@ -174,17 +170,17 @@ void shouldUseOtherMessageIfFirstMessageIsMissingForOperations() {
.build();
Operation publishOperation1 = Operation.builder()
.action(OperationAction.SEND)
.title("publisher1")
.operationId("publisher1")
.build();
Operation publishOperation2 = Operation.builder()
.action(OperationAction.SEND)
.title("publisher2")
.operationId("publisher1")
.messages(List.of(MessageReference.toChannelMessage(channelId, message2)))
.build();

// when
Map<String, Operation> mergedOperations = OperationMerger.mergeOperations(
Arrays.asList(Map.entry("publisher1", publishOperation1), Map.entry("publisher1", publishOperation2)));
Map<String, Operation> mergedOperations =
OperationMerger.mergeOperations(Arrays.asList(publishOperation1, publishOperation2));
// then expectedMessage message2
var expectedMessage = MessageReference.toChannelMessage(channelId, message2);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,32 @@ void noClassFoundTest() {
void processClassTest() {
// given
when(classScanner.scan()).thenReturn(Set.of(String.class));
Map.Entry<String, Operation> operation1 =
Map.entry("operation1", Operation.builder().build());
Map.Entry<String, Operation> operation2 =
Map.entry("operation2", Operation.builder().build());
Operation operation1 = Operation.builder().operationId("operation1").build();
Operation operation2 = Operation.builder().operationId("operation2").build();
when(classProcessor.scan(any())).thenReturn(Stream.of(operation1, operation2));

// when
Map<String, Operation> operations = operationsInClassScannerAdapter.scan();

// then
assertThat(operations).containsExactly(operation2, operation1);
assertThat(operations).containsExactlyEntriesOf(Map.of("operation1", operation1, "operation2", operation2));

Check failure on line 46 in springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/operations/OperationsInClassScannerAdapterTest.java

View workflow job for this annotation

GitHub Actions / test-core

OperationsInClassScannerAdapterTest.processClassTest()

java.lang.AssertionError: Actual and expected have the same elements but not in the same order, at index 0 actual element was: "operation2"=Operation(operationId=operation2, action=null, channel=null, title=null, summary=null, description=null, security=null, tags=null, externalDocs=null, bindings=null, traits=null, messages=null, reply=null) whereas expected element was: "operation1"=Operation(operationId=operation1, action=null, channel=null, title=null, summary=null, description=null, security=null, tags=null, externalDocs=null, bindings=null, traits=null, messages=null, reply=null)
Raw output
java.lang.AssertionError: 
Actual and expected have the same elements but not in the same order, at index 0 actual element was:
  "operation2"=Operation(operationId=operation2, action=null, channel=null, title=null, summary=null, description=null, security=null, tags=null, externalDocs=null, bindings=null, traits=null, messages=null, reply=null)
whereas expected element was:
  "operation1"=Operation(operationId=operation1, action=null, channel=null, title=null, summary=null, description=null, security=null, tags=null, externalDocs=null, bindings=null, traits=null, messages=null, reply=null)

	at io.github.springwolf.core.asyncapi.scanners.operations.OperationsInClassScannerAdapterTest.processClassTest(OperationsInClassScannerAdapterTest.java:46)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:569)
	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:767)
	at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
	at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:92)
	at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:86)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$8(TestMethodTestDescriptor.java:217)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:213)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:138)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:68)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:156)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:146)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:144)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:143)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:100)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:160)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:146)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:144)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:143)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:100)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:160)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:146)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:144)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:143)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:100)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:107)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
	at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:124)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:99)
	at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:94)
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:63)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:92)
	at jdk.proxy1/jdk.proxy1.$Proxy4.stop(Unknown Source)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker$3.run(TestWorker.java:200)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:132)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:103)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:63)
	at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:121)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:71)
	at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
	at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)
}

@Test
void sameOperationsAreMergedTest() {
// given
when(classScanner.scan()).thenReturn(Set.of(String.class));
Map.Entry<String, Operation> operation1 =
Map.entry("operation1", Operation.builder().build());
Map.Entry<String, Operation> operation2 =
Map.entry("operation1", Operation.builder().build());
Operation operation1 =
Operation.builder().operationId("operation1").description("op1").build();
Operation operation2 =
Operation.builder().operationId("operation1").description("op2").build();
when(classProcessor.scan(any())).thenReturn(Stream.of(operation1, operation2));

// when
Map<String, Operation> operations = operationsInClassScannerAdapter.scan();

// then
assertThat(operations)
.containsExactly(Map.entry("operation1", Operation.builder().build()));
assertThat(operations).hasSize(1);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.lang.annotation.RetentionPolicy;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -59,7 +60,7 @@ void scan() {
// when
Map<String, Operation> actualOperations = operationsScanner
.scan(ClassWithListenerAnnotation.class)
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
.collect(Collectors.toMap(Operation::getOperationId, Function.identity()));

// then
assertThat(actualOperations).hasSize(1);
Expand Down
Loading

0 comments on commit 399e2e1

Please sign in to comment.