diff options
author | Jisi Liu <jisi.liu@gmail.com> | 2017-10-18 12:22:18 -0700 |
---|---|---|
committer | Jisi Liu <jisi.liu@gmail.com> | 2017-10-18 12:22:18 -0700 |
commit | 1a7a7fca804afa1cf67f8be5e71092898ba40334 (patch) | |
tree | 04b3da27c71c607510f34a12cf7856a1b94181ae /java/core/src/test | |
parent | c4f59dcc5c13debc572154c8f636b8a9361aacde (diff) | |
download | protobuf-1a7a7fca804afa1cf67f8be5e71092898ba40334.tar.gz protobuf-1a7a7fca804afa1cf67f8be5e71092898ba40334.tar.bz2 protobuf-1a7a7fca804afa1cf67f8be5e71092898ba40334.zip |
Merge from google internal
Diffstat (limited to 'java/core/src/test')
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java | 30 | ||||
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/LiteTest.java | 9 |
2 files changed, 9 insertions, 30 deletions
diff --git a/java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java b/java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java index ff686a0c..42da5bb3 100644 --- a/java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java +++ b/java/core/src/test/java/com/google/protobuf/FieldPresenceTest.java @@ -404,34 +404,4 @@ public class FieldPresenceTest extends TestCase { assertTrue(builder.buildPartial().isInitialized()); } - - // Test that unknown fields are dropped. - public void testUnknownFields() throws Exception { - TestAllTypes.Builder builder = TestAllTypes.newBuilder(); - builder.setOptionalInt32(1234); - builder.addRepeatedInt32(5678); - TestAllTypes message = builder.build(); - ByteString data = message.toByteString(); - - TestOptionalFieldsOnly optionalOnlyMessage = - TestOptionalFieldsOnly.parseFrom(data); - // UnknownFieldSet should be empty. - assertEquals( - 0, optionalOnlyMessage.getUnknownFields().toByteString().size()); - assertEquals(1234, optionalOnlyMessage.getOptionalInt32()); - message = TestAllTypes.parseFrom(optionalOnlyMessage.toByteString()); - assertEquals(1234, message.getOptionalInt32()); - // The repeated field is discarded because it's unknown to the optional-only - // message. - assertEquals(0, message.getRepeatedInt32Count()); - - DynamicMessage dynamicOptionalOnlyMessage = - DynamicMessage.getDefaultInstance( - TestOptionalFieldsOnly.getDescriptor()) - .getParserForType().parseFrom(data); - assertEquals( - 0, dynamicOptionalOnlyMessage.getUnknownFields().toByteString().size()); - assertEquals(optionalOnlyMessage.toByteString(), - dynamicOptionalOnlyMessage.toByteString()); - } } diff --git a/java/core/src/test/java/com/google/protobuf/LiteTest.java b/java/core/src/test/java/com/google/protobuf/LiteTest.java index ba4d539d..40b44538 100644 --- a/java/core/src/test/java/com/google/protobuf/LiteTest.java +++ b/java/core/src/test/java/com/google/protobuf/LiteTest.java @@ -1453,6 +1453,15 @@ public class LiteTest extends TestCase { UnittestLite.optionalFixed32ExtensionLite)); } + public void testBuilderMergeFromNull() throws Exception { + try { + TestAllTypesLite.newBuilder().mergeFrom((TestAllTypesLite) null); + fail("Expected exception"); + } catch (NullPointerException e) { + // Pass. + } + } + // Builder.mergeFrom() should keep existing extensions. public void testBuilderMergeFromWithExtensions() throws Exception { TestAllExtensionsLite message = |