33import io .cloudquery .scalar .Binary ;
44import io .cloudquery .scalar .ValidationException ;
55
6+ import org .apache .arrow .vector .types .pojo .ArrowType ;
7+ import org .junit .Assert ;
68import 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
1215public 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}
0 commit comments