public void testEqualsAndHashCode() throws Exception { TestAllTypes a = TestUtil.getAllSet(); TestAllTypes b = TestAllTypes.newBuilder().build(); TestAllTypes c = TestAllTypes.newBuilder(b).addRepeatedString("x").build(); TestAllTypes d = TestAllTypes.newBuilder(c).addRepeatedString("y").build(); TestAllExtensions e = TestUtil.getAllExtensionsSet(); TestAllExtensions f = TestAllExtensions.newBuilder(e) .addExtension(UnittestProto.repeatedInt32Extension, 999) .build(); checkEqualsIsConsistent(a); checkEqualsIsConsistent(b); checkEqualsIsConsistent(c); checkEqualsIsConsistent(d); checkEqualsIsConsistent(e); checkEqualsIsConsistent(f); checkNotEqual(a, b); checkNotEqual(a, c); checkNotEqual(a, d); checkNotEqual(a, e); checkNotEqual(a, f); checkNotEqual(b, c); checkNotEqual(b, d); checkNotEqual(b, e); checkNotEqual(b, f); checkNotEqual(c, d); checkNotEqual(c, e); checkNotEqual(c, f); checkNotEqual(d, e); checkNotEqual(d, f); checkNotEqual(e, f); // Deserializing into the TestEmptyMessage such that every field // is an {@link UnknownFieldSet.Field}. UnittestProto.TestEmptyMessage eUnknownFields = UnittestProto.TestEmptyMessage.parseFrom(e.toByteArray()); UnittestProto.TestEmptyMessage fUnknownFields = UnittestProto.TestEmptyMessage.parseFrom(f.toByteArray()); checkNotEqual(eUnknownFields, fUnknownFields); checkEqualsIsConsistent(eUnknownFields); checkEqualsIsConsistent(fUnknownFields); // Subsequent reconstitutions should be identical UnittestProto.TestEmptyMessage eUnknownFields2 = UnittestProto.TestEmptyMessage.parseFrom(e.toByteArray()); checkEqualsIsConsistent(eUnknownFields, eUnknownFields2); }
public void testEqualsAndHashCode() { TestAllTypes a = TestUtil.getAllSet(); TestAllTypes b = TestAllTypes.newBuilder().build(); TestAllTypes c = TestAllTypes.newBuilder(b).addRepeatedString("x").build(); TestAllTypes d = TestAllTypes.newBuilder(c).addRepeatedString("y").build(); TestAllExtensions e = TestUtil.getAllExtensionsSet(); TestAllExtensions f = TestAllExtensions.newBuilder(e) .addExtension(UnittestProto.repeatedInt32Extension, 999) .build(); checkEqualsIsConsistent(a); checkEqualsIsConsistent(b); checkEqualsIsConsistent(c); checkEqualsIsConsistent(d); checkEqualsIsConsistent(e); checkEqualsIsConsistent(f); checkNotEqual(a, b); checkNotEqual(a, c); checkNotEqual(a, d); checkNotEqual(a, e); checkNotEqual(a, f); checkNotEqual(b, c); checkNotEqual(b, d); checkNotEqual(b, e); checkNotEqual(b, f); checkNotEqual(c, d); checkNotEqual(c, e); checkNotEqual(c, f); checkNotEqual(d, e); checkNotEqual(d, f); checkNotEqual(e, f); }