Add more tests for UnknownFieldSet Builder reusability

Split up from testFieldBuildersAreReusable

This is to build confidence I'm not breaking things with my upcoming changes.

PiperOrigin-RevId: 653410161
pull/17454/head
Mark Hansen 4 months ago committed by Copybara-Service
parent af04a770ae
commit bc03650b3e
  1. 60
      java/core/src/test/java/com/google/protobuf/UnknownFieldSetTest.java

@ -80,7 +80,7 @@ public class UnknownFieldSetTest {
// =================================================================
@Test
public void testFieldBuildersAreReusable() {
public void testFixed32FieldBuildersAreReusable() {
UnknownFieldSet.Field.Builder fieldBuilder = UnknownFieldSet.Field.newBuilder();
fieldBuilder.addFixed32(10);
UnknownFieldSet.Field first = fieldBuilder.build();
@ -92,6 +92,64 @@ public class UnknownFieldSetTest {
assertThat(first).isNotEqualTo(third);
}
@Test
public void testFixed64FieldBuildersAreReusable() {
UnknownFieldSet.Field.Builder fieldBuilder = UnknownFieldSet.Field.newBuilder();
fieldBuilder.addFixed64(10);
UnknownFieldSet.Field first = fieldBuilder.build();
UnknownFieldSet.Field second = fieldBuilder.build();
fieldBuilder.addFixed64(11);
UnknownFieldSet.Field third = fieldBuilder.build();
assertThat(first).isEqualTo(second);
assertThat(first).isNotEqualTo(third);
}
@Test
public void testVarintFieldBuildersAreReusable() {
UnknownFieldSet.Field.Builder fieldBuilder = UnknownFieldSet.Field.newBuilder();
fieldBuilder.addVarint(10);
UnknownFieldSet.Field first = fieldBuilder.build();
UnknownFieldSet.Field second = fieldBuilder.build();
fieldBuilder.addVarint(11);
UnknownFieldSet.Field third = fieldBuilder.build();
assertThat(first).isEqualTo(second);
assertThat(first).isNotEqualTo(third);
}
@Test
public void testLengthDelimitedFieldBuildersAreReusable() {
UnknownFieldSet.Field.Builder fieldBuilder = UnknownFieldSet.Field.newBuilder();
fieldBuilder.addLengthDelimited(ByteString.copyFromUtf8("foo"));
UnknownFieldSet.Field first = fieldBuilder.build();
UnknownFieldSet.Field second = fieldBuilder.build();
fieldBuilder.addLengthDelimited(ByteString.copyFromUtf8("bar"));
UnknownFieldSet.Field third = fieldBuilder.build();
assertThat(first).isEqualTo(second);
assertThat(first).isNotEqualTo(third);
}
@Test
public void testGroupFieldBuildersAreReusable() {
UnknownFieldSet.Field.Builder fieldBuilder = UnknownFieldSet.Field.newBuilder();
fieldBuilder.addGroup(
UnknownFieldSet.newBuilder()
.addField(10, UnknownFieldSet.Field.newBuilder().addVarint(10).build())
.build());
UnknownFieldSet.Field first = fieldBuilder.build();
UnknownFieldSet.Field second = fieldBuilder.build();
fieldBuilder.addGroup(
UnknownFieldSet.newBuilder()
.addField(11, UnknownFieldSet.Field.newBuilder().addVarint(11).build())
.build());
UnknownFieldSet.Field third = fieldBuilder.build();
assertThat(first).isEqualTo(second);
assertThat(first).isNotEqualTo(third);
}
@Test
public void testClone() {
UnknownFieldSet.Builder unknownSetBuilder = UnknownFieldSet.newBuilder();

Loading…
Cancel
Save