use of com.google.cloud.spanner.ResultSet in project spanner-jdbc by olavloite.
the class TransactionContextMock method mockPreparedWithMutationsResultSet.
private ResultSet mockPreparedWithMutationsResultSet() throws SQLException {
List<String> mutations = createSerializedMutations();
ResultSet rs = mock(ResultSet.class);
when(rs.next()).thenReturn(true, true, true, false);
when(rs.getLong(0)).thenReturn(1l, 2l, 3l);
when(rs.getString(1)).thenReturn(mutations.get(0), mutations.get(1), mutations.get(2));
return rs;
}
use of com.google.cloud.spanner.ResultSet in project spanner-jdbc by olavloite.
the class CloudSpannerResultSetTest method getMockResultSet.
static ResultSet getMockResultSet() {
ResultSet res = mock(ResultSet.class);
when(res.getString(STRING_COL_NULL)).thenReturn(null);
when(res.isNull(STRING_COL_NULL)).thenReturn(true);
when(res.getString(STRING_COL_NOT_NULL)).thenReturn("FOO");
when(res.isNull(STRING_COL_NOT_NULL)).thenReturn(false);
when(res.getString(STRING_COLINDEX_NULL - 1)).thenReturn(null);
when(res.isNull(STRING_COLINDEX_NULL - 1)).thenReturn(true);
when(res.getString(STRING_COLINDEX_NOTNULL - 1)).thenReturn("BAR");
when(res.isNull(STRING_COLINDEX_NOTNULL - 1)).thenReturn(false);
when(res.getColumnType(STRING_COL_NULL)).thenReturn(Type.string());
when(res.getColumnType(STRING_COL_NOT_NULL)).thenReturn(Type.string());
when(res.getColumnType(STRING_COLINDEX_NULL - 1)).thenReturn(Type.string());
when(res.getColumnType(STRING_COLINDEX_NOTNULL - 1)).thenReturn(Type.string());
when(res.getString(URL_COL_NULL)).thenReturn(null);
when(res.isNull(URL_COL_NULL)).thenReturn(true);
when(res.getString(URL_COL_NOT_NULL)).thenReturn("https://github.com/olavloite/spanner-jdbc");
when(res.isNull(URL_COL_NOT_NULL)).thenReturn(false);
when(res.getString(URL_COLINDEX_NULL - 1)).thenReturn(null);
when(res.isNull(URL_COLINDEX_NULL - 1)).thenReturn(true);
when(res.getString(URL_COLINDEX_NOTNULL - 1)).thenReturn("https://github.com/olavloite");
when(res.isNull(URL_COLINDEX_NOTNULL - 1)).thenReturn(false);
when(res.getColumnType(URL_COL_NULL)).thenReturn(Type.string());
when(res.getColumnType(URL_COL_NOT_NULL)).thenReturn(Type.string());
when(res.getColumnType(URL_COLINDEX_NULL - 1)).thenReturn(Type.string());
when(res.getColumnType(URL_COLINDEX_NOTNULL - 1)).thenReturn(Type.string());
when(res.getBoolean(BOOLEAN_COL_NULL)).thenReturn(false);
when(res.isNull(BOOLEAN_COL_NULL)).thenReturn(true);
when(res.getBoolean(BOOLEAN_COL_NOT_NULL)).thenReturn(true);
when(res.isNull(BOOLEAN_COL_NOT_NULL)).thenReturn(false);
when(res.getBoolean(BOOLEAN_COLINDEX_NULL - 1)).thenReturn(false);
when(res.isNull(BOOLEAN_COLINDEX_NULL - 1)).thenReturn(true);
when(res.getBoolean(BOOLEAN_COLINDEX_NOTNULL - 1)).thenReturn(false);
when(res.isNull(BOOLEAN_COLINDEX_NOTNULL - 1)).thenReturn(false);
when(res.getColumnType(BOOLEAN_COL_NULL)).thenReturn(Type.bool());
when(res.getColumnType(BOOLEAN_COL_NOT_NULL)).thenReturn(Type.bool());
when(res.getColumnType(BOOLEAN_COLINDEX_NULL - 1)).thenReturn(Type.bool());
when(res.getColumnType(BOOLEAN_COLINDEX_NOTNULL - 1)).thenReturn(Type.bool());
when(res.getDouble(DOUBLE_COL_NULL)).thenReturn(0d);
when(res.isNull(DOUBLE_COL_NULL)).thenReturn(true);
when(res.getDouble(DOUBLE_COL_NOT_NULL)).thenReturn(1.123456789d);
when(res.isNull(DOUBLE_COL_NOT_NULL)).thenReturn(false);
when(res.getDouble(DOUBLE_COLINDEX_NULL - 1)).thenReturn(0d);
when(res.isNull(DOUBLE_COLINDEX_NULL - 1)).thenReturn(true);
when(res.getDouble(DOUBLE_COLINDEX_NOTNULL - 1)).thenReturn(2.123456789d);
when(res.isNull(DOUBLE_COLINDEX_NOTNULL - 1)).thenReturn(false);
when(res.getColumnType(DOUBLE_COL_NULL)).thenReturn(Type.float64());
when(res.getColumnType(DOUBLE_COL_NOT_NULL)).thenReturn(Type.float64());
when(res.getColumnType(DOUBLE_COLINDEX_NULL - 1)).thenReturn(Type.float64());
when(res.getColumnType(DOUBLE_COLINDEX_NOTNULL - 1)).thenReturn(Type.float64());
when(res.getString(BYTES_COL_NULL)).thenReturn(null);
when(res.isNull(BYTES_COL_NULL)).thenReturn(true);
when(res.getBytes(BYTES_COL_NOT_NULL)).thenReturn(ByteArray.copyFrom("FOO"));
when(res.isNull(BYTES_COL_NOT_NULL)).thenReturn(false);
when(res.getBytes(BYTES_COLINDEX_NULL - 1)).thenReturn(null);
when(res.isNull(BYTES_COLINDEX_NULL - 1)).thenReturn(true);
when(res.getBytes(BYTES_COLINDEX_NOTNULL - 1)).thenReturn(ByteArray.copyFrom("BAR"));
when(res.isNull(BYTES_COLINDEX_NOTNULL - 1)).thenReturn(false);
when(res.getColumnType(BYTES_COL_NULL)).thenReturn(Type.bytes());
when(res.getColumnType(BYTES_COL_NOT_NULL)).thenReturn(Type.bytes());
when(res.getColumnType(BYTES_COLINDEX_NULL - 1)).thenReturn(Type.bytes());
when(res.getColumnType(BYTES_COLINDEX_NOTNULL - 1)).thenReturn(Type.bytes());
when(res.getLong(LONG_COL_NULL)).thenReturn(0l);
when(res.isNull(LONG_COL_NULL)).thenReturn(true);
when(res.getLong(LONG_COL_NOT_NULL)).thenReturn(1l);
when(res.isNull(LONG_COL_NOT_NULL)).thenReturn(false);
when(res.getLong(LONG_COLINDEX_NULL - 1)).thenReturn(0l);
when(res.isNull(LONG_COLINDEX_NULL - 1)).thenReturn(true);
when(res.getLong(LONG_COLINDEX_NOTNULL - 1)).thenReturn(2l);
when(res.isNull(LONG_COLINDEX_NOTNULL - 1)).thenReturn(false);
when(res.getColumnType(LONG_COL_NULL)).thenReturn(Type.int64());
when(res.getColumnType(LONG_COL_NOT_NULL)).thenReturn(Type.int64());
when(res.getColumnType(LONG_COLINDEX_NULL - 1)).thenReturn(Type.int64());
when(res.getColumnType(LONG_COLINDEX_NOTNULL - 1)).thenReturn(Type.int64());
when(res.getDate(DATE_COL_NULL)).thenAnswer(new Returns(null));
when(res.isNull(DATE_COL_NULL)).thenAnswer(new Returns(true));
when(res.getDate(DATE_COL_NOT_NULL)).thenAnswer(new Returns(Date.fromYearMonthDay(2017, 9, 10)));
when(res.isNull(DATE_COL_NOT_NULL)).thenAnswer(new Returns(false));
when(res.getDate(DATE_COLINDEX_NULL - 1)).thenAnswer(new Returns(null));
when(res.isNull(DATE_COLINDEX_NULL - 1)).thenAnswer(new Returns(true));
when(res.getDate(DATE_COLINDEX_NOTNULL - 1)).thenAnswer(new Returns(Date.fromYearMonthDay(2017, 9, 10)));
when(res.isNull(DATE_COLINDEX_NOTNULL - 1)).thenAnswer(new Returns(false));
when(res.getColumnType(DATE_COL_NULL)).thenAnswer(new Returns(Type.date()));
when(res.getColumnType(DATE_COL_NOT_NULL)).thenAnswer(new Returns(Type.date()));
when(res.getColumnType(DATE_COLINDEX_NULL - 1)).thenAnswer(new Returns(Type.date()));
when(res.getColumnType(DATE_COLINDEX_NOTNULL - 1)).thenAnswer(new Returns(Type.date()));
Calendar cal1 = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
cal1.clear();
cal1.set(2017, 8, 10, 8, 15, 59);
Calendar cal2 = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
cal2.clear();
cal2.set(2017, 8, 11, 8, 15, 59);
when(res.getTimestamp(TIMESTAMP_COL_NULL)).thenReturn(null);
when(res.isNull(TIMESTAMP_COL_NULL)).thenReturn(true);
when(res.getTimestamp(TIMESTAMP_COL_NOT_NULL)).thenReturn(Timestamp.of(cal1.getTime()));
when(res.isNull(TIMESTAMP_COL_NOT_NULL)).thenReturn(false);
when(res.getTimestamp(TIMESTAMP_COLINDEX_NULL - 1)).thenReturn(null);
when(res.isNull(TIMESTAMP_COLINDEX_NULL - 1)).thenReturn(true);
when(res.getTimestamp(TIMESTAMP_COLINDEX_NOTNULL - 1)).thenReturn(Timestamp.of(cal2.getTime()));
when(res.isNull(TIMESTAMP_COLINDEX_NOTNULL - 1)).thenReturn(false);
when(res.getColumnType(TIMESTAMP_COL_NULL)).thenReturn(Type.timestamp());
when(res.getColumnType(TIMESTAMP_COL_NOT_NULL)).thenReturn(Type.timestamp());
when(res.getColumnType(TIMESTAMP_COLINDEX_NULL - 1)).thenReturn(Type.timestamp());
when(res.getColumnType(TIMESTAMP_COLINDEX_NOTNULL - 1)).thenReturn(Type.timestamp());
Calendar cal3 = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
cal3.clear();
cal3.set(1970, 0, 1, 14, 6, 15);
Calendar cal4 = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
cal4.clear();
cal4.set(1970, 0, 1, 14, 6, 15);
when(res.getTimestamp(TIME_COL_NULL)).thenReturn(null);
when(res.isNull(TIME_COL_NULL)).thenReturn(true);
when(res.getTimestamp(TIME_COL_NOT_NULL)).thenReturn(Timestamp.of(cal3.getTime()));
when(res.isNull(TIME_COL_NOT_NULL)).thenReturn(false);
when(res.getTimestamp(TIME_COLINDEX_NULL - 1)).thenReturn(null);
when(res.isNull(TIME_COLINDEX_NULL - 1)).thenReturn(true);
when(res.getTimestamp(TIME_COLINDEX_NOTNULL - 1)).thenReturn(Timestamp.of(cal4.getTime()));
when(res.isNull(TIME_COLINDEX_NOTNULL - 1)).thenReturn(false);
when(res.getColumnType(TIME_COL_NULL)).thenReturn(Type.timestamp());
when(res.getColumnType(TIME_COL_NOT_NULL)).thenReturn(Type.timestamp());
when(res.getColumnType(TIME_COLINDEX_NULL - 1)).thenReturn(Type.timestamp());
when(res.getColumnType(TIME_COLINDEX_NOTNULL - 1)).thenReturn(Type.timestamp());
when(res.getLongList(ARRAY_COL_NULL)).thenAnswer(new Returns(null));
when(res.isNull(ARRAY_COL_NULL)).thenAnswer(new Returns(true));
when(res.getLongList(ARRAY_COL_NOT_NULL)).thenAnswer(new Returns(Arrays.asList(1L, 2L, 3L)));
when(res.isNull(ARRAY_COL_NOT_NULL)).thenAnswer(new Returns(false));
when(res.getLongList(ARRAY_COLINDEX_NULL - 1)).thenAnswer(new Returns(null));
when(res.isNull(ARRAY_COLINDEX_NULL - 1)).thenAnswer(new Returns(true));
when(res.getLongList(ARRAY_COLINDEX_NOTNULL - 1)).thenAnswer(new Returns(Arrays.asList(1L, 2L, 3L)));
when(res.isNull(ARRAY_COLINDEX_NOTNULL - 1)).thenAnswer(new Returns(false));
when(res.getColumnType(ARRAY_COL_NULL)).thenAnswer(new Returns(Type.array(Type.int64())));
when(res.getColumnType(ARRAY_COL_NOT_NULL)).thenAnswer(new Returns(Type.array(Type.int64())));
when(res.getColumnType(ARRAY_COLINDEX_NULL - 1)).thenAnswer(new Returns(Type.array(Type.int64())));
when(res.getColumnType(ARRAY_COLINDEX_NOTNULL - 1)).thenAnswer(new Returns(Type.array(Type.int64())));
when(res.getColumnIndex(STRING_COL_NOT_NULL)).thenAnswer(new Returns(1));
when(res.getColumnIndex(UNKNOWN_COLUMN)).thenThrow(IllegalArgumentException.class);
when(res.getColumnIndex(DATE_COL_NOT_NULL)).thenAnswer(new Returns(DATE_COLINDEX_NOTNULL - 1));
when(res.getColumnIndex(ARRAY_COL_NOT_NULL)).thenAnswer(new Returns(ARRAY_COLINDEX_NOTNULL - 1));
when(res.getColumnIndex(ARRAY_COL_NULL)).thenAnswer(new Returns(ARRAY_COLINDEX_NULL - 1));
when(res.getType()).thenReturn(Type.struct(StructField.of(STRING_COL_NULL, Type.string()), StructField.of(STRING_COL_NOT_NULL, Type.string()), StructField.of(BOOLEAN_COL_NULL, Type.bool()), StructField.of(BOOLEAN_COL_NOT_NULL, Type.bool()), StructField.of(DOUBLE_COL_NULL, Type.float64()), StructField.of(DOUBLE_COL_NOT_NULL, Type.float64()), StructField.of(BYTES_COL_NULL, Type.bytes()), StructField.of(BYTES_COL_NOT_NULL, Type.bytes()), StructField.of(LONG_COL_NULL, Type.int64()), StructField.of(LONG_COL_NOT_NULL, Type.int64()), StructField.of(DATE_COL_NULL, Type.date()), StructField.of(DATE_COL_NOT_NULL, Type.date()), StructField.of(TIMESTAMP_COL_NULL, Type.timestamp()), StructField.of(TIMESTAMP_COL_NOT_NULL, Type.timestamp()), StructField.of(TIME_COL_NULL, Type.timestamp()), StructField.of(TIME_COL_NOT_NULL, Type.timestamp()), StructField.of(URL_COL_NULL, Type.string()), StructField.of(URL_COL_NOT_NULL, Type.string())));
// Next behaviour.
when(res.next()).thenReturn(true, true, true, true, false);
return res;
}
use of com.google.cloud.spanner.ResultSet in project spanner-jdbc by olavloite.
the class CloudSpannerResultSetMetaDataTest method createFooColumnsResultSet.
private CloudSpannerResultSet createFooColumnsResultSet(CloudSpannerStatement statement, String colName) throws SQLException {
List<TestColumn> columns = colName == null ? tableColumns() : Arrays.asList(getTestColumn(colName));
List<Struct> rows = new ArrayList<>(columns.size());
for (TestColumn col : columns) {
rows.add(Struct.newBuilder().set("COLUMN_NAME").to(Value.string(col.name)).set("NULLABLE").to(Value.int64(col.nullable)).set("COLUMN_SIZE").to(Value.int64(col.size)).build());
}
ResultSet rs = ResultSets.forRows(Type.struct(StructField.of("COLUMN_NAME", Type.string()), StructField.of("NULLABLE", Type.int64()), StructField.of("COLUMN_SIZE", Type.int64())), rows);
return new CloudSpannerResultSet(statement, rs, null);
}
use of com.google.cloud.spanner.ResultSet in project spring-cloud-gcp by spring-cloud.
the class ConverterAwareMappingSpannerEntityProcessorTests method mapToListTest.
@Test
public void mapToListTest() {
List<Double> doubleList = new ArrayList<>();
doubleList.add(3.33);
List<String> stringList = new ArrayList<>();
stringList.add("string");
Instant i1 = Instant.ofEpochSecond(111);
Instant i2 = Instant.ofEpochSecond(222);
Instant i3 = Instant.ofEpochSecond(333);
List<Instant> instants = new ArrayList<>();
instants.add(i1);
instants.add(i2);
instants.add(i3);
Timestamp ts1 = Timestamp.ofTimeSecondsAndNanos(111, 0);
Timestamp ts2 = Timestamp.ofTimeSecondsAndNanos(222, 0);
Timestamp ts3 = Timestamp.ofTimeSecondsAndNanos(333, 0);
List<Timestamp> timestamps = new ArrayList<>();
timestamps.add(ts1);
timestamps.add(ts2);
timestamps.add(ts3);
Struct struct1 = Struct.newBuilder().set("id").to(Value.string("key1")).set("id2").to(Value.string("key2")).set("id3").to(Value.string("key3")).set("id4").to(Value.string("key4")).set("custom_col").to(Value.string("WHITE")).set("booleanField").to(Value.bool(true)).set("intField").to(Value.int64(123L)).set("intField2").to(Value.int64(333L)).set("longField").to(Value.int64(3L)).set("doubleField").to(Value.float64(3.33)).set("doubleArray").to(Value.float64Array(new double[] { 3.33, 3.33, 3.33 })).set("doubleList").to(Value.float64Array(doubleList)).set("stringList").to(Value.stringArray(stringList)).set("booleanList").to(Value.boolArray(new boolean[] {})).set("longList").to(Value.int64Array(new long[] {})).set("timestampList").to(Value.timestampArray(new ArrayList<>())).set("dateList").to(Value.dateArray(new ArrayList<>())).set("bytesList").to(Value.bytesArray(new ArrayList<>())).set("dateField").to(Value.date(Date.fromYearMonthDay(2018, 11, 22))).set("timestampField").to(Value.timestamp(Timestamp.ofTimeMicroseconds(333))).set("bytes").to(Value.bytes(ByteArray.copyFrom("string1"))).set("momentsInTime").to(Value.timestampArray(timestamps)).set("commitTimestamp").to(Value.timestamp(Timestamp.ofTimeMicroseconds(1))).set("bigDecimalField").to(Value.numeric(BigDecimal.TEN)).set("bigDecimals").to(Value.numericArray(Arrays.asList(BigDecimal.ONE, BigDecimal.ZERO))).build();
Struct struct2 = Struct.newBuilder().set("id").to(Value.string("key12")).set("id2").to(Value.string("key22")).set("id3").to(Value.string("key32")).set("id4").to(Value.string("key42")).set("custom_col").to(Value.string("BLACK")).set("booleanField").to(Value.bool(true)).set("intField").to(Value.int64(222L)).set("intField2").to(Value.int64(555L)).set("longField").to(Value.int64(5L)).set("doubleField").to(Value.float64(5.55)).set("doubleArray").to(Value.float64Array(new double[] { 5.55, 5.55 })).set("doubleList").to(Value.float64Array(doubleList)).set("stringList").to(Value.stringArray(stringList)).set("booleanList").to(Value.boolArray(new boolean[] {})).set("longList").to(Value.int64Array(new long[] {})).set("timestampList").to(Value.timestampArray(new ArrayList<>())).set("dateList").to(Value.dateArray(new ArrayList<>())).set("bytesList").to(Value.bytesArray(new ArrayList<>())).set("dateField").to(Value.date(Date.fromYearMonthDay(2019, 11, 22))).set("timestampField").to(Value.timestamp(Timestamp.ofTimeMicroseconds(555))).set("momentsInTime").to(Value.timestampArray(timestamps)).set("bytes").to(Value.bytes(ByteArray.copyFrom("string2"))).set("commitTimestamp").to(Value.timestamp(Timestamp.ofTimeMicroseconds(1))).set("bigDecimalField").to(Value.numeric(new BigDecimal("0.0001"))).set("bigDecimals").to(Value.numericArray(Arrays.asList(new BigDecimal("-0.999"), new BigDecimal("10.9001")))).build();
MockResults mockResults = new MockResults();
mockResults.structs = Arrays.asList(struct1, struct2);
ResultSet results = mock(ResultSet.class);
when(results.next()).thenAnswer((invocation) -> mockResults.next());
when(results.getCurrentRowAsStruct()).thenAnswer((invocation) -> mockResults.getCurrent());
List<TestEntity> entities = this.spannerEntityProcessor.mapToList(results, TestEntity.class);
verify(results, times(1)).close();
assertThat(entities).hasSize(2);
TestEntity t1 = entities.get(0);
TestEntity t2 = entities.get(1);
assertThat(t1.id).isEqualTo("key1");
assertThat(t1.testEmbeddedColumns.id2).isEqualTo("key2");
assertThat(t1.testEmbeddedColumns.id3).isEqualTo("key3");
assertThat(t1.id4).isEqualTo("key4");
assertThat(t1.enumField).isEqualTo(TestEntity.Color.WHITE);
assertThat(t1.booleanField).isEqualTo(true);
assertThat(t1.intField).isEqualTo(123);
assertThat(t1.testEmbeddedColumns.intField2).isEqualTo(333);
assertThat(t1.longField).isEqualTo(3L);
assertThat(t1.doubleField).isEqualTo(3.33, DELTA);
assertThat(t1.doubleArray.length).isEqualTo(3);
assertThat(t1.dateField.getYear()).isEqualTo(2018);
assertThat(t1.momentsInTime).isEqualTo(instants);
assertThat(t1.bytes).isEqualTo(ByteArray.copyFrom("string1"));
assertThat(t1.commitTimestamp).isEqualTo(Timestamp.ofTimeMicroseconds(1));
assertThat(t1.bigDecimalField).isEqualTo(BigDecimal.TEN);
assertThat(t1.bigDecimals).containsExactly(BigDecimal.ONE, BigDecimal.ZERO);
assertThat(t2.id).isEqualTo("key12");
assertThat(t2.testEmbeddedColumns.id2).isEqualTo("key22");
assertThat(t2.testEmbeddedColumns.id3).isEqualTo("key32");
assertThat(t2.id4).isEqualTo("key42");
assertThat(t2.enumField).isEqualTo(TestEntity.Color.BLACK);
assertThat(t2.booleanField).isEqualTo(true);
assertThat(t2.intField).isEqualTo(222);
assertThat(t2.testEmbeddedColumns.intField2).isEqualTo(555);
assertThat(t2.longField).isEqualTo(5L);
assertThat(t2.doubleField).isEqualTo(5.55, DELTA);
assertThat(t2.doubleArray.length).isEqualTo(2);
assertThat(t2.dateField.getYear()).isEqualTo(2019);
assertThat(t2.doubleList).hasSize(1);
assertThat(t2.doubleList.get(0)).isEqualTo(3.33, DELTA);
assertThat(t2.momentsInTime).isEqualTo(instants);
assertThat(t2.stringList).containsExactly("string");
assertThat(t2.bytes).isEqualTo(ByteArray.copyFrom("string2"));
assertThat(t2.commitTimestamp).isEqualTo(Timestamp.ofTimeMicroseconds(1));
assertThat(t2.bigDecimalField).isEqualTo(new BigDecimal("0.0001"));
assertThat(t2.bigDecimals).containsExactly(new BigDecimal("-0.999"), new BigDecimal("10.9001"));
}
use of com.google.cloud.spanner.ResultSet in project spring-cloud-gcp by spring-cloud.
the class ConverterAwareMappingSpannerEntityProcessorTests method mapToListPartialColumnsTest.
@Test
public void mapToListPartialColumnsTest() {
List<Double> doubleList = new ArrayList<>();
doubleList.add(3.33);
List<String> stringList = new ArrayList<>();
stringList.add("string");
Struct struct1 = Struct.newBuilder().set("id").to(Value.string("key1")).set("custom_col").to(Value.string("WHITE")).set("doubleList").to(Value.float64Array(doubleList)).set("stringList").to(Value.stringArray(stringList)).build();
Struct struct2 = Struct.newBuilder().set("id").to(Value.string("key2")).set("custom_col").to(Value.string("BLACK")).set("doubleList").to(Value.float64Array(doubleList)).set("stringList").to(Value.stringArray(stringList)).build();
MockResults mockResults = new MockResults();
mockResults.structs = Arrays.asList(struct1, struct2);
ResultSet results = mock(ResultSet.class);
when(results.next()).thenAnswer((invocation) -> mockResults.next());
when(results.getCurrentRowAsStruct()).thenAnswer((invocation) -> mockResults.getCurrent());
List<TestEntity> entities = this.spannerEntityProcessor.mapToList(results, TestEntity.class, "id", "custom_col");
verify(results, times(1)).close();
assertThat(entities).hasSize(2);
TestEntity t1 = entities.get(0);
TestEntity t2 = entities.get(1);
assertThat(t1.id).isEqualTo("key1");
assertThat(t1.enumField).isEqualTo(TestEntity.Color.WHITE);
// This should not have been set
assertThat(t1.doubleList).isNull();
assertThat(t2.id).isEqualTo("key2");
assertThat(t2.enumField).isEqualTo(TestEntity.Color.BLACK);
// This should not have been set
assertThat(t2.stringList).isNull();
}
Aggregations