Skip to content

Commit cfa3e14

Browse files
ajaaymsduskis
authored andcommitted
---
yaml --- r: 17643 b: refs/heads/autosynth-texttospeech c: d6b2c21 h: refs/heads/master i: 17641: da9eb1d 17639: 83bb502
1 parent 45c0bef commit cfa3e14

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

  • branches/autosynth-texttospeech/google-cloud-clients/google-cloud-spanner/src

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ refs/heads/autosynth-securitycenter: 8e95447ccb176c3648880ee0cb926cd1f4065156
143143
refs/heads/autosynth-spanner: 9bff86d057df31e04c76d72865e8e073ac5794fb
144144
refs/heads/autosynth-speech: 75d6c62a9d07d3a3642980502a25d07fbde0f232
145145
refs/heads/autosynth-tasks: b0cdb991f3f75345151a3f68db1aab273dfc069b
146-
refs/heads/autosynth-texttospeech: 64f3b2be23eab15df420e5890f14409fa52c8411
146+
refs/heads/autosynth-texttospeech: d6b2c21e731a4307128d79d65daa64893e421a5a
147147
refs/heads/autosynth-trace: 80c58aa2fb54b0a9c6876f2c21aa8d19cf55962e
148148
refs/heads/autosynth-websecurityscanner: d4febbffb6c648b74faec62fe90e20adadc9a7d3
149149
refs/heads/bigquerystorage: 06db74d123d7f8a3ef48755c2fcabed09faf8e64

branches/autosynth-texttospeech/google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/Key.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,9 @@ ListValue toProto() {
281281
} else if (part instanceof ByteArray) {
282282
builder.addValuesBuilder().setStringValue(((ByteArray) part).toBase64());
283283
} else if (part instanceof Timestamp) {
284-
builder.addValuesBuilder().setStringValue(((Timestamp) part).toString());
284+
builder.addValuesBuilder().setStringValue(part.toString());
285+
} else if (part instanceof Date) {
286+
builder.addValuesBuilder().setStringValue(part.toString());
285287
} else {
286288
throw new AssertionError("Illegal key part: " + part.getClass());
287289
}

branches/autosynth-texttospeech/google-cloud-clients/google-cloud-spanner/src/test/java/com/google/cloud/spanner/KeyTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import com.google.cloud.Date;
2424
import com.google.cloud.Timestamp;
2525
import com.google.common.testing.EqualsTester;
26+
import com.google.protobuf.ListValue;
27+
import com.google.protobuf.NullValue;
2628
import org.junit.Test;
2729
import org.junit.runner.RunWith;
2830
import org.junit.runners.JUnit4;
@@ -189,4 +191,35 @@ public void serialization() throws Exception {
189191
reserializeAndAssert(Key.of(Date.parseDate("2015-09-15")));
190192
reserializeAndAssert(Key.of(1, 2, 3));
191193
}
194+
195+
@Test
196+
public void toProto() {
197+
String timestamp = "2015-09-15T00:00:00Z";
198+
String date = "2015-09-15";
199+
Key k =
200+
Key.newBuilder()
201+
.append((Boolean) null)
202+
.append(true)
203+
.append(32)
204+
.append(64L)
205+
.append(2.0f)
206+
.append(4.0d)
207+
.append("x")
208+
.append(ByteArray.copyFrom("y"))
209+
.append(Timestamp.parseTimestamp(timestamp))
210+
.append(Date.parseDate(date))
211+
.build();
212+
ListValue.Builder builder = ListValue.newBuilder();
213+
builder.addValuesBuilder().setNullValue(NullValue.NULL_VALUE);
214+
builder.addValuesBuilder().setBoolValue(true);
215+
builder.addValuesBuilder().setStringValue("32");
216+
builder.addValuesBuilder().setStringValue("64");
217+
builder.addValuesBuilder().setNumberValue(2.0f);
218+
builder.addValuesBuilder().setNumberValue(4.0d);
219+
builder.addValuesBuilder().setStringValue("x");
220+
builder.addValuesBuilder().setStringValue("eQ==");
221+
builder.addValuesBuilder().setStringValue(timestamp);
222+
builder.addValuesBuilder().setStringValue(date);
223+
assertThat(k.toProto()).isEqualTo(builder.build());
224+
}
192225
}

0 commit comments

Comments
 (0)