diff options
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 = |