@Test public void float64ArrayWrapper() { Value v = Value.float64Array(Arrays.asList(.1, null, .3)); assertThat(v.isNull()).isFalse(); assertThat(v.getFloat64Array()).containsExactly(.1d, null, .3d).inOrder(); assertThat(v.toString()).isEqualTo("[0.1,NULL,0.3]"); }
@Test public void int64ArrayWrapper() { Value v = Value.int64Array(Arrays.asList(1L, null, 3L)); assertThat(v.isNull()).isFalse(); assertThat(v.getInt64Array()).containsExactly(1L, null, 3L).inOrder(); assertThat(v.toString()).isEqualTo("[1,NULL,3]"); }
@Test public void string() { Value v = Value.string("abc"); assertThat(v.getType()).isEqualTo(Type.string()); assertThat(v.isNull()).isFalse(); assertThat(v.getString()).isEqualTo("abc"); }
@Test public void boolArrayRange() { Value v = Value.boolArray(new boolean[] {true, false, false, true, false}, 1, 3); assertThat(v.isNull()).isFalse(); assertThat(v.getBoolArray()).containsExactly(false, false, true).inOrder(); assertThat(v.toString()).isEqualTo("[false,false,true]"); }
@Test public void float64ArrayRange() { Value v = Value.float64Array(new double[] {.1, .2, .3, .4, .5}, 1, 3); assertThat(v.isNull()).isFalse(); assertThat(v.getFloat64Array()).containsExactly(.2d, .3d, .4d).inOrder(); assertThat(v.toString()).isEqualTo("[0.2,0.3,0.4]"); }
@Test public void float64Wrapper() { Value v = Value.float64(Double.valueOf(1.23)); assertThat(v.getType()).isEqualTo(Type.float64()); assertThat(v.isNull()).isFalse(); assertThat(v.getFloat64()).isWithin(0.0001).of(1.23); assertThat(v.toString()).isEqualTo("1.23"); }
@Test public void bool() { Value v = Value.bool(true); assertThat(v.getType()).isEqualTo(Type.bool()); assertThat(v.isNull()).isFalse(); assertThat(v.getBool()).isTrue(); assertThat(v.toString()).isEqualTo("true"); }
@Test public void int64() { Value v = Value.int64(123); assertThat(v.getType()).isEqualTo(Type.int64()); assertThat(v.isNull()).isFalse(); assertThat(v.getInt64()).isEqualTo(123); assertThat(v.toString()).isEqualTo("123"); }
@Test public void float64() { Value v = Value.float64(1.23); assertThat(v.getType()).isEqualTo(Type.float64()); assertThat(v.isNull()).isFalse(); assertThat(v.getFloat64()).isWithin(0.0001).of(1.23); assertThat(v.toString()).isEqualTo("1.23"); }
@Test public void int64ArrayWrapperNull() { Value v = Value.int64Array((Iterable<Long>) null); assertThat(v.isNull()).isTrue(); assertThat(v.toString()).isEqualTo(NULL_STRING); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("null value"); v.getInt64Array(); }
@Test public void stringArrayNull() { Value v = Value.stringArray(null); assertThat(v.isNull()).isTrue(); assertThat(v.toString()).isEqualTo(NULL_STRING); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("null value"); v.getStringArray(); }
@Test public void timestamp() { String timestamp = "2016-09-15T00:00:00Z"; Timestamp t = Timestamp.parseTimestamp(timestamp); Value v = Value.timestamp(t); assertThat(v.getType()).isEqualTo(Type.timestamp()); assertThat(v.isNull()).isFalse(); assertThat(v.isCommitTimestamp()).isFalse(); assertThat(v.getTimestamp()).isSameAs(t); assertThat(v.toString()).isEqualTo(timestamp); }
@Test public void bytesArrayNull() { Value v = Value.bytesArray(null); assertThat(v.isNull()).isTrue(); assertThat(v.toString()).isEqualTo(NULL_STRING); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("null value"); v.getBytesArray(); }
@Test public void boolArrayFromListNull() { Value v = Value.boolArray((Iterable<Boolean>) null); assertThat(v.isNull()).isTrue(); assertThat(v.toString()).isEqualTo(NULL_STRING); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("null value"); v.getBoolArray(); }
@Test public void dateArrayNull() { Value v = Value.dateArray(null); assertThat(v.isNull()).isTrue(); assertThat(v.toString()).isEqualTo(NULL_STRING); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("null value"); v.getDateArray(); }
@Test public void bytesNull() { Value v = Value.bytes(null); assertThat(v.getType()).isEqualTo(Type.bytes()); assertThat(v.isNull()).isTrue(); assertThat(v.toString()).isEqualTo(NULL_STRING); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("null value"); v.getBytes(); }
@Test public void dateNull() { Value v = Value.date(null); assertThat(v.getType()).isEqualTo(Type.date()); assertThat(v.isNull()).isTrue(); assertThat(v.toString()).isEqualTo(NULL_STRING); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("null value"); v.getDate(); }
@Test public void float64WrapperNull() { Value v = Value.float64(null); assertThat(v.getType()).isEqualTo(Type.float64()); assertThat(v.isNull()).isTrue(); assertThat(v.toString()).isEqualTo(NULL_STRING); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("null value"); v.getFloat64(); }
@Test public void int64WrapperNull() { Value v = Value.int64(null); assertThat(v.getType()).isEqualTo(Type.int64()); assertThat(v.isNull()).isTrue(); assertThat(v.toString()).isEqualTo(NULL_STRING); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("null value"); v.getInt64(); }
@Test public void nullStructGetter() { List<Type.StructField> fieldTypes = Arrays.asList( Type.StructField.of("f1", Type.string()), Type.StructField.of("f2", Type.int64())); Value v = Value.struct(Type.struct(fieldTypes), null); assertThat(v.isNull()).isTrue(); expectedException.expect(IllegalStateException.class); expectedException.expectMessage("Illegal call to getter of null value."); v.getStruct(); }