| Index: third_party/protobuf/java/core/src/test/java/com/google/protobuf/LazyFieldLiteTest.java
|
| diff --git a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/LazyFieldLiteTest.java b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/LazyFieldLiteTest.java
|
| index 813fe6bc69688ae0dff654265f1a26cfd0b0b70b..8d1de6dc810ec5f7a90b626f986f9957892925c2 100644
|
| --- a/third_party/protobuf/java/core/src/test/java/com/google/protobuf/LazyFieldLiteTest.java
|
| +++ b/third_party/protobuf/java/core/src/test/java/com/google/protobuf/LazyFieldLiteTest.java
|
| @@ -31,12 +31,15 @@
|
| package com.google.protobuf;
|
|
|
| import static protobuf_unittest.UnittestProto.optionalInt32Extension;
|
| +import static protobuf_unittest.UnittestProto.optionalInt64Extension;
|
|
|
| import protobuf_unittest.UnittestProto.TestAllExtensions;
|
| import protobuf_unittest.UnittestProto.TestAllTypes;
|
| -import java.io.IOException;
|
| +
|
| import junit.framework.TestCase;
|
|
|
| +import java.io.IOException;
|
| +
|
| /**
|
| * Unit test for {@link LazyFieldLite}.
|
| *
|
| @@ -218,6 +221,29 @@ public class LazyFieldLiteTest extends TestCase {
|
| assertEquals(messageWithExtensions, field.getValue(TestAllExtensions.getDefaultInstance()));
|
| }
|
|
|
| + public void testMergeMightLoseExtensions() throws Exception {
|
| + // Test that we don't know about the extensions when parsing.
|
| + TestAllExtensions message1 =
|
| + TestAllExtensions.newBuilder().setExtension(optionalInt32Extension, 1).build();
|
| + TestAllExtensions message2 =
|
| + TestAllExtensions.newBuilder().setExtension(optionalInt64Extension, 2L).build();
|
| +
|
| + LazyFieldLite field = LazyFieldLite.fromValue(message1);
|
| + field.merge(LazyFieldLite.fromValue(message2));
|
| +
|
| + // We lose the extensions from message 2 because we have to serialize it and then parse it
|
| + // again, using the empty registry this time.
|
| + TestAllExtensions value =
|
| + (TestAllExtensions) field.getValue(TestAllExtensions.getDefaultInstance());
|
| + assertTrue(value.hasExtension(optionalInt32Extension));
|
| + assertEquals(Integer.valueOf(1), value.getExtension(optionalInt32Extension));
|
| + assertFalse(value.hasExtension(optionalInt64Extension));
|
| +
|
| + // The field is still there, it is just unknown.
|
| + assertTrue(value.getUnknownFields()
|
| + .hasField(optionalInt64Extension.getDescriptor().getNumber()));
|
| + }
|
| +
|
|
|
| // Help methods.
|
|
|
|
|