Skip to content

Broker version parsing - add tests #101

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

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
/.classpath
/.project
/.settings
/.jqwik-database
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think jdtls created this in my env 🤷

5 changes: 3 additions & 2 deletions src/main/java/com/rabbitmq/client/amqp/impl/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,9 @@ static int versionCompare(String str1, String str2) {
}
// compare first non-equal ordinal number
if (i < vals1.length && i < vals2.length) {
int diff = Integer.valueOf(vals1[i]).compareTo(Integer.valueOf(vals2[i]));
return Integer.signum(diff);
Integer val1 = Integer.valueOf(vals1[i]);
Integer val2 = Integer.valueOf(vals2[i]);
return val1.compareTo(val2);
}
// the strings are equal or one string is a substring of the other
// e.g. "1.2.3" = "1.2.3" or "1.2.3" < "1.2.3.4"
Expand Down
36 changes: 36 additions & 0 deletions src/test/java/com/rabbitmq/client/amqp/impl/UtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,40 @@ void checkAnnotationsKO() {
assertThatThrownBy(() -> checkMessageAnnotations(of("x-foo", "bar1", "foo", "bar2")))
.isInstanceOf(IllegalArgumentException.class);
}

@ParameterizedTest
@ValueSource(strings = {
"3.13.6",
"3.13.6.2",
"3.13.6-alpha.0",
"3.13.6~beta-1",
"3.13.6+funky-metadata-1",
"4.0.6",
"4.0.6.9",
"4.0.6-alpha.0",
"4.0.6~beta-1",
"4.0.6+funky-metadata-1"
})
void validateBrokerVersionParsing4AndEarlier(String brokerVersion) {
assertThat(Utils.is4_1_OrMore(brokerVersion)).isFalse();
assertThat(Utils.supportFilterExpressions(brokerVersion)).isFalse();
}

@ParameterizedTest
@ValueSource(strings = {
"4.1.6",
"4.1.6.9",
"4.1.6-alpha.0",
"4.1.6~beta-1",
"4.1.6+funky-metadata-1",
"4.2.6",
"4.2.6.9",
"4.2.6-alpha.0",
"4.2.6~beta-1",
"4.2.6+funky-metadata-1"
})
void validateBrokerVersionParsing41AndLater(String brokerVersion) {
assertThat(Utils.is4_1_OrMore(brokerVersion)).isTrue();
assertThat(Utils.supportFilterExpressions(brokerVersion)).isTrue();
}
}