Skip to content

Commit 4c12293

Browse files
committed
fixed isAtLeastVersion
1 parent bc720a4 commit 4c12293

File tree

6 files changed

+82
-9
lines changed

6 files changed

+82
-9
lines changed

src/test/java/com/arangodb/ArangoDBTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.arangodb.entity.*;
2424
import com.arangodb.model.*;
2525
import com.arangodb.model.LogOptions.SortOrder;
26+
import com.arangodb.util.TestUtils;
2627
import com.arangodb.velocypack.exception.VPackException;
2728
import com.arangodb.velocystream.Request;
2829
import com.arangodb.velocystream.RequestType;
@@ -101,8 +102,7 @@ private boolean isCluster() {
101102
}
102103

103104
private boolean isAtLeastVersion(final int major, final int minor) {
104-
final String[] split = arangoDB.getVersion().getVersion().split("\\.");
105-
return Integer.parseInt(split[0]) >= major && Integer.parseInt(split[1]) >= minor;
105+
return TestUtils.isAtLeastVersion(arangoDB.getVersion().getVersion(), major, minor, 0);
106106
}
107107

108108
@Test

src/test/java/com/arangodb/BaseTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.arangodb.entity.*;
2424
import com.arangodb.model.CollectionCreateOptions;
2525
import com.arangodb.model.GraphCreateOptions;
26+
import com.arangodb.util.TestUtils;
2627
import org.junit.AfterClass;
2728
import org.junit.BeforeClass;
2829
import org.junit.runners.Parameterized.Parameters;
@@ -111,8 +112,11 @@ static String rnd() {
111112
}
112113

113114
boolean isAtLeastVersion(final int major, final int minor) {
114-
final String[] split = arangoDB.getVersion().getVersion().split("\\.");
115-
return Integer.parseInt(split[0]) >= major && Integer.parseInt(split[1]) >= minor;
115+
return isAtLeastVersion(major, minor, 0);
116+
}
117+
118+
boolean isAtLeastVersion(final int major, final int minor, final int patch) {
119+
return TestUtils.isAtLeastVersion(arangoDB.getVersion().getVersion(), major, minor, patch);
116120
}
117121

118122
boolean isStorageEngine(ArangoDBEngine.StorageEngineName name) {

src/test/java/com/arangodb/async/ArangoDBTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ private boolean isCluster() {
6969

7070
private boolean isAtLeastVersion(final int major, final int minor) {
7171
final ArangoDB arangoDB = new ArangoDB.Builder().build();
72-
final String[] split = arangoDB.getVersion().getVersion().split("\\.");
73-
return Integer.parseInt(split[0]) >= major && Integer.parseInt(split[1]) >= minor;
72+
return com.arangodb.util.TestUtils.isAtLeastVersion(arangoDB.getVersion().getVersion(), major,minor,0);
7473
}
7574

7675
@Test

src/test/java/com/arangodb/async/BaseTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ public static void shutdown() throws InterruptedException, ExecutionException {
6666

6767
protected static boolean isAtLeastVersion(final ArangoDBAsync arangoDB, final int major, final int minor)
6868
throws InterruptedException, ExecutionException {
69-
final String[] split = arangoDB.getVersion().get().getVersion().split("\\.");
70-
return Integer.parseInt(split[0]) >= major && Integer.parseInt(split[1]) >= minor;
69+
return com.arangodb.util.TestUtils.isAtLeastVersion(arangoDB.getVersion().get().getVersion(), major, minor, 0);
7170
}
7271

7372
protected boolean isAtLeastVersion(final int major, final int minor) throws InterruptedException, ExecutionException {

src/test/java/com/arangodb/async/TestUtils.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.arangodb.async;/*
1+
/*
22
* DISCLAIMER
33
*
44
* Copyright 2016 ArangoDB GmbH, Cologne, Germany
@@ -19,6 +19,9 @@
1919
*/
2020

2121

22+
package com.arangodb.async;
23+
24+
2225
import org.junit.rules.TestRule;
2326

2427
import java.io.IOException;
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* DISCLAIMER
3+
*
4+
* Copyright 2016 ArangoDB GmbH, Cologne, Germany
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
*/
20+
21+
22+
package com.arangodb.util;
23+
24+
25+
/**
26+
* @author Michele Rastelli
27+
*/
28+
public final class TestUtils {
29+
30+
private TestUtils() {
31+
}
32+
33+
/**
34+
* Parses {@param version} and checks whether it is greater or equal to
35+
* <{@param otherMajor}, {@param otherMinor}, {@param otherPatch}>
36+
* comparing the corresponding version components in lexicographical order.
37+
*
38+
* @param version
39+
* @param otherMajor
40+
* @param otherMinor
41+
* @param otherPatch
42+
*/
43+
public static boolean isAtLeastVersion(final String version, final int otherMajor, final int otherMinor, final int otherPatch) {
44+
String[] parts = version.split("-")[0].split("\\.");
45+
46+
int major = Integer.parseInt(parts[0]);
47+
int minor = Integer.parseInt(parts[1]);
48+
int patch = Integer.parseInt(parts[2]);
49+
50+
int majorComparison = Integer.compare(major, otherMajor);
51+
if (majorComparison != 0) {
52+
return majorComparison > 0;
53+
}
54+
55+
int minorComparison = Integer.compare(minor, otherMinor);
56+
if (minorComparison != 0) {
57+
return minorComparison > 0;
58+
}
59+
60+
int patchComparison = Integer.compare(patch, otherPatch);
61+
if (patchComparison != 0) {
62+
return patchComparison > 0;
63+
}
64+
65+
return true;
66+
}
67+
68+
}

0 commit comments

Comments
 (0)