|
| 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 BoolTest { |
| 10 | + @Test |
| 11 | + public void testNew() { |
| 12 | + assertDoesNotThrow(() -> { |
| 13 | + new Bool(); |
| 14 | + }); |
| 15 | + } |
| 16 | + |
| 17 | + @Test |
| 18 | + public void testNewWithValidParam() { |
| 19 | + assertDoesNotThrow(() -> { |
| 20 | + new Bool(true); |
| 21 | + new Bool("true"); |
| 22 | + |
| 23 | + Scalar s = new Bool(true); |
| 24 | + new Bool(s); |
| 25 | + }); |
| 26 | + } |
| 27 | + |
| 28 | + @Test |
| 29 | + public void testNewWithInvalidParam() { |
| 30 | + assertThrows(ValidationException.class, () -> { |
| 31 | + new Bool(new char[]{'1'}); |
| 32 | + }); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + public void testToString() { |
| 37 | + Bool b = new Bool(); |
| 38 | + assertEquals(Scalar.NULL_VALUE_STRING, b.toString()); |
| 39 | + |
| 40 | + assertDoesNotThrow(() -> { |
| 41 | + b.set(true); |
| 42 | + }); |
| 43 | + assertEquals("true", b.toString()); |
| 44 | + |
| 45 | + assertDoesNotThrow(() -> { |
| 46 | + b.set(false); |
| 47 | + }); |
| 48 | + assertEquals("false", b.toString()); |
| 49 | + } |
| 50 | + |
| 51 | + @Test |
| 52 | + public void testDataType() { |
| 53 | + Bool b = new Bool(); |
| 54 | + assertEquals(ArrowType.Bool.INSTANCE, b.dataType()); |
| 55 | + assertEquals(new ArrowType.Bool(), b.dataType()); |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + public void testIsValid() { |
| 60 | + Bool b = new Bool(); |
| 61 | + assertFalse(b.isValid()); |
| 62 | + |
| 63 | + assertDoesNotThrow(() -> { |
| 64 | + b.set("true"); |
| 65 | + }); |
| 66 | + assertTrue(b.isValid()); |
| 67 | + } |
| 68 | + |
| 69 | + @Test |
| 70 | + public void testSet() { |
| 71 | + Bool b = new Bool(); |
| 72 | + assertDoesNotThrow(() -> { |
| 73 | + new Bool(true); |
| 74 | + new Bool("true"); |
| 75 | + |
| 76 | + Scalar s = new Bool(true); |
| 77 | + b.set(s); |
| 78 | + }); |
| 79 | + } |
| 80 | + |
| 81 | + @Test |
| 82 | + public void testSetWithInvalidParam() { |
| 83 | + Bool b = new Bool(); |
| 84 | + assertThrows(ValidationException.class, () -> { |
| 85 | + b.set(new char[]{}); |
| 86 | + }); |
| 87 | + } |
| 88 | + |
| 89 | + @Test |
| 90 | + public void testGet() { |
| 91 | + Bool b = new Bool(); |
| 92 | + assertFalse(b.isValid()); |
| 93 | + assertNull(b.get()); |
| 94 | + |
| 95 | + assertDoesNotThrow(() -> { |
| 96 | + b.set(true); |
| 97 | + }); |
| 98 | + assertTrue(b.isValid()); |
| 99 | + assertEquals(true, b.get()); |
| 100 | + |
| 101 | + assertDoesNotThrow(() -> { |
| 102 | + b.set("abc"); |
| 103 | + }); |
| 104 | + assertTrue(b.isValid()); |
| 105 | + assertEquals(false, b.get()); |
| 106 | + } |
| 107 | + |
| 108 | + @Test |
| 109 | + public void testEquals() { |
| 110 | + Bool a = new Bool(); |
| 111 | + Bool b = new Bool(); |
| 112 | + assertEquals(a, b); |
| 113 | + assertNotEquals(a, null); |
| 114 | + assertNotEquals(a, new Binary()); // we can't cast Binary to Bool |
| 115 | + assertNotEquals(null, a); |
| 116 | + |
| 117 | + assertDoesNotThrow(() -> { |
| 118 | + a.set(true); |
| 119 | + }); |
| 120 | + assertNotEquals(a, b); |
| 121 | + |
| 122 | + assertDoesNotThrow(() -> { |
| 123 | + for (Object obj : new Object[]{null, true, false, "abc", "true", "false"}) { |
| 124 | + a.set(obj); |
| 125 | + assertEquals(a, new Bool(obj)); |
| 126 | + } |
| 127 | + }); |
| 128 | + } |
| 129 | +} |
0 commit comments