Search in sources :

Example 6 with TestEntity

use of org.springframework.cloud.gcp.data.spanner.core.convert.TestEntities.TestEntity in project spring-cloud-gcp by spring-cloud.

the class ConverterAwareMappingSpannerEntityWriterTests method writeNullColumnsTest.

@Test
public void writeNullColumnsTest() {
    TestEntity t = new TestEntity();
    t.dateField = null;
    t.doubleList = null;
    WriteBuilder writeBuilder = mock(WriteBuilder.class);
    ValueBinder<WriteBuilder> dateFieldBinder = mock(ValueBinder.class);
    when(dateFieldBinder.to((Date) any())).thenReturn(null);
    when(writeBuilder.set(eq("dateField"))).thenReturn(dateFieldBinder);
    ValueBinder<WriteBuilder> doubleListFieldBinder = mock(ValueBinder.class);
    when(doubleListFieldBinder.toFloat64Array((Iterable<Double>) any())).thenReturn(null);
    when(writeBuilder.set(eq("doubleList"))).thenReturn(doubleListFieldBinder);
    this.spannerEntityWriter.write(t, writeBuilder::set, Collections.unmodifiableSet(new HashSet<String>(Arrays.asList("dateField", "doubleList"))));
    verify(dateFieldBinder, times(1)).to((Date) isNull());
    verify(doubleListFieldBinder, times(1)).toFloat64Array((Iterable<Double>) isNull());
}
Also used : FaultyTestEntity(org.springframework.cloud.gcp.data.spanner.core.convert.TestEntities.FaultyTestEntity) ChildTestEntity(org.springframework.cloud.gcp.data.spanner.core.convert.TestEntities.ChildTestEntity) TestEntity(org.springframework.cloud.gcp.data.spanner.core.convert.TestEntities.TestEntity) WriteBuilder(com.google.cloud.spanner.Mutation.WriteBuilder) ArgumentMatchers.anyDouble(org.mockito.ArgumentMatchers.anyDouble) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 TestEntity (org.springframework.cloud.gcp.data.spanner.core.convert.TestEntities.TestEntity)6 WriteBuilder (com.google.cloud.spanner.Mutation.WriteBuilder)4 ChildTestEntity (org.springframework.cloud.gcp.data.spanner.core.convert.TestEntities.ChildTestEntity)4 FaultyTestEntity (org.springframework.cloud.gcp.data.spanner.core.convert.TestEntities.FaultyTestEntity)4 ArrayList (java.util.ArrayList)3 Timestamp (com.google.cloud.Timestamp)2 ResultSet (com.google.cloud.spanner.ResultSet)2 Struct (com.google.cloud.spanner.Struct)2 BigDecimal (java.math.BigDecimal)2 Instant (java.time.Instant)2 ArgumentMatchers.anyDouble (org.mockito.ArgumentMatchers.anyDouble)2 HashSet (java.util.HashSet)1 TestEmbeddedColumns (org.springframework.cloud.gcp.data.spanner.core.convert.TestEntities.TestEmbeddedColumns)1