Skip to content

Commit cc41103

Browse files
authored
chore: Test io.cloudquery.scalar.Binary & io.cloudquery.scalar.LargeBinary (#25)
1 parent 858e9f2 commit cc41103

File tree

10 files changed

+305
-13
lines changed

10 files changed

+305
-13
lines changed

lib/src/main/java/io/cloudquery/scalar/Binary.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,6 @@ public boolean equals(Object other) {
9292
return false;
9393
}
9494

95-
return (this.valid && o.valid) && Arrays.equals(this.value, o.value);
95+
return (this.valid == o.valid) && Arrays.equals(this.value, o.value);
9696
}
9797
}

lib/src/main/java/io/cloudquery/scalar/LargeBinary.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,33 @@
22

33
import org.apache.arrow.vector.types.pojo.ArrowType;
44

5+
import java.util.Arrays;
6+
57
public class LargeBinary extends Binary {
68

79
public LargeBinary() {
10+
super();
811
}
912

1013
public LargeBinary(Object value) throws ValidationException {
11-
this.set(value);
14+
super(value);
1215
}
1316

1417
@Override
1518
public ArrowType dataType() {
1619
return ArrowType.LargeBinary.INSTANCE;
1720
}
21+
22+
@Override
23+
public boolean equals(Object other) {
24+
if (other == null) {
25+
return false;
26+
}
27+
28+
if (!(other instanceof LargeBinary o)) {
29+
return false;
30+
}
31+
32+
return (this.valid == o.valid) && Arrays.equals(this.value, o.value);
33+
}
1834
}

lib/src/test/java/io/cloudquery/glob/GlobTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
import java.util.List;
66

77
import static io.cloudquery.glob.Glob.GLOB;
8-
import static org.junit.jupiter.api.Assertions.assertFalse;
9-
import static org.junit.jupiter.api.Assertions.assertTrue;
8+
import static org.junit.jupiter.api.Assertions.*;
109

1110
public class GlobTest {
1211
@Test

lib/src/test/java/io/cloudquery/scalar/BinaryTest.java

Lines changed: 126 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
import io.cloudquery.scalar.Binary;
44
import io.cloudquery.scalar.ValidationException;
55

6+
import org.apache.arrow.vector.types.pojo.ArrowType;
7+
import org.junit.Assert;
68
import org.junit.jupiter.api.Test;
79

8-
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
9-
import static org.junit.jupiter.api.Assertions.assertThrows;
10+
import java.util.Arrays;
11+
12+
import static org.junit.jupiter.api.Assertions.*;
1013

1114

1215
public class BinaryTest {
@@ -20,7 +23,12 @@ public void testNew() {
2023
@Test
2124
public void testNewWithValidParam() {
2225
assertDoesNotThrow(() -> {
26+
new Binary(new byte[]{'a', 'b', 'c'});
2327
new Binary("abc");
28+
new Binary(new char[]{'a', 'b', 'c'});
29+
30+
Scalar s = new Binary(new char[]{'a', 'b', 'c'});
31+
new Binary(s);
2432
});
2533
}
2634

@@ -30,4 +38,120 @@ public void testNewWithInvalidParam() {
3038
new Binary(false);
3139
});
3240
}
41+
42+
@Test
43+
public void testToString() {
44+
Binary b = new Binary();
45+
assertEquals(Scalar.NULL_VALUE_STRING, b.toString());
46+
47+
assertDoesNotThrow(() -> {
48+
b.set("abc");
49+
});
50+
assertEquals("abc=", b.toString());
51+
52+
assertDoesNotThrow(() -> {
53+
b.set(new byte[]{0, 1, 2, 3, 4, 5});
54+
});
55+
assertEquals("AAECAwQF", b.toString());
56+
}
57+
58+
@Test
59+
public void testDataType() {
60+
Binary b = new Binary();
61+
assertEquals(ArrowType.Binary.INSTANCE, b.dataType());
62+
assertEquals(new ArrowType.Binary(), b.dataType());
63+
}
64+
65+
@Test
66+
public void testIsValid() {
67+
Binary b = new Binary();
68+
assertFalse(b.isValid());
69+
70+
assertDoesNotThrow(() -> {
71+
b.set("abc");
72+
});
73+
assertTrue(b.isValid());
74+
}
75+
76+
@Test
77+
public void testSet() {
78+
Binary b = new Binary();
79+
assertDoesNotThrow(() -> {
80+
b.set(new byte[]{'a', 'b', 'c'});
81+
b.set("abc");
82+
b.set(new char[]{'a', 'b', 'c'});
83+
84+
Scalar s = new Binary(new char[]{'a', 'b', 'c'});
85+
b.set(s);
86+
});
87+
}
88+
89+
@Test
90+
public void testSetWithInvalidParam() {
91+
Binary b = new Binary();
92+
assertThrows(ValidationException.class, () -> {
93+
b.set(false);
94+
});
95+
}
96+
97+
@Test
98+
public void testGet() {
99+
Binary b = new Binary();
100+
assertFalse(b.isValid());
101+
assertNull(b.get());
102+
103+
assertDoesNotThrow(() -> {
104+
b.set(new byte[]{'a', 'b', 'c'});
105+
});
106+
assertTrue(b.isValid());
107+
assertArrayEquals(new byte[]{'a', 'b', 'c'}, (byte[]) b.get());
108+
109+
assertDoesNotThrow(() -> {
110+
b.set("abc");
111+
});
112+
assertTrue(b.isValid());
113+
assertArrayEquals(new byte[]{105, -73}, (byte[]) b.get());
114+
115+
assertDoesNotThrow(() -> {
116+
b.set(new char[]{'a', 'b', 'c'});
117+
});
118+
assertTrue(b.isValid());
119+
assertArrayEquals(new byte[]{105, -73}, (byte[]) b.get());
120+
121+
assertDoesNotThrow(() -> {
122+
Scalar s = new Binary(new char[]{'a', 'b', 'c'});
123+
b.set(s);
124+
});
125+
assertTrue(b.isValid());
126+
assertArrayEquals(new byte[]{105, -73}, (byte[]) b.get());
127+
128+
assertDoesNotThrow(() -> {
129+
Scalar s = new Binary(new byte[]{'a', 'b', 'c'});
130+
b.set(s);
131+
});
132+
assertTrue(b.isValid());
133+
assertArrayEquals(new byte[]{'a', 'b', 'c'}, (byte[]) b.get());
134+
}
135+
136+
@Test
137+
public void testEquals() {
138+
Binary a = new Binary();
139+
Binary b = new Binary();
140+
assertEquals(a, b);
141+
assertNotEquals(a, null);
142+
assertEquals(a, new LargeBinary()); // we can cast LargeBinary to Binary
143+
assertNotEquals(null, a);
144+
145+
assertDoesNotThrow(() -> {
146+
a.set(new byte[]{'a', 'b', 'c'});
147+
});
148+
assertNotEquals(a, b);
149+
150+
assertDoesNotThrow(() -> {
151+
for (Object obj : new Object[]{null, new byte[]{'a', 'b', 'c'}, new char[]{'a', 'b', 'c'}, "abc", new Binary("abc"),}) {
152+
a.set(obj);
153+
assertEquals(a, new Binary(obj));
154+
}
155+
});
156+
}
33157
}
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
package io.cloudquery.scalar;
2+
3+
import org.apache.arrow.vector.types.pojo.ArrowType;
4+
import org.junit.jupiter.api.Test;
5+
6+
import static org.junit.jupiter.api.Assertions.*;
7+
8+
9+
public class LargeBinaryTest {
10+
@Test
11+
public void testNew() {
12+
assertDoesNotThrow(() -> {
13+
new LargeBinary();
14+
});
15+
}
16+
17+
@Test
18+
public void testNewWithValidParam() {
19+
assertDoesNotThrow(() -> {
20+
new LargeBinary(new byte[]{'a', 'b', 'c'});
21+
new LargeBinary("abc");
22+
new LargeBinary(new char[]{'a', 'b', 'c'});
23+
24+
Scalar s = new LargeBinary(new char[]{'a', 'b', 'c'});
25+
new LargeBinary(s);
26+
});
27+
}
28+
29+
@Test
30+
public void testNewWithInvalidParam() {
31+
assertThrows(ValidationException.class, () -> {
32+
new LargeBinary(false);
33+
});
34+
}
35+
36+
@Test
37+
public void testToString() {
38+
LargeBinary b = new LargeBinary();
39+
assertEquals(Scalar.NULL_VALUE_STRING, b.toString());
40+
41+
assertDoesNotThrow(() -> {
42+
b.set("abc");
43+
});
44+
assertEquals("abc=", b.toString());
45+
46+
assertDoesNotThrow(() -> {
47+
b.set(new byte[]{0, 1, 2, 3, 4, 5});
48+
});
49+
assertEquals("AAECAwQF", b.toString());
50+
}
51+
52+
@Test
53+
public void testDataType() {
54+
LargeBinary b = new LargeBinary();
55+
assertEquals(ArrowType.LargeBinary.INSTANCE, b.dataType());
56+
assertEquals(new ArrowType.LargeBinary(), b.dataType());
57+
}
58+
59+
@Test
60+
public void testIsValid() {
61+
LargeBinary b = new LargeBinary();
62+
assertFalse(b.isValid());
63+
64+
assertDoesNotThrow(() -> {
65+
b.set("abc");
66+
});
67+
assertTrue(b.isValid());
68+
}
69+
70+
@Test
71+
public void testSet() {
72+
LargeBinary b = new LargeBinary();
73+
assertDoesNotThrow(() -> {
74+
b.set(new byte[]{'a', 'b', 'c'});
75+
b.set("abc");
76+
b.set(new char[]{'a', 'b', 'c'});
77+
78+
Scalar s = new LargeBinary(new char[]{'a', 'b', 'c'});
79+
b.set(s);
80+
});
81+
}
82+
83+
@Test
84+
public void testSetWithInvalidParam() {
85+
LargeBinary b = new LargeBinary();
86+
assertThrows(ValidationException.class, () -> {
87+
b.set(false);
88+
});
89+
}
90+
91+
@Test
92+
public void testGet() {
93+
LargeBinary b = new LargeBinary();
94+
assertFalse(b.isValid());
95+
assertNull(b.get());
96+
97+
assertDoesNotThrow(() -> {
98+
b.set(new byte[]{'a', 'b', 'c'});
99+
});
100+
assertTrue(b.isValid());
101+
assertArrayEquals(new byte[]{'a', 'b', 'c'}, (byte[]) b.get());
102+
103+
assertDoesNotThrow(() -> {
104+
b.set("abc");
105+
});
106+
assertTrue(b.isValid());
107+
assertArrayEquals(new byte[]{105, -73}, (byte[]) b.get());
108+
109+
assertDoesNotThrow(() -> {
110+
b.set(new char[]{'a', 'b', 'c'});
111+
});
112+
assertTrue(b.isValid());
113+
assertArrayEquals(new byte[]{105, -73}, (byte[]) b.get());
114+
115+
assertDoesNotThrow(() -> {
116+
Scalar s = new LargeBinary(new char[]{'a', 'b', 'c'});
117+
b.set(s);
118+
});
119+
assertTrue(b.isValid());
120+
assertArrayEquals(new byte[]{105, -73}, (byte[]) b.get());
121+
122+
assertDoesNotThrow(() -> {
123+
Scalar s = new LargeBinary(new byte[]{'a', 'b', 'c'});
124+
b.set(s);
125+
});
126+
assertTrue(b.isValid());
127+
assertArrayEquals(new byte[]{'a', 'b', 'c'}, (byte[]) b.get());
128+
}
129+
@Test
130+
public void testEquals() {
131+
LargeBinary a = new LargeBinary();
132+
LargeBinary b = new LargeBinary();
133+
assertEquals(a, b);
134+
assertNotEquals(a,null);
135+
assertNotEquals(a,new Binary()); // we can't cast Binary to LargeBinary
136+
assertNotEquals(null, a);
137+
138+
assertDoesNotThrow(() -> {
139+
a.set(new byte[]{'a', 'b', 'c'});
140+
});
141+
assertNotEquals(a,b);
142+
143+
assertDoesNotThrow(() -> {
144+
for (Object obj: new Object[]{
145+
null,
146+
new byte[]{'a', 'b', 'c'},
147+
new char[]{'a', 'b', 'c'},
148+
"abc",
149+
new LargeBinary("abc"),
150+
}) {
151+
a.set(obj);
152+
assertEquals(a, new LargeBinary(obj));
153+
}
154+
});
155+
}
156+
}

lib/src/test/java/io/cloudquery/schema/TableFilterDFSTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
import java.util.stream.Stream;
88

99
import static org.assertj.core.api.Assertions.assertThat;
10-
import static org.junit.jupiter.api.Assertions.assertEquals;
11-
import static org.junit.jupiter.api.Assertions.assertThrows;
10+
import static org.junit.jupiter.api.Assertions.*;
1211

1312
public class TableFilterDFSTest {
1413
public static final List<Table> BASIC_TABLES = Stream.of("table1", "table2", "table3").map(

lib/src/test/java/io/cloudquery/schema/TableFlattenTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import java.util.List;
66

7-
import static org.junit.jupiter.api.Assertions.assertEquals;
7+
import static org.junit.jupiter.api.Assertions.*;
88

99
public class TableFlattenTest {
1010

lib/src/test/java/io/cloudquery/schema/TableMaxTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import java.util.Collections;
66
import java.util.List;
77

8-
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
import static org.junit.jupiter.api.Assertions.*;
99

1010
public class TableMaxTest {
1111

lib/src/test/java/io/cloudquery/server/AddressTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
import org.junit.jupiter.api.BeforeEach;
55
import org.junit.jupiter.api.Test;
66

7-
import static org.junit.jupiter.api.Assertions.assertEquals;
8-
import static org.junit.jupiter.api.Assertions.assertThrows;
7+
import static org.junit.jupiter.api.Assertions.*;
98

109
public class AddressTest {
1110

0 commit comments

Comments
 (0)