Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Sort Messages references #681

Merged
merged 2 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: Sort Messages references
Message references are now alphabetically sorted.

When an Operation has multiple messages, the resulting order depends on how the classes are parsed. This can produce slightly different results in different machines, making problematic the comparison for changes.
  • Loading branch information
ctasada committed Apr 1, 2024
commit 8acc3e6fc6c0207988d302205b31c1780e9c898c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.github.springwolf.asyncapi.v3.model.operation.Operation;

import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -62,6 +63,9 @@ private static List<MessageReference> mergeMessageReferences(
if (otherMessages != null) {
messageReferences.addAll(otherMessages);
}
return messageReferences.stream().toList();

return messageReferences.stream()
.sorted(Comparator.comparing(MessageReference::getRef))
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void shouldMergeDifferentMessageForSameOperation() {
// 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
assertThat(mergedOperations).hasSize(1).hasEntrySatisfying(operationId, it -> {
assertThat(it.getMessages()).containsExactlyInAnyOrder(messageRef1, messageRef2);
assertThat(it.getMessages()).containsExactly(messageRef2, messageRef1);
});
}

Expand Down
Loading