Skip to content

Commit

Permalink
Do not use utility classes from dependencies
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
akudiyar committed Jul 29, 2023
1 parent 3ddf1ea commit b29ae05
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
7 changes: 4 additions & 3 deletions src/test/java/io/tarantool/driver/TarantoolUtils.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.tarantool.driver;

import io.tarantool.driver.utils.Assert;
import org.testcontainers.shaded.org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.Collections;
Expand All @@ -18,13 +17,14 @@ private TarantoolUtils() {
public static boolean versionGreaterOrEqualThen(String tarantoolVersion) {
Assert.notNull(tarantoolVersion, "tarantoolVersion must not be null");
String tarantoolCiVersion = java.lang.System.getenv(TARANTOOL_VERSION);
if (StringUtils.isEmpty(tarantoolCiVersion)) {
if (tarantoolCiVersion == null || tarantoolCiVersion.isEmpty()) {
return true;
}
TarantoolVersion ciVersion = new TarantoolVersion(tarantoolCiVersion);
TarantoolVersion version = new TarantoolVersion(tarantoolVersion);
return ciVersion.getMajor() >= version.getMajor() &&
ciVersion.getMinor() >= version.getMinor();

}

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

public TarantoolVersion(String stringVersion) {
List<String> majorMinor = StringUtils.isEmpty(stringVersion) ? Collections.emptyList() :
List<String> majorMinor = stringVersion == null || stringVersion.isEmpty() ?
Collections.emptyList() :
Arrays.stream(stringVersion.split("\\."))
.collect(Collectors.toList());
if (majorMinor.size() >= 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIf;
import org.testcontainers.shaded.org.apache.commons.lang3.ArrayUtils;

import java.time.Instant;
import java.util.UUID;

import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;

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

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

//then
byte[] bytesFromTarantool = fields.getByteArray("varbinary_field");
List<Byte> byteListFromTarantool = Arrays.asList(ArrayUtils.toObject(bytesFromTarantool));
List<Byte> byteListFromTarantool = Utils.convertBytesToByteList(bytesFromTarantool);
Assertions.assertEquals(byteList, byteListFromTarantool);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIf;
import org.testcontainers.shaded.org.apache.commons.lang3.ArrayUtils;

import java.time.Instant;
import java.util.UUID;

import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;

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

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

//then
byte[] bytesFromTarantool = fields.getByteArray("varbinary_field");
List<Byte> byteListFromTarantool = Arrays.asList(ArrayUtils.toObject(bytesFromTarantool));
List<Byte> byteListFromTarantool = Utils.convertBytesToByteList(bytesFromTarantool);
Assertions.assertEquals(byteList, byteListFromTarantool);
}

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

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

//then
byte[] bytesFromTarantool = fields.getByteArray("string_field");
List<Byte> byteListFromTarantool = Arrays.asList(ArrayUtils.toObject(bytesFromTarantool));
List<Byte> byteListFromTarantool = Utils.convertBytesToByteList(bytesFromTarantool);
Assertions.assertEquals(byteList, byteListFromTarantool);
}
}
11 changes: 11 additions & 0 deletions src/test/java/io/tarantool/driver/integration/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

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

Expand Down Expand Up @@ -103,4 +105,13 @@ private static long crc32(byte[] data) {
crc32 = Integer.reverse(crc32); // result reflect
return crc32 & 0x00000000ffffffffL; // the unsigned java problem
}

/**
* Converts a byte array to a list of bytes
*
* @param bytes byte array
*/
static List<Byte> convertBytesToByteList(byte[] bytes) {
return IntStream.range(0, bytes.length).mapToObj(i -> bytes[i]).collect(Collectors.toList());
}
}

0 comments on commit b29ae05

Please sign in to comment.