kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 1dc91f71e2102632893739d1a53d7d0e29a7d016d4418ac30db3f2c7c86cf9b6 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2016-07-05 11:52 -07:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2016-07-05 11:52 -07:00 |
| Parents | e6b964e55287 |
4 files changed
modified driver-core/src/main/java/com/datastax/driver/core/VersionNumber.java +13 −14
| @@ -60,7 +60,7 @@ | ||
| 60 | 60 | * The version string should have primarily the form X.Y.Z to which can be appended |
| 61 | 61 | * one or more pre-release label after dashes (2.0.1-beta1, 2.1.4-rc1-SNAPSHOT) |
| 62 | 62 | * 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. | |
| 64 | 64 | * |
| 65 | 65 | * @param version the string to parse |
| 66 | 66 | * @return the parsed version number. |
| @@ -139,7 +139,7 @@ | ||
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
| 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. | |
| 143 | 143 | * |
| 144 | 144 | * @return the pre-releases labels. The return list will be {@code null} if the version number |
| 145 | 145 | * doesn't have one. |
| @@ -217,19 +217,18 @@ | ||
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | @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)) | |
| 222 | 224 | 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); | |
| 233 | 232 | } |
| 234 | 233 | |
| 235 | 234 | @Override |
modified driver-core/src/test/java/com/datastax/driver/core/Assertions.java +3 −0
| @@ -84,4 +84,7 @@ | ||
| 84 | 84 | return new MaterializedViewMetadataAssert(view); |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | + public static VersionNumberAssert assertThat(VersionNumber actual) { | |
| 88 | + return new VersionNumberAssert(actual); | |
| 89 | + } | |
| 87 | 90 | } |
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 −38
| @@ -15,49 +15,90 @@ | ||
| 15 | 15 | */ |
| 16 | 16 | package com.datastax.driver.core; |
| 17 | 17 | |
| 18 | -import java.util.Arrays; | |
| 19 | -import java.util.List; | |
| 20 | - | |
| 21 | 18 | import org.testng.annotations.Test; |
| 22 | 19 | |
| 23 | -import static org.testng.Assert.assertEquals; | |
| 24 | -import static org.testng.Assert.assertNull; | |
| 20 | +import static com.datastax.driver.core.Assertions.assertThat; | |
| 25 | 21 | |
| 26 | 22 | public class VersionNumberTest { |
| 27 | 23 | |
| 28 | 24 | @Test(groups = "unit") |
| 29 | - public void versionNumberTest() { | |
| 30 | - | |
| 31 | - String[] versions = new String[]{ | |
| 32 | - "1.2.0", | |
| 33 | - "2.0.0", | |
| 34 | - "2.0.0-beta1", | |
| 35 | - "2.0.0-beta1-SNAPSHOT", | |
| 36 | - "2.0.0-beta1-SNAPSHOT+abc01", | |
| 37 | - "2.0.0.22" // DSE | |
| 38 | - }; | |
| 39 | - | |
| 40 | - VersionNumber[] numbers = new VersionNumber[versions.length]; | |
| 41 | - for (int i = 0; i < versions.length; i++) | |
| 42 | - numbers[i] = VersionNumber.parse(versions[i]); | |
| 43 | - | |
| 44 | - for (int i = 0; i < versions.length; i++) | |
| 45 | - assertEquals(numbers[i].toString(), versions[i]); | |
| 46 | - | |
| 47 | - assertEquals(numbers[0].compareTo(numbers[1]), -1); | |
| 48 | - assertEquals(numbers[1].compareTo(numbers[2]), 1); | |
| 49 | - assertEquals(numbers[2].compareTo(numbers[3]), -1); | |
| 50 | - assertEquals(numbers[3].compareTo(numbers[4]), 0); | |
| 51 | - assertEquals(numbers[1].compareTo(numbers[5]), -1); | |
| 52 | - | |
| 53 | - VersionNumber deb = VersionNumber.parse("2.0.0~beta1"); | |
| 54 | - assertEquals(deb, numbers[2]); | |
| 55 | - | |
| 56 | - VersionNumber shorter = VersionNumber.parse("2.0"); | |
| 57 | - assertEquals(shorter, numbers[1]); | |
| 58 | - | |
| 59 | - List<String> preReleaseLabels = Arrays.asList("beta1", "SNAPSHOT"); | |
| 60 | - assertEquals(numbers[3].getPreReleaseLabels(), preReleaseLabels); | |
| 61 | - assertNull(numbers[0].getPreReleaseLabels()); | |
| 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); | |
| 62 | 103 | } |
| 63 | 104 | } |