Skip to content

Commit

Permalink
Fixed float types in jsonTest.proto, and added a test that checks if …
Browse files Browse the repository at this point in the history
…repeated types are optional
  • Loading branch information
allenc3 committed Jul 9, 2020
1 parent 55e1775 commit 004aa87
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Expand Up @@ -257,17 +257,27 @@ public void testOptional() throws Exception {
AreMatchingFieldsFilledIn(protoMsg, json);
}

@Test
public void testRepeatedIsOptional() throws Exception {
JSONObject json = new JSONObject();
json.put("required_double", 1.1);

DynamicMessage protoMsg =
JsonToProtoMessage.convertJsonToProtoMessage(TestRepeatedIsOptional.getDescriptor(), json);
AreMatchingFieldsFilledIn(protoMsg, json);
}

@Test
public void testRequired() throws Exception {
JSONObject json = new JSONObject();
json.put("test_required_float", 1.1);
json.put("test_required_double", 1.1);
json.put("optional_double", 1.1);
try {
DynamicMessage protoMsg =
JsonToProtoMessage.convertJsonToProtoMessage(TestRequired.getDescriptor(), json);
} catch (IllegalArgumentException e) {
assertEquals(
e.getMessage(), "JSONObject does not have the required field root.required_float.");
e.getMessage(), "JSONObject does not have the required field root.required_double.");
}
}

Expand Down
9 changes: 7 additions & 2 deletions google-cloud-bigquerystorage/src/test/proto/jsonTest.proto
Expand Up @@ -83,7 +83,7 @@ message TestInt64 {

message TestDouble {
optional double double = 1;
optional float float = 2;
optional double float = 2;
}

message NestedRepeated {
Expand All @@ -94,5 +94,10 @@ message NestedRepeated {

message TestRequired {
optional double optional_double = 1;
required float required_float = 2;
required double required_double = 2;
}

message TestRepeatedIsOptional {
optional double required_double = 1;
repeated double repeated_double = 2;
}

0 comments on commit 004aa87

Please sign in to comment.