diff options
author | Feng Xiao <xfxyjwf@gmail.com> | 2018-08-08 17:00:41 -0700 |
---|---|---|
committer | Feng Xiao <xfxyjwf@gmail.com> | 2018-08-08 17:00:41 -0700 |
commit | 6bbe197e9c1b6fc38cbdc45e3bf83fa7ced792a3 (patch) | |
tree | e575738adf52d24b883cca5e8928a5ded31caba1 /java/core/src/test/java/com/google/protobuf/TestUtil.java | |
parent | e7746f487cb9cca685ffb1b3d7dccc5554b618a4 (diff) | |
download | protobuf-6bbe197e9c1b6fc38cbdc45e3bf83fa7ced792a3.tar.gz protobuf-6bbe197e9c1b6fc38cbdc45e3bf83fa7ced792a3.tar.bz2 protobuf-6bbe197e9c1b6fc38cbdc45e3bf83fa7ced792a3.zip |
Down-integrate from google3.
Diffstat (limited to 'java/core/src/test/java/com/google/protobuf/TestUtil.java')
-rw-r--r-- | java/core/src/test/java/com/google/protobuf/TestUtil.java | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/java/core/src/test/java/com/google/protobuf/TestUtil.java b/java/core/src/test/java/com/google/protobuf/TestUtil.java index b4bc3a3d..8ec22d3f 100644 --- a/java/core/src/test/java/com/google/protobuf/TestUtil.java +++ b/java/core/src/test/java/com/google/protobuf/TestUtil.java @@ -130,8 +130,6 @@ import static protobuf_unittest.UnittestProto.defaultFixed64Extension; import static protobuf_unittest.UnittestProto.defaultFloatExtension; import static protobuf_unittest.UnittestProto.defaultForeignEnumExtension; import static protobuf_unittest.UnittestProto.defaultImportEnumExtension; -// The static imports are to avoid 100+ char lines. The following is roughly equivalent to -// import static protobuf_unittest.UnittestProto.*; import static protobuf_unittest.UnittestProto.defaultInt32Extension; import static protobuf_unittest.UnittestProto.defaultInt64Extension; import static protobuf_unittest.UnittestProto.defaultNestedEnumExtension; @@ -263,12 +261,14 @@ public final class TestUtil { return ByteString.copyFrom(str.getBytes(Internal.UTF_8)); } + // BEGIN FULL-RUNTIME /** * Dirties the message by resetting the momoized serialized size. */ public static void resetMemoizedSize(AbstractMessage message) { message.memoizedSize = -1; } + // END FULL-RUNTIME /** * Get a {@code TestAllTypes} with all fields set as they would be by @@ -1201,17 +1201,29 @@ public final class TestUtil { * Get an unmodifiable {@link ExtensionRegistry} containing all the * extensions of {@code TestAllExtensions}. */ - public static ExtensionRegistry getExtensionRegistry() { + public static ExtensionRegistryLite getExtensionRegistry() { + ExtensionRegistryLite registry = ExtensionRegistryLite.newInstance(); + registerAllExtensions(registry); + return registry.getUnmodifiable(); + } + + // BEGIN FULL-RUNTIME + /** + * Get an unmodifiable {@link ExtensionRegistry} containing all the + * extensions of {@code TestAllExtensions}. + */ + public static ExtensionRegistry getFullExtensionRegistry() { ExtensionRegistry registry = ExtensionRegistry.newInstance(); registerAllExtensions(registry); return registry.getUnmodifiable(); } + // END FULL-RUNTIME /** * Register all of {@code TestAllExtensions}'s extensions with the * given {@link ExtensionRegistry}. */ - public static void registerAllExtensions(ExtensionRegistry registry) { + public static void registerAllExtensions(ExtensionRegistryLite registry) { UnittestProto.registerAllExtensions(registry); TestUtilLite.registerAllExtensionsLite(registry); } @@ -2634,6 +2646,7 @@ public final class TestUtil { } // ================================================================= + // BEGIN FULL-RUNTIME /** * Performs the same things that the methods of {@code TestUtil} do, but @@ -3819,6 +3832,16 @@ public final class TestUtil { "Couldn't read file: " + fullPath.getPath(), e); } } + // END FULL-RUNTIME + + private static ByteString readBytesFromResource(String name) { + try { + return ByteString.copyFrom( + com.google.common.io.ByteStreams.toByteArray(TestUtil.class.getResourceAsStream(name))); + } catch (IOException e) { + throw new RuntimeException(e); + } + } /** * Get the bytes of the "golden message". This is a serialized TestAllTypes @@ -3829,7 +3852,7 @@ public final class TestUtil { */ public static ByteString getGoldenMessage() { if (goldenMessage == null) { - goldenMessage = readBytesFromFile("golden_message_oneof_implemented"); + goldenMessage = readBytesFromResource("/google/protobuf/testdata/golden_message_oneof_implemented"); } return goldenMessage; } @@ -3846,12 +3869,13 @@ public final class TestUtil { public static ByteString getGoldenPackedFieldsMessage() { if (goldenPackedFieldsMessage == null) { goldenPackedFieldsMessage = - readBytesFromFile("golden_packed_fields_message"); + readBytesFromResource("/google/protobuf/testdata/golden_packed_fields_message"); } return goldenPackedFieldsMessage; } private static ByteString goldenPackedFieldsMessage = null; + // BEGIN FULL-RUNTIME /** * Mock implementation of {@link GeneratedMessage.BuilderParent} for testing. * @@ -3871,4 +3895,5 @@ public final class TestUtil { return invalidations; } } + // END FULL-RUNTIME } |