Elffuss BraidHub

kikocis/java-driver public

Merge branch 'java1160' into 3.0.x
Changeset48c2cd67580853d74115a1701d5448ef1b0612f3b4f826392b248ce71ccb3876
Authorolim7t <omichallat+github@gmail.com> · 2016-07-05 11:55 -07:00
Committerolim7t <omichallat+github@gmail.com> · 2016-07-05 11:55 -07:00
Parentse35412f5ec60, 1dc91f71e210

Browse the files at this changeset

5 files changed

modified changelog/README.md +1 −0
@@ -16,6 +16,7 @@
1616 - [improvement] JAVA-1200: Upgrade LZ4 to 1.3.0.
1717 - [bug] JAVA-1232: Fix NPE in IdempotenceAwareRetryPolicy.isIdempotent.
1818 - [improvement] JAVA-1227: Document "SELECT *" issue with prepared statement.
19+- [bug] JAVA-1160: Fix NPE in VersionNumber.getPreReleaseLabels().
1920
2021
2122 ### 3.0.2
modified driver-core/src/main/java/com/datastax/driver/core/VersionNumber.java +14 −15
@@ -60,7 +60,7 @@
6060 * The version string should have primarily the form X.Y.Z to which can be appended
6161 * one or more pre-release label after dashes (2.0.1-beta1, 2.1.4-rc1-SNAPSHOT)
6262 * and an optional build label (2.1.0-beta1+a20ba.sha). Out of convenience, the
63- * "patch" version number, Z, can be ommitted, in which case it is assumed to be 0.
63+ * "patch" version number, Z, can be omitted, in which case it is assumed to be 0.
6464 *
6565 * @param version the string to parse
6666 * @return the parsed version number.
@@ -139,13 +139,13 @@
139139 }
140140
141141 /**
142- * The pre-release labels if relevants, i.e. label1 and label2 in X.Y.Z-label1-lable2.
142+ * The pre-release labels if relevant, i.e. label1 and label2 in X.Y.Z-label1-lable2.
143143 *
144144 * @return the pre-releases labels. The return list will be {@code null} if the version number
145145 * doesn't have one.
146146 */
147147 public List<String> getPreReleaseLabels() {
148- return Collections.unmodifiableList(Arrays.asList(preReleases));
148+ return preReleases == null ? null : Collections.unmodifiableList(Arrays.asList(preReleases));
149149 }
150150
151151 /**
@@ -217,19 +217,18 @@
217217 }
218218
219219 @Override
220- public boolean equals(Object o) {
221- if (!(o instanceof VersionNumber))
220+ public boolean equals(Object other) {
221+ if (other == this)
222+ return true;
223+ if (!(other instanceof VersionNumber))
222224 return false;
223- VersionNumber that = (VersionNumber) o;
224- if (major != that.major || minor != that.minor || patch != that.patch)
225- return false;
226-
227- return major == that.major
228- && minor == that.minor
229- && patch == that.patch
230- && dsePatch == that.dsePatch
231- && (preReleases == null ? that.preReleases == null : Arrays.equals(preReleases, that.preReleases))
232- && Objects.equal(build, that.build);
225+ VersionNumber that = (VersionNumber) other;
226+ return this.major == that.major
227+ && this.minor == that.minor
228+ && this.patch == that.patch
229+ && this.dsePatch == that.dsePatch
230+ && (this.preReleases == null ? that.preReleases == null : Arrays.equals(this.preReleases, that.preReleases))
231+ && Objects.equal(this.build, that.build);
233232 }
234233
235234 @Override
modified driver-core/src/test/java/com/datastax/driver/core/Assertions.java +3 −0
@@ -84,4 +84,7 @@
8484 return new MaterializedViewMetadataAssert(view);
8585 }
8686
87+ public static VersionNumberAssert assertThat(VersionNumber actual) {
88+ return new VersionNumberAssert(actual);
89+ }
8790 }
added driver-core/src/test/java/com/datastax/driver/core/VersionNumberAssert.java +64 −0
@@ -0,0 +1,64 @@
1+/*
2+ * Copyright (C) 2012-2015 DataStax Inc.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+package com.datastax.driver.core;
17+
18+import org.assertj.core.api.AbstractComparableAssert;
19+
20+import static com.datastax.driver.core.Assertions.assertThat;
21+
22+public class VersionNumberAssert extends AbstractComparableAssert<VersionNumberAssert, VersionNumber> {
23+
24+ public VersionNumberAssert(VersionNumber actual) {
25+ super(actual, VersionNumberAssert.class);
26+ }
27+
28+ public VersionNumberAssert hasMajorMinorPatch(int major, int minor, int patch) {
29+ assertThat(actual.getMajor()).isEqualTo(major);
30+ assertThat(actual.getMinor()).isEqualTo(minor);
31+ assertThat(actual.getPatch()).isEqualTo(patch);
32+ return this;
33+ }
34+
35+ public VersionNumberAssert hasDsePatch(int dsePatch) {
36+ assertThat(actual.getDSEPatch()).isEqualTo(dsePatch);
37+ return this;
38+ }
39+
40+ public VersionNumberAssert hasPreReleaseLabels(String... labels) {
41+ assertThat(actual.getPreReleaseLabels()).containsExactly(labels);
42+ return this;
43+ }
44+
45+ public VersionNumberAssert hasNoPreReleaseLabels() {
46+ assertThat(actual.getPreReleaseLabels()).isNull();
47+ return this;
48+ }
49+
50+ public VersionNumberAssert hasBuildLabel(String label) {
51+ assertThat(actual.getBuildLabel()).isEqualTo(label);
52+ return this;
53+ }
54+
55+ public VersionNumberAssert hasNextStable(String version) {
56+ assertThat(actual.nextStable()).isEqualTo(VersionNumber.parse(version));
57+ return this;
58+ }
59+
60+ public VersionNumberAssert hasToString(String string) {
61+ assertThat(actual.toString()).isEqualTo(string);
62+ return this;
63+ }
64+}
modified driver-core/src/test/java/com/datastax/driver/core/VersionNumberTest.java +79 −30
@@ -17,39 +17,88 @@
1717
1818 import org.testng.annotations.Test;
1919
20-import static org.testng.Assert.assertEquals;
20+import static com.datastax.driver.core.Assertions.assertThat;
2121
2222 public class VersionNumberTest {
2323
2424 @Test(groups = "unit")
25- public void versionNumberTest() {
26-
27- String[] versions = new String[]{
28- "1.2.0",
29- "2.0.0",
30- "2.0.0-beta1",
31- "2.0.0-beta1-SNAPSHOT",
32- "2.0.0-beta1-SNAPSHOT+abc01",
33- "2.0.0.22" // DSE
34- };
35-
36- VersionNumber[] numbers = new VersionNumber[versions.length];
37- for (int i = 0; i < versions.length; i++)
38- numbers[i] = VersionNumber.parse(versions[i]);
39-
40- for (int i = 0; i < versions.length; i++)
41- assertEquals(numbers[i].toString(), versions[i]);
42-
43- assertEquals(numbers[0].compareTo(numbers[1]), -1);
44- assertEquals(numbers[1].compareTo(numbers[2]), 1);
45- assertEquals(numbers[2].compareTo(numbers[3]), -1);
46- assertEquals(numbers[3].compareTo(numbers[4]), 0);
47- assertEquals(numbers[1].compareTo(numbers[5]), -1);
48-
49- VersionNumber deb = VersionNumber.parse("2.0.0~beta1");
50- assertEquals(deb, numbers[2]);
51-
52- VersionNumber shorter = VersionNumber.parse("2.0");
53- assertEquals(shorter, numbers[1]);
25+ public void should_parse_release_version() {
26+ assertThat(VersionNumber.parse("1.2.19"))
27+ .hasMajorMinorPatch(1, 2, 19)
28+ .hasDsePatch(-1)
29+ .hasNoPreReleaseLabels()
30+ .hasBuildLabel(null)
31+ .hasNextStable("1.2.19")
32+ .hasToString("1.2.19");
33+ }
34+
35+ @Test(groups = "unit")
36+ public void should_parse_release_without_patch() {
37+ assertThat(VersionNumber.parse("1.2"))
38+ .hasMajorMinorPatch(1, 2, 0);
39+ }
40+
41+ @Test(groups = "unit")
42+ public void should_parse_pre_release_version() {
43+ assertThat(VersionNumber.parse("1.2.0-beta1-SNAPSHOT"))
44+ .hasMajorMinorPatch(1, 2, 0)
45+ .hasDsePatch(-1)
46+ .hasPreReleaseLabels("beta1", "SNAPSHOT")
47+ .hasBuildLabel(null)
48+ .hasToString("1.2.0-beta1-SNAPSHOT")
49+ .hasNextStable("1.2.0");
50+ }
51+
52+ @Test(groups = "unit")
53+ public void should_allow_tilde_as_first_pre_release_delimiter() {
54+ assertThat(VersionNumber.parse("1.2.0~beta1-SNAPSHOT"))
55+ .hasMajorMinorPatch(1, 2, 0)
56+ .hasDsePatch(-1)
57+ .hasPreReleaseLabels("beta1", "SNAPSHOT")
58+ .hasBuildLabel(null)
59+ .hasToString("1.2.0-beta1-SNAPSHOT")
60+ .hasNextStable("1.2.0");
61+ }
62+
63+ @Test(groups = "unit")
64+ public void should_parse_dse_patch() {
65+ assertThat(VersionNumber.parse("1.2.19.2-SNAPSHOT"))
66+ .hasMajorMinorPatch(1, 2, 19)
67+ .hasDsePatch(2)
68+ .hasToString("1.2.19.2-SNAPSHOT")
69+ .hasNextStable("1.2.19.2");
70+ }
71+
72+ @Test(groups = "unit")
73+ public void should_order_versions() {
74+ // by component
75+ assertOrder("1.2.0", "2.0.0", -1);
76+ assertOrder("2.0.0", "2.1.0", -1);
77+ assertOrder("2.0.1", "2.0.2", -1);
78+ assertOrder("2.0.1.1", "2.0.1.2", -1);
79+
80+ // shortened vs. longer version
81+ assertOrder("2.0", "2.0.0", 0);
82+ assertOrder("2.0", "2.0.1", -1);
83+
84+ // any DSE version is higher than no DSE version
85+ assertOrder("2.0.0", "2.0.0.0", -1);
86+ assertOrder("2.0.0", "2.0.0.1", -1);
87+
88+ // pre-release vs. release
89+ assertOrder("2.0.0-beta1", "2.0.0", -1);
90+ assertOrder("2.0.0-SNAPSHOT", "2.0.0", -1);
91+ assertOrder("2.0.0-beta1-SNAPSHOT", "2.0.0", -1);
92+
93+ // pre-release vs. pre-release
94+ assertOrder("2.0.0-a-b-c", "2.0.0-a-b-d", -1);
95+ assertOrder("2.0.0-a-b-c", "2.0.0-a-b-c-d", -1);
96+
97+ // build number ignored
98+ assertOrder("2.0.0+build01", "2.0.0+build02", 0);
99+ }
100+
101+ private void assertOrder(String version1, String version2, int expected) {
102+ assertThat(VersionNumber.parse(version1).compareTo(VersionNumber.parse(version2))).isEqualTo(expected);
54103 }
55104 }