From 662f97841e838802987e5d208c1d898226c06ef1 Mon Sep 17 00:00:00 2001 From: Anuraag Agrawal Date: Tue, 4 Apr 2017 17:25:12 +0900 Subject: Fix duplicate fields test. The repeated version is passing because null values in a repeated field are rejected and not testing what it wanted to. Also adds a oneof version that verifies the case of oneof fields of different names (currently only same name check seems to be tested). Also fix spelling of a test. --- .../java/com/google/protobuf/util/JsonFormatTest.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'java') diff --git a/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java b/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java index de02c117..395d7458 100644 --- a/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java +++ b/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java @@ -264,7 +264,7 @@ public class JsonFormatTest extends TestCase { assertRoundTripEquals(message); } - public void testParserAcceptStringForNumbericField() throws Exception { + public void testParserAcceptStringForNumericField() throws Exception { TestAllTypes.Builder builder = TestAllTypes.newBuilder(); mergeFromJson( "{\n" @@ -479,8 +479,8 @@ public class JsonFormatTest extends TestCase { TestAllTypes.Builder builder = TestAllTypes.newBuilder(); mergeFromJson( "{\n" - + " \"repeatedNestedMessage\": [null, null],\n" - + " \"repeated_nested_message\": [null, null]\n" + + " \"repeatedInt32\": [1, 2],\n" + + " \"repeated_int32\": [5, 6]\n" + "}", builder); fail(); @@ -488,7 +488,7 @@ public class JsonFormatTest extends TestCase { // Exception expected. } - // Duplicated oneof fields. + // Duplicated oneof fields, same name. try { TestOneof.Builder builder = TestOneof.newBuilder(); mergeFromJson("{\n" + " \"oneofInt32\": 1,\n" + " \"oneof_int32\": 2\n" + "}", builder); @@ -496,6 +496,16 @@ public class JsonFormatTest extends TestCase { } catch (InvalidProtocolBufferException e) { // Exception expected. } + + // Duplicated oneof fields, different name. + try { + TestOneof.Builder builder = TestOneof.newBuilder(); + mergeFromJson( + "{\n" + " \"oneofInt32\": 1,\n" + " \"oneofNullValue\": null\n" + "}", builder); + fail(); + } catch (InvalidProtocolBufferException e) { + // Exception expected. + } } public void testMapFields() throws Exception { -- cgit v1.2.3 From 09328db1ff546e5c535ee0c3fbbe2b1f3ec07b63 Mon Sep 17 00:00:00 2001 From: Anuraag Agrawal Date: Tue, 4 Apr 2017 18:58:46 +0900 Subject: Fix test for unexpected type url when parsing Any. Currently, the test fails since TestAllTypes doesn't have field '@type', which is the same test as testUnknownFields. --- java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'java') diff --git a/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java b/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java index 395d7458..808e542d 100644 --- a/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java +++ b/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java @@ -1099,7 +1099,7 @@ public class JsonFormatTest extends TestCase { public void testParserUnexpectedTypeUrl() throws Exception { try { - TestAllTypes.Builder builder = TestAllTypes.newBuilder(); + Any.Builder builder = Any.newBuilder(); mergeFromJson( "{\n" + " \"@type\": \"type.googleapis.com/json_test.TestAllTypes\",\n" -- cgit v1.2.3