Skip to content

Commit 9a3b5d4

Browse files
test: Adding additional assert checks for exception being thrown for invalid json (#2011)
1 parent d54f252 commit 9a3b5d4

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

google-cloud-spanner/src/test/java/com/google/cloud/spanner/it/ITJsonWriteReadTest.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import com.google.cloud.spanner.Database;
2424
import com.google.cloud.spanner.DatabaseClient;
25+
import com.google.cloud.spanner.ErrorCode;
2526
import com.google.cloud.spanner.IntegrationTestEnv;
2627
import com.google.cloud.spanner.Mutation;
2728
import com.google.cloud.spanner.ParallelIntegrationTest;
@@ -125,17 +126,21 @@ public void testWriteAndReadInvalidJsonValues() throws IOException {
125126
Resources.toString(
126127
Resources.getResource(this.getClass(), INVALID_JSON_DIR + File.separator + resource),
127128
StandardCharsets.UTF_8);
128-
assertThrows(
129-
SpannerException.class,
130-
() ->
131-
databaseClient.write(
132-
Collections.singletonList(
133-
Mutation.newInsertBuilder(TABLE_NAME)
134-
.set("Id")
135-
.to(id.getAndIncrement())
136-
.set("json")
137-
.to(Value.json(jsonStr))
138-
.build())));
129+
130+
SpannerException exception =
131+
assertThrows(
132+
SpannerException.class,
133+
() ->
134+
databaseClient.write(
135+
Collections.singletonList(
136+
Mutation.newInsertBuilder(TABLE_NAME)
137+
.set("Id")
138+
.to(id.getAndIncrement())
139+
.set("json")
140+
.to(Value.json(jsonStr))
141+
.build())));
142+
143+
assertEquals(ErrorCode.FAILED_PRECONDITION, exception.getErrorCode());
139144
}
140145
}
141146

0 commit comments

Comments
 (0)