Skip to content

Commit 5a02996

Browse files
committed
Fix release train version's comparison with other version types
Fixes gh-24782
1 parent c5d4ca9 commit 5a02996

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/ReleaseTrainDependencyVersion.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -48,7 +48,7 @@ private ReleaseTrainDependencyVersion(String releaseTrain, String type, int vers
4848
@Override
4949
public int compareTo(DependencyVersion other) {
5050
if (!(other instanceof ReleaseTrainDependencyVersion)) {
51-
return 0;
51+
return -1;
5252
}
5353
ReleaseTrainDependencyVersion otherReleaseTrain = (ReleaseTrainDependencyVersion) other;
5454
int comparison = this.releaseTrain.compareTo(otherReleaseTrain.releaseTrain);

buildSrc/src/test/java/org/springframework/boot/build/bom/bomr/version/ReleaseTrainDependencyVersionTests.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -92,6 +92,14 @@ void isSameMinorAndNewerThanWhenReleaseTrainIsTheSameAndVersionIsOlderShouldRetu
9292
assertThat(version("Kay-SR6").isSameMinorAndNewerThan(version("Kay-SR7"))).isFalse();
9393
}
9494

95+
@Test
96+
void whenComparedWithADifferentDependencyVersionTypeThenTheResultsAreNonZero() {
97+
ReleaseTrainDependencyVersion dysprosium = ReleaseTrainDependencyVersion.parse("Dysprosium-SR16");
98+
ArtifactVersionDependencyVersion twentyTwenty = ArtifactVersionDependencyVersion.parse("2020.0.0");
99+
assertThat(dysprosium.compareTo(twentyTwenty)).isLessThan(0);
100+
assertThat(twentyTwenty.compareTo(dysprosium)).isGreaterThan(0);
101+
}
102+
95103
private static ReleaseTrainDependencyVersion version(String input) {
96104
return ReleaseTrainDependencyVersion.parse(input);
97105
}

0 commit comments

Comments
 (0)