Skip to content

Commit

Permalink
Replace usingTypeRegistry(TypeRegistry) with unpackingAnyUsing(TypeRe…
Browse files Browse the repository at this point in the history
…gistry, ExtensionRegistry).

RELNOTES=Note to person doing the release: Update the earlier release note about usingTypeRegistry to refer to unpackingAnyUsing instead.
PiperOrigin-RevId: 334903297
  • Loading branch information
cpovirk committed Oct 1, 2020
1 parent d32fe90 commit 97ca9f7
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.google.errorprone.annotations.CheckReturnValue;
import com.google.protobuf.Descriptors.Descriptor;
import com.google.protobuf.Descriptors.FieldDescriptor;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.Message;
import com.google.protobuf.TypeRegistry;
import org.checkerframework.checker.nullness.qual.Nullable;
Expand All @@ -57,7 +58,7 @@ abstract class FluentEqualityConfig implements FieldScopeLogicContainer<FluentEq
.setCompareExpectedFieldsOnly(false)
.setCompareFieldsScope(FieldScopeLogic.all())
.setReportMismatchesOnly(false)
.setUseTypeRegistry(TypeRegistry.getEmptyTypeRegistry())
.setUnpackingAnyUsing(TypeRegistry.getEmptyTypeRegistry(), ExtensionRegistry.getEmptyRegistry())
.setUsingCorrespondenceStringFunction(Functions.constant(""))
.build();

Expand Down Expand Up @@ -106,6 +107,8 @@ public ProtoTruthMessageDifferencer load(Descriptor descriptor) {

abstract TypeRegistry useTypeRegistry();

abstract ExtensionRegistry useExtensionRegistry();

// For pretty-printing, does not affect behavior.
abstract Function<? super Optional<Descriptor>, String> usingCorrespondenceStringFunction();

Expand Down Expand Up @@ -322,10 +325,12 @@ final FluentEqualityConfig reportingMismatchesOnly() {
.build();
}

final FluentEqualityConfig usingTypeRegistry(TypeRegistry typeRegistry) {
final FluentEqualityConfig unpackingAnyUsing(
TypeRegistry typeRegistry, ExtensionRegistry extensionRegistry) {
return toBuilder()
.setUseTypeRegistry(typeRegistry)
.addUsingCorrespondenceString(".usingTypeRegistry(" + typeRegistry + ")")
.setUnpackingAnyUsing(typeRegistry, extensionRegistry)
.addUsingCorrespondenceString(
".unpackingAnyUsing(" + typeRegistry + ", " + extensionRegistry + ")")
.build();
}

Expand Down Expand Up @@ -443,8 +448,17 @@ abstract Builder setFloatCorrespondenceMap(

abstract Builder setReportMismatchesOnly(boolean reportMismatchesOnly);

final Builder setUnpackingAnyUsing(
TypeRegistry typeRegistry, ExtensionRegistry extensionRegistry) {
setUseTypeRegistry(typeRegistry);
setUseExtensionRegistry(extensionRegistry);
return this;
}

abstract Builder setUseTypeRegistry(TypeRegistry typeRegistry);

abstract Builder setUseExtensionRegistry(ExtensionRegistry extensionRegistry);

@CheckReturnValue
abstract Function<? super Optional<Descriptor>, String> usingCorrespondenceStringFunction();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.google.common.truth.extensions.proto;

import com.google.protobuf.Descriptors.FieldDescriptor;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.Message;
import com.google.protobuf.TypeRegistry;

Expand Down Expand Up @@ -462,10 +463,11 @@ IterableOfProtosFluentAssertion<M> ignoringFieldDescriptors(
IterableOfProtosFluentAssertion<M> reportingMismatchesOnly();

/**
* Specifies the {@link TypeRegistry} to use for {@link com.google.protobuf.Any Any} messages.
* Specifies the {@link TypeRegistry} and {@link ExtensionRegistry} to use for {@link
* com.google.protobuf.Any Any} messages.
*
* <p>To compare the value of an {@code Any} message, ProtoTruth looks in the given registry for a
* descriptor for the message's type URL.
* <p>To compare the value of an {@code Any} message, ProtoTruth looks in the given type registry
* for a descriptor for the message's type URL:
*
* <ul>
* <li>If ProtoTruth finds a descriptor, it unpacks the value and compares it against the
Expand All @@ -474,9 +476,14 @@ IterableOfProtosFluentAssertion<M> ignoringFieldDescriptors(
* descriptor), it compares the raw, serialized bytes of the expected and actual values.
* </ul>
*
* <p>When ProtoTruth unpacks a value, it is parsing a serialized proto. That proto may contain
* extensions. To look up those extensions, ProtoTruth uses the provided {@link
* ExtensionRegistry}.
*
* @since 1.1
*/
IterableOfProtosFluentAssertion<M> usingTypeRegistry(TypeRegistry typeRegistry);
IterableOfProtosFluentAssertion<M> unpackingAnyUsing(
TypeRegistry typeRegistry, ExtensionRegistry extensionRegistry);

/**
* @deprecated Do not call {@code equals()} on a {@code IterableOfProtosFluentAssertion}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.common.truth.Ordered;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.protobuf.Descriptors.FieldDescriptor;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.Message;
import com.google.protobuf.TypeRegistry;
import java.util.Arrays;
Expand Down Expand Up @@ -631,10 +632,11 @@ public IterableOfProtosFluentAssertion<M> reportingMismatchesOnly() {
}

/**
* Specifies the {@link TypeRegistry} to use for {@link com.google.protobuf.Any Any} messages.
* Specifies the {@link TypeRegistry} and {@link ExtensionRegistry} to use for {@link
* com.google.protobuf.Any Any} messages.
*
* <p>To compare the value of an {@code Any} message, ProtoTruth looks in the given registry for a
* descriptor for the message's type URL.
* <p>To compare the value of an {@code Any} message, ProtoTruth looks in the given type registry
* for a descriptor for the message's type URL:
*
* <ul>
* <li>If ProtoTruth finds a descriptor, it unpacks the value and compares it against the
Expand All @@ -643,10 +645,15 @@ public IterableOfProtosFluentAssertion<M> reportingMismatchesOnly() {
* descriptor), it compares the raw, serialized bytes of the expected and actual values.
* </ul>
*
* <p>When ProtoTruth unpacks a value, it is parsing a serialized proto. That proto may contain
* extensions. To look up those extensions, ProtoTruth uses the provided {@link
* ExtensionRegistry}.
*
* @since 1.1
*/
public IterableOfProtosFluentAssertion<M> usingTypeRegistry(TypeRegistry typeRegistry) {
return usingConfig(config.usingTypeRegistry(typeRegistry));
public IterableOfProtosFluentAssertion<M> unpackingAnyUsing(
TypeRegistry typeRegistry, ExtensionRegistry extensionRegistry) {
return usingConfig(config.unpackingAnyUsing(typeRegistry, extensionRegistry));
}

//////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -1000,8 +1007,9 @@ public IterableOfProtosFluentAssertion<M> reportingMismatchesOnly() {
}

@Override
public IterableOfProtosFluentAssertion<M> usingTypeRegistry(TypeRegistry typeRegistry) {
return subject.usingTypeRegistry(typeRegistry);
public IterableOfProtosFluentAssertion<M> unpackingAnyUsing(
TypeRegistry typeRegistry, ExtensionRegistry extensionRegistry) {
return subject.unpackingAnyUsing(typeRegistry, extensionRegistry);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.google.common.truth.Ordered;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.protobuf.Descriptors.FieldDescriptor;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.Message;
import com.google.protobuf.TypeRegistry;
import java.util.Map;
Expand Down Expand Up @@ -478,10 +479,11 @@ MapWithProtoValuesFluentAssertion<M> ignoringFieldDescriptorsForValues(
MapWithProtoValuesFluentAssertion<M> reportingMismatchesOnlyForValues();

/**
* Specifies the {@link TypeRegistry} to use for {@link com.google.protobuf.Any Any} messages.
* Specifies the {@link TypeRegistry} and {@link ExtensionRegistry} to use for {@link
* com.google.protobuf.Any Any} messages.
*
* <p>To compare the value of an {@code Any} message, ProtoTruth looks in the given registry for a
* descriptor for the message's type URL.
* <p>To compare the value of an {@code Any} message, ProtoTruth looks in the given type registry
* for a descriptor for the message's type URL:
*
* <ul>
* <li>If ProtoTruth finds a descriptor, it unpacks the value and compares it against the
Expand All @@ -490,9 +492,14 @@ MapWithProtoValuesFluentAssertion<M> ignoringFieldDescriptorsForValues(
* descriptor), it compares the raw, serialized bytes of the expected and actual values.
* </ul>
*
* <p>When ProtoTruth unpacks a value, it is parsing a serialized proto. That proto may contain
* extensions. To look up those extensions, ProtoTruth uses the provided {@link
* ExtensionRegistry}.
*
* @since 1.1
*/
MapWithProtoValuesFluentAssertion<M> usingTypeRegistryForValues(TypeRegistry typeRegistry);
MapWithProtoValuesFluentAssertion<M> unpackingAnyUsingForValues(
TypeRegistry typeRegistry, ExtensionRegistry extensionRegistry);

/**
* Fails if the map does not contain an entry with the given key and a value that corresponds to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.google.common.truth.Ordered;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.protobuf.Descriptors.FieldDescriptor;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.Message;
import com.google.protobuf.TypeRegistry;
import java.util.ArrayList;
Expand Down Expand Up @@ -600,10 +601,11 @@ public MapWithProtoValuesFluentAssertion<M> reportingMismatchesOnlyForValues() {
}

/**
* Specifies the {@link TypeRegistry} to use for {@link com.google.protobuf.Any Any} messages.
* Specifies the {@link TypeRegistry} and {@link ExtensionRegistry} to use for {@link
* com.google.protobuf.Any Any} messages.
*
* <p>To compare the value of an {@code Any} message, ProtoTruth looks in the given registry for a
* descriptor for the message's type URL.
* <p>To compare the value of an {@code Any} message, ProtoTruth looks in the given type registry
* for a descriptor for the message's type URL:
*
* <ul>
* <li>If ProtoTruth finds a descriptor, it unpacks the value and compares it against the
Expand All @@ -612,11 +614,15 @@ public MapWithProtoValuesFluentAssertion<M> reportingMismatchesOnlyForValues() {
* descriptor), it compares the raw, serialized bytes of the expected and actual values.
* </ul>
*
* <p>When ProtoTruth unpacks a value, it is parsing a serialized proto. That proto may contain
* extensions. To look up those extensions, ProtoTruth uses the provided {@link
* ExtensionRegistry}.
*
* @since 1.1
*/
public MapWithProtoValuesFluentAssertion<M> usingTypeRegistryForValues(
TypeRegistry typeRegistry) {
return usingConfig(config.usingTypeRegistry(typeRegistry));
public MapWithProtoValuesFluentAssertion<M> unpackingAnyUsingForValues(
TypeRegistry typeRegistry, ExtensionRegistry extensionRegistry) {
return usingConfig(config.unpackingAnyUsing(typeRegistry, extensionRegistry));
}

//////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -842,9 +848,9 @@ public MapWithProtoValuesFluentAssertion<M> reportingMismatchesOnlyForValues() {
}

@Override
public MapWithProtoValuesFluentAssertion<M> usingTypeRegistryForValues(
TypeRegistry typeRegistry) {
return subject.usingTypeRegistryForValues(typeRegistry);
public MapWithProtoValuesFluentAssertion<M> unpackingAnyUsingForValues(
TypeRegistry typeRegistry, ExtensionRegistry extensionRegistry) {
return subject.unpackingAnyUsingForValues(typeRegistry, extensionRegistry);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.google.common.truth.Ordered;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.protobuf.Descriptors.FieldDescriptor;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.Message;
import com.google.protobuf.TypeRegistry;
import org.checkerframework.checker.nullness.qual.Nullable;
Expand Down Expand Up @@ -479,10 +480,11 @@ MultimapWithProtoValuesFluentAssertion<M> ignoringFieldDescriptorsForValues(
MultimapWithProtoValuesFluentAssertion<M> reportingMismatchesOnlyForValues();

/**
* Specifies the {@link TypeRegistry} to use for {@link com.google.protobuf.Any Any} messages.
* Specifies the {@link TypeRegistry} and {@link ExtensionRegistry} to use for {@link
* com.google.protobuf.Any Any} messages.
*
* <p>To compare the value of an {@code Any} message, ProtoTruth looks in the given registry for a
* descriptor for the message's type URL.
* <p>To compare the value of an {@code Any} message, ProtoTruth looks in the given type registry
* for a descriptor for the message's type URL:
*
* <ul>
* <li>If ProtoTruth finds a descriptor, it unpacks the value and compares it against the
Expand All @@ -491,9 +493,14 @@ MultimapWithProtoValuesFluentAssertion<M> ignoringFieldDescriptorsForValues(
* descriptor), it compares the raw, serialized bytes of the expected and actual values.
* </ul>
*
* <p>When ProtoTruth unpacks a value, it is parsing a serialized proto. That proto may contain
* extensions. To look up those extensions, ProtoTruth uses the provided {@link
* ExtensionRegistry}.
*
* @since 1.1
*/
MultimapWithProtoValuesFluentAssertion<M> usingTypeRegistryForValues(TypeRegistry typeRegistry);
MultimapWithProtoValuesFluentAssertion<M> unpackingAnyUsingForValues(
TypeRegistry typeRegistry, ExtensionRegistry extensionRegistry);

/**
* Fails if the multimap does not contain an entry with the given key and a value that corresponds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.common.truth.Subject;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.protobuf.Descriptors.FieldDescriptor;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.Message;
import com.google.protobuf.TypeRegistry;
import java.util.ArrayList;
Expand Down Expand Up @@ -623,10 +624,11 @@ public MultimapWithProtoValuesFluentAssertion<M> reportingMismatchesOnlyForValue
}

/**
* Specifies the {@link TypeRegistry} to use for {@link com.google.protobuf.Any Any} messages.
* Specifies the {@link TypeRegistry} and {@link ExtensionRegistry} to use for {@link
* com.google.protobuf.Any Any} messages.
*
* <p>To compare the value of an {@code Any} message, ProtoTruth looks in the given registry for a
* descriptor for the message's type URL.
* <p>To compare the value of an {@code Any} message, ProtoTruth looks in the given type registry
* for a descriptor for the message's type URL:
*
* <ul>
* <li>If ProtoTruth finds a descriptor, it unpacks the value and compares it against the
Expand All @@ -635,11 +637,15 @@ public MultimapWithProtoValuesFluentAssertion<M> reportingMismatchesOnlyForValue
* descriptor), it compares the raw, serialized bytes of the expected and actual values.
* </ul>
*
* <p>When ProtoTruth unpacks a value, it is parsing a serialized proto. That proto may contain
* extensions. To look up those extensions, ProtoTruth uses the provided {@link
* ExtensionRegistry}.
*
* @since 1.1
*/
public MultimapWithProtoValuesFluentAssertion<M> usingTypeRegistryForValues(
TypeRegistry typeRegistry) {
return usingConfig(config.usingTypeRegistry(typeRegistry));
public MultimapWithProtoValuesFluentAssertion<M> unpackingAnyUsingForValues(
TypeRegistry typeRegistry, ExtensionRegistry extensionRegistry) {
return usingConfig(config.unpackingAnyUsing(typeRegistry, extensionRegistry));
}

//////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -874,9 +880,9 @@ public MultimapWithProtoValuesFluentAssertion<M> reportingMismatchesOnlyForValue
}

@Override
public MultimapWithProtoValuesFluentAssertion<M> usingTypeRegistryForValues(
TypeRegistry typeRegistry) {
return subject.usingTypeRegistryForValues(typeRegistry);
public MultimapWithProtoValuesFluentAssertion<M> unpackingAnyUsingForValues(
TypeRegistry typeRegistry, ExtensionRegistry extensionRegistry) {
return subject.unpackingAnyUsingForValues(typeRegistry, extensionRegistry);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.google.common.truth.extensions.proto;

import com.google.protobuf.Descriptors.FieldDescriptor;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.Message;
import com.google.protobuf.TypeRegistry;
import org.checkerframework.checker.nullness.qual.Nullable;
Expand Down Expand Up @@ -455,10 +456,11 @@ ProtoFluentAssertion ignoringFieldDescriptors(
ProtoFluentAssertion reportingMismatchesOnly();

/**
* Specifies the {@link TypeRegistry} to use for {@link com.google.protobuf.Any Any} messages.
* Specifies the {@link TypeRegistry} and {@link ExtensionRegistry} to use for {@link
* com.google.protobuf.Any Any} messages.
*
* <p>To compare the value of an {@code Any} message, ProtoTruth looks in the given registry for a
* descriptor for the message's type URL.
* <p>To compare the value of an {@code Any} message, ProtoTruth looks in the given type registry
* for a descriptor for the message's type URL:
*
* <ul>
* <li>If ProtoTruth finds a descriptor, it unpacks the value and compares it against the
Expand All @@ -467,9 +469,14 @@ ProtoFluentAssertion ignoringFieldDescriptors(
* descriptor), it compares the raw, serialized bytes of the expected and actual values.
* </ul>
*
* <p>When ProtoTruth unpacks a value, it is parsing a serialized proto. That proto may contain
* extensions. To look up those extensions, ProtoTruth uses the provided {@link
* ExtensionRegistry}.
*
* @since 1.1
*/
ProtoFluentAssertion usingTypeRegistry(TypeRegistry typeRegistry);
ProtoFluentAssertion unpackingAnyUsing(
TypeRegistry typeRegistry, ExtensionRegistry extensionRegistry);

/**
* Compares the subject of the assertion to {@code expected}, using all of the rules specified by
Expand Down
Loading

0 comments on commit 97ca9f7

Please sign in to comment.