Skip to content

Commit cd1d0f1

Browse files
committed
Do not use utility classes from dependencies
We have been avoiding this previously and we need to continue keeping out of any unnecessary dependencies in the code, especially we should not use any internal classes and transitive dependencies of the dependencies, because it easily breaks dependency updates.
1 parent 3ddf1ea commit cd1d0f1

5 files changed

Lines changed: 35 additions & 15 deletions

File tree

src/test/java/io/tarantool/driver/TarantoolUtils.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.tarantool.driver;
22

33
import io.tarantool.driver.utils.Assert;
4-
import org.testcontainers.shaded.org.apache.commons.lang3.StringUtils;
54

65
import java.util.Arrays;
76
import java.util.Collections;
@@ -18,13 +17,14 @@ private TarantoolUtils() {
1817
public static boolean versionGreaterOrEqualThen(String tarantoolVersion) {
1918
Assert.notNull(tarantoolVersion, "tarantoolVersion must not be null");
2019
String tarantoolCiVersion = java.lang.System.getenv(TARANTOOL_VERSION);
21-
if (StringUtils.isEmpty(tarantoolCiVersion)) {
20+
if (tarantoolCiVersion == null || tarantoolCiVersion.isEmpty()) {
2221
return true;
2322
}
2423
TarantoolVersion ciVersion = new TarantoolVersion(tarantoolCiVersion);
2524
TarantoolVersion version = new TarantoolVersion(tarantoolVersion);
2625
return ciVersion.getMajor() >= version.getMajor() &&
2726
ciVersion.getMinor() >= version.getMinor();
27+
2828
}
2929

3030
public static boolean versionWithUUID() {
@@ -44,7 +44,8 @@ public static class TarantoolVersion {
4444
private Integer minor;
4545

4646
public TarantoolVersion(String stringVersion) {
47-
List<String> majorMinor = StringUtils.isEmpty(stringVersion) ? Collections.emptyList() :
47+
List<String> majorMinor = stringVersion == null || stringVersion.isEmpty() ?
48+
Collections.emptyList() :
4849
Arrays.stream(stringVersion.split("\\."))
4950
.collect(Collectors.toList());
5051
if (majorMinor.size() >= 1) {

src/test/java/io/tarantool/driver/integration/ConnectionIT.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.slf4j.Logger;
2323
import org.slf4j.LoggerFactory;
2424
import org.testcontainers.junit.jupiter.Testcontainers;
25-
import org.testcontainers.shaded.com.fasterxml.jackson.databind.util.ClassUtil;
2625

2726
import java.util.ArrayList;
2827
import java.util.List;
@@ -364,6 +363,6 @@ public void test_AddressProviderReturnsNull_shouldThrowTarantoolClientException(
364363

365364
// then
366365
TarantoolClientException exception = assertThrows(TarantoolClientException.class, client::getVersion);
367-
assertFalse(ClassUtil.getRootCause(exception) instanceof NullPointerException);
366+
assertFalse(Utils.getRootCause(exception) instanceof NullPointerException);
368367
}
369368
}

src/test/java/io/tarantool/driver/integration/ConvertersWithClusterClientIT.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@
1313
import org.junit.jupiter.api.BeforeAll;
1414
import org.junit.jupiter.api.Test;
1515
import org.junit.jupiter.api.condition.EnabledIf;
16-
import org.testcontainers.shaded.org.apache.commons.lang3.ArrayUtils;
1716

1817
import java.time.Instant;
1918
import java.util.UUID;
2019

2120
import java.nio.charset.StandardCharsets;
22-
import java.util.Arrays;
2321
import java.util.List;
2422

2523
/**
@@ -87,7 +85,7 @@ public void test_boxSelect_shouldReturnTupleWithInstant() throws Exception {
8785
public void test_boxOperations_shouldWorkWithVarbinary() throws Exception {
8886
//given
8987
byte[] bytes = "hello".getBytes(StandardCharsets.UTF_8);
90-
List<Byte> byteList = Arrays.asList(ArrayUtils.toObject(bytes));
88+
List<Byte> byteList = Utils.convertBytesToByteList(bytes);
9189
client.space("space_with_varbinary")
9290
.insert(tupleFactory.create(1, bytes)).get();
9391

@@ -98,7 +96,7 @@ public void test_boxOperations_shouldWorkWithVarbinary() throws Exception {
9896

9997
//then
10098
byte[] bytesFromTarantool = fields.getByteArray("varbinary_field");
101-
List<Byte> byteListFromTarantool = Arrays.asList(ArrayUtils.toObject(bytesFromTarantool));
99+
List<Byte> byteListFromTarantool = Utils.convertBytesToByteList(bytesFromTarantool);
102100
Assertions.assertEquals(byteList, byteListFromTarantool);
103101
}
104102
}

src/test/java/io/tarantool/driver/integration/ConvertersWithProxyClientIT.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,11 @@
1313
import org.junit.jupiter.api.Disabled;
1414
import org.junit.jupiter.api.Test;
1515
import org.junit.jupiter.api.condition.EnabledIf;
16-
import org.testcontainers.shaded.org.apache.commons.lang3.ArrayUtils;
1716

1817
import java.time.Instant;
1918
import java.util.UUID;
2019

2120
import java.nio.charset.StandardCharsets;
22-
import java.util.Arrays;
2321
import java.util.List;
2422

2523
/**
@@ -89,7 +87,7 @@ public void test_crudSelect_shouldReturnTupleWithInstant() throws Exception {
8987
public void test_crudOperations_shouldWorkWithVarbinary() throws Exception {
9088
//given
9189
byte[] bytes = "hello".getBytes(StandardCharsets.UTF_8);
92-
List<Byte> byteList = Arrays.asList(ArrayUtils.toObject(bytes));
90+
List<Byte> byteList = Utils.convertBytesToByteList(bytes);
9391
client.space("space_with_varbinary")
9492
.insert(tupleFactory.create(1, bytes)).get();
9593

@@ -100,15 +98,15 @@ public void test_crudOperations_shouldWorkWithVarbinary() throws Exception {
10098

10199
//then
102100
byte[] bytesFromTarantool = fields.getByteArray("varbinary_field");
103-
List<Byte> byteListFromTarantool = Arrays.asList(ArrayUtils.toObject(bytesFromTarantool));
101+
List<Byte> byteListFromTarantool = Utils.convertBytesToByteList(bytesFromTarantool);
104102
Assertions.assertEquals(byteList, byteListFromTarantool);
105103
}
106104

107105
@Test
108106
public void test_crudOperations_shouldWorkWithBytesAsString() throws Exception {
109107
//given
110108
byte[] bytes = "hello".getBytes(StandardCharsets.UTF_8);
111-
List<Byte> byteList = Arrays.asList(ArrayUtils.toObject(bytes));
109+
List<Byte> byteList = Utils.convertBytesToByteList(bytes);
112110
client.space("space_with_string")
113111
.insert(tupleFactory.create(1, bytes)).get();
114112

@@ -119,7 +117,7 @@ public void test_crudOperations_shouldWorkWithBytesAsString() throws Exception {
119117

120118
//then
121119
byte[] bytesFromTarantool = fields.getByteArray("string_field");
122-
List<Byte> byteListFromTarantool = Arrays.asList(ArrayUtils.toObject(bytesFromTarantool));
120+
List<Byte> byteListFromTarantool = Utils.convertBytesToByteList(bytesFromTarantool);
123121
Assertions.assertEquals(byteList, byteListFromTarantool);
124122
}
125123
}

src/test/java/io/tarantool/driver/integration/Utils.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import java.util.List;
1616
import java.util.Optional;
1717
import java.util.concurrent.ExecutionException;
18+
import java.util.stream.Collectors;
19+
import java.util.stream.IntStream;
1820

1921
import static org.junit.jupiter.api.Assertions.assertEquals;
2022

@@ -103,4 +105,26 @@ private static long crc32(byte[] data) {
103105
crc32 = Integer.reverse(crc32); // result reflect
104106
return crc32 & 0x00000000ffffffffL; // the unsigned java problem
105107
}
108+
109+
/**
110+
* Converts a byte array to a list of bytes
111+
*
112+
* @param bytes byte array
113+
*/
114+
static List<Byte> convertBytesToByteList(byte[] bytes) {
115+
return IntStream.range(0, bytes.length).mapToObj(i -> bytes[i]).collect(Collectors.toList());
116+
}
117+
118+
/**
119+
* Find the rootmost non-null cause of an Exception recursively
120+
*
121+
* @param t exception
122+
* @return root cause of the exception or the exception itself
123+
*/
124+
static Throwable getRootCause(Throwable t) {
125+
while (t.getCause() != null) {
126+
t = t.getCause();
127+
}
128+
return t;
129+
}
106130
}

0 commit comments

Comments
 (0)