@Test public void parseErrorMissingTypeCode() { com.google.spanner.v1.Type proto = com.google.spanner.v1.Type.newBuilder().build(); expectedException.expect(IllegalArgumentException.class); Type.fromProto(proto); }
@Test public void parseErrorMissingArrayElementTypeProto() { com.google.spanner.v1.Type proto = com.google.spanner.v1.Type.newBuilder().setCode(TypeCode.ARRAY).build(); expectedException.expect(IllegalArgumentException.class); Type.fromProto(proto); }
void test() { Type t = newType(); assertThat(t.getCode()).isEqualTo(expectedCode); assertThat(newType()).isSameAs(t); // Interned. // String form is deliberately the same as the corresponding type enum in the public API. assertThat(t.toString()).isEqualTo(expectedProtoCode.toString()); com.google.spanner.v1.Type proto = t.toProto(); assertThat(proto.getCode()).isEqualTo(expectedProtoCode); assertThat(proto.hasArrayElementType()).isFalse(); assertThat(proto.hasStructType()).isFalse(); // Round trip. Type fromProto = Type.fromProto(proto); assertThat(fromProto).isEqualTo(t); assertThat(fromProto).isSameAs(t); reserializeAndAssert(t); } }
void test() { Type elementType = newElementType(); Type t = Type.array(elementType); assertThat(t.getCode()).isEqualTo(Type.Code.ARRAY); assertThat(t.getArrayElementType()).isEqualTo(elementType); if (expectInterned) { assertThat(Type.array(newElementType())).isSameAs(t); } assertThat(t.toString()).isEqualTo("ARRAY<" + elementType.toString() + ">"); com.google.spanner.v1.Type proto = t.toProto(); assertThat(proto.getCode()).isEqualTo(TypeCode.ARRAY); assertThat(proto.getArrayElementType()).isEqualTo(elementType.toProto()); assertThat(proto.hasStructType()).isFalse(); Type fromProto = Type.fromProto(proto); assertThat(fromProto).isEqualTo(t); if (expectInterned) { assertThat(fromProto).isSameAs(t); } reserializeAndAssert(t); } }
.build(); try { type = Type.fromProto(typeProto); } catch (IllegalArgumentException e) { throw newSpannerException(
.build(); try { type = Type.fromProto(typeProto); } catch (IllegalArgumentException e) { throw newSpannerException(