Class IterableOfProtosSubject<M extends Message>
- java.lang.Object
-
- com.google.common.truth.Subject
-
- com.google.common.truth.IterableSubject
-
- com.google.common.truth.extensions.proto.IterableOfProtosSubject<M>
-
- Type Parameters:
M
- the type of the messages in theIterable
public class IterableOfProtosSubject<M extends Message> extends IterableSubject
Truth subject for the iterables of protocol buffers.ProtoTruth.assertThat(actual).containsExactly(expected)
performs the same assertion asTruth.assertThat(actual).containsExactly(expected)
. By default, the assertions are strict with respect to repeated field order, missing fields, etc. This behavior can be changed with the configuration methods on this subject, e.g.ProtoTruth.assertThat(actual).ignoringRepeatedFieldOrder().containsExactlyEntriesIn(expected)
.By default, floating-point fields are compared using exact equality, which is probably not what you want if the values are the results of some arithmetic. To check for approximate equality, use
usingDoubleTolerance(double)
,usingFloatTolerance(float)
, and their per-field equivalents.Equality tests, and other methods, may yield slightly different behavior for versions 2 and 3 of Protocol Buffers. If testing protos of multiple versions, make sure you understand the behaviors of default and unknown fields so you don't under or over test.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.google.common.truth.Subject
Subject.Factory<SubjectT extends Subject,ActualT>
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
IterableOfProtosSubject(FailureMetadata failureMetadata, @Nullable Iterable<M> messages)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected String
actualCustomStringRepresentation()
Supplies the direct string representation of the actual value to other methods which may prefix or otherwise position it in an error message.IterableOfProtosFluentAssertion<M>
comparingExpectedFieldsOnly()
Limits the comparison of Protocol buffers to the fields set in the expected proto(s).IterableOfProtosUsingCorrespondence<M>
displayingDiffsPairedBy(Function<? super M,?> keyFunction)
Specifies a way to pair up unexpected and missing elements in the message when an assertion fails.IterableOfProtosFluentAssertion<M>
ignoringExtraRepeatedFieldElements()
Specifies that, for all repeated and map fields, any elements in the 'actual' proto which are not found in the 'expected' proto are ignored, with the exception of fields in the expected proto which are empty.IterableOfProtosFluentAssertion<M>
ignoringExtraRepeatedFieldElementsOfFieldDescriptors(Descriptors.FieldDescriptor firstFieldDescriptor, Descriptors.FieldDescriptor... rest)
Specifies that extra repeated field elements for these explicitly specified field descriptors should be ignored.IterableOfProtosFluentAssertion<M>
ignoringExtraRepeatedFieldElementsOfFieldDescriptors(Iterable<Descriptors.FieldDescriptor> fieldDescriptors)
Specifies that extra repeated field elements for these explicitly specified field descriptors should be ignored.IterableOfProtosFluentAssertion<M>
ignoringExtraRepeatedFieldElementsOfFields(int firstFieldNumber, int... rest)
Specifies that extra repeated field elements for these explicitly specified top-level field numbers should be ignored.IterableOfProtosFluentAssertion<M>
ignoringExtraRepeatedFieldElementsOfFields(Iterable<Integer> fieldNumbers)
Specifies that extra repeated field elements for these explicitly specified top-level field numbers should be ignored.IterableOfProtosFluentAssertion<M>
ignoringFieldAbsence()
Specifies that the 'has' bit of individual fields should be ignored when comparing for equality.IterableOfProtosFluentAssertion<M>
ignoringFieldAbsenceOfFieldDescriptors(Descriptors.FieldDescriptor firstFieldDescriptor, Descriptors.FieldDescriptor... rest)
Specifies that the 'has' bit of these explicitly specified field descriptors should be ignored when comparing for equality.IterableOfProtosFluentAssertion<M>
ignoringFieldAbsenceOfFieldDescriptors(Iterable<Descriptors.FieldDescriptor> fieldDescriptors)
Specifies that the 'has' bit of these explicitly specified field descriptors should be ignored when comparing for equality.IterableOfProtosFluentAssertion<M>
ignoringFieldAbsenceOfFields(int firstFieldNumber, int... rest)
Specifies that the 'has' bit of these explicitly specified top-level field numbers should be ignored when comparing for equality.IterableOfProtosFluentAssertion<M>
ignoringFieldAbsenceOfFields(Iterable<Integer> fieldNumbers)
Specifies that the 'has' bit of these explicitly specified top-level field numbers should be ignored when comparing for equality.IterableOfProtosFluentAssertion<M>
ignoringFieldDescriptors(Descriptors.FieldDescriptor firstFieldDescriptor, Descriptors.FieldDescriptor... rest)
Excludes all message fields matching the givenDescriptors.FieldDescriptor
s from the comparison.IterableOfProtosFluentAssertion<M>
ignoringFieldDescriptors(Iterable<Descriptors.FieldDescriptor> fieldDescriptors)
Excludes all message fields matching the givenDescriptors.FieldDescriptor
s from the comparison.IterableOfProtosFluentAssertion<M>
ignoringFields(int firstFieldNumber, int... rest)
Excludes the top-level message fields with the given tag numbers from the comparison.IterableOfProtosFluentAssertion<M>
ignoringFields(Iterable<Integer> fieldNumbers)
Excludes the top-level message fields with the given tag numbers from the comparison.IterableOfProtosFluentAssertion<M>
ignoringFieldScope(FieldScope fieldScope)
Excludes all specific field paths under the argumentFieldScope
from the comparison.IterableOfProtosFluentAssertion<M>
ignoringRepeatedFieldOrder()
Specifies that the ordering of repeated fields, at all levels, should be ignored when comparing for equality.IterableOfProtosFluentAssertion<M>
ignoringRepeatedFieldOrderOfFieldDescriptors(Descriptors.FieldDescriptor firstFieldDescriptor, Descriptors.FieldDescriptor... rest)
Specifies that the ordering of repeated fields for these explicitly specified field descriptors should be ignored when comparing for equality.IterableOfProtosFluentAssertion<M>
ignoringRepeatedFieldOrderOfFieldDescriptors(Iterable<Descriptors.FieldDescriptor> fieldDescriptors)
Specifies that the ordering of repeated fields for these explicitly specified field descriptors should be ignored when comparing for equality.IterableOfProtosFluentAssertion<M>
ignoringRepeatedFieldOrderOfFields(int firstFieldNumber, int... rest)
Specifies that the ordering of repeated fields for these explicitly specified top-level field numbers should be ignored when comparing for equality.IterableOfProtosFluentAssertion<M>
ignoringRepeatedFieldOrderOfFields(Iterable<Integer> fieldNumbers)
Specifies that the ordering of repeated fields for these explicitly specified top-level field numbers should be ignored when comparing for equality.void
isInOrder()
Deprecated.Protos do not implementComparable
, so you must supply a comparator.void
isInStrictOrder()
Deprecated.Protos do not implementComparable
, so you must supply a comparator.IterableOfProtosFluentAssertion<M>
reportingMismatchesOnly()
If set, in the event of a comparison failure, the error message printed will list only those specific fields that did not match between the actual and expected values.IterableOfProtosFluentAssertion<M>
unpackingAnyUsing(TypeRegistry typeRegistry, ExtensionRegistry extensionRegistry)
IterableOfProtosFluentAssertion<M>
usingDoubleTolerance(double tolerance)
Compares double fields as equal if they are both finite and their absolute difference is less than or equal totolerance
.IterableOfProtosFluentAssertion<M>
usingDoubleToleranceForFieldDescriptors(double tolerance, Descriptors.FieldDescriptor firstFieldDescriptor, Descriptors.FieldDescriptor... rest)
Compares double fields with these explicitly specified fields using the provided absolute tolerance.IterableOfProtosFluentAssertion<M>
usingDoubleToleranceForFieldDescriptors(double tolerance, Iterable<Descriptors.FieldDescriptor> fieldDescriptors)
Compares double fields with these explicitly specified fields using the provided absolute tolerance.IterableOfProtosFluentAssertion<M>
usingDoubleToleranceForFields(double tolerance, int firstFieldNumber, int... rest)
Compares double fields with these explicitly specified top-level field numbers using the provided absolute tolerance.IterableOfProtosFluentAssertion<M>
usingDoubleToleranceForFields(double tolerance, Iterable<Integer> fieldNumbers)
Compares double fields with these explicitly specified top-level field numbers using the provided absolute tolerance.IterableOfProtosFluentAssertion<M>
usingFloatTolerance(float tolerance)
Compares float fields as equal if they are both finite and their absolute difference is less than or equal totolerance
.IterableOfProtosFluentAssertion<M>
usingFloatToleranceForFieldDescriptors(float tolerance, Descriptors.FieldDescriptor firstFieldDescriptor, Descriptors.FieldDescriptor... rest)
Compares float fields with these explicitly specified fields using the provided absolute tolerance.IterableOfProtosFluentAssertion<M>
usingFloatToleranceForFieldDescriptors(float tolerance, Iterable<Descriptors.FieldDescriptor> fieldDescriptors)
Compares float fields with these explicitly specified top-level field numbers using the provided absolute tolerance.IterableOfProtosFluentAssertion<M>
usingFloatToleranceForFields(float tolerance, int firstFieldNumber, int... rest)
Compares float fields with these explicitly specified top-level field numbers using the provided absolute tolerance.IterableOfProtosFluentAssertion<M>
usingFloatToleranceForFields(float tolerance, Iterable<Integer> fieldNumbers)
Compares float fields with these explicitly specified top-level field numbers using the provided absolute tolerance.IterableOfProtosFluentAssertion<M>
withPartialScope(FieldScope fieldScope)
Limits the comparison of Protocol buffers to the definedFieldScope
.-
Methods inherited from class com.google.common.truth.IterableSubject
comparingElementsUsing, contains, containsAnyIn, containsAnyIn, containsAnyOf, containsAtLeast, containsAtLeastElementsIn, containsAtLeastElementsIn, containsExactly, containsExactlyElementsIn, containsExactlyElementsIn, containsNoDuplicates, containsNoneIn, containsNoneIn, containsNoneOf, doesNotContain, formattingDiffsUsing, hasSize, isEmpty, isEqualTo, isInOrder, isInStrictOrder, isNoneOf, isNotEmpty, isNotIn
-
Methods inherited from class com.google.common.truth.Subject
check, equals, failWithActual, failWithActual, failWithoutActual, hashCode, ignoreCheck, isAnyOf, isIn, isInstanceOf, isNotEqualTo, isNotInstanceOf, isNotNull, isNotSameInstanceAs, isNull, isSameInstanceAs, toString
-
-
-
-
Constructor Detail
-
IterableOfProtosSubject
protected IterableOfProtosSubject(FailureMetadata failureMetadata, @Nullable Iterable<M> messages)
-
-
Method Detail
-
actualCustomStringRepresentation
protected String actualCustomStringRepresentation()
Description copied from class:Subject
Supplies the direct string representation of the actual value to other methods which may prefix or otherwise position it in an error message. This should only be overridden to provide an improved string representation of the value under test, as it would appear in any given error message, and should not be used for additional prefixing.Subjects should override this with care.
By default, this returns
String.ValueOf(getActualValue())
.- Overrides:
actualCustomStringRepresentation
in classIterableSubject
-
displayingDiffsPairedBy
public IterableOfProtosUsingCorrespondence<M> displayingDiffsPairedBy(Function<? super M,?> keyFunction)
Specifies a way to pair up unexpected and missing elements in the message when an assertion fails. For example:assertThat(actualFoos) .ignoringRepeatedFieldOrder() .ignoringFields(Foo.BAR_FIELD_NUMBER) .displayingDiffsPairedBy(Foo::getId) .containsExactlyElementsIn(expectedFoos);
On assertions where it makes sense to do so, the elements are paired as follows: they are keyed by
keyFunction
, and if an unexpected element and a missing element have the same non-null key then the they are paired up. (Elements with null keys are not paired.) The failure message will show paired elements together, and a diff will be shown.The expected elements given in the assertion should be uniquely keyed by
keyFunction
. If multiple missing elements have the same key then the pairing will be skipped.Useful key functions will have the property that key equality is less strict than the already specified equality rules; i.e. given
actual
andexpected
values with keysactualKey
andexpectedKey
, ifactual
andexpected
compare equal given the rest of the directives such asignoringRepeatedFieldOrder
andignoringFields
, then it is guaranteed thatactualKey
is equal toexpectedKey
, but there are cases whereactualKey
is equal toexpectedKey
but the direct comparison fails.Note that calling this method makes no difference to whether a test passes or fails, it just improves the message if it fails.
-
ignoringFieldAbsence
public IterableOfProtosFluentAssertion<M> ignoringFieldAbsence()
Specifies that the 'has' bit of individual fields should be ignored when comparing for equality.For version 2 Protocol Buffers, this setting determines whether two protos with the same value for a field compare equal if one explicitly sets the value, and the other merely implicitly uses the schema-defined default. This setting also determines whether unknown fields should be considered in the comparison. By
ignoringFieldAbsence()
, unknown fields are ignored, and value-equal fields as specified above are considered equal.For version 3 Protocol Buffers, this setting does not affect primitive fields, because their default value is indistinguishable from unset.
-
ignoringFieldAbsenceOfFields
public IterableOfProtosFluentAssertion<M> ignoringFieldAbsenceOfFields(int firstFieldNumber, int... rest)
Specifies that the 'has' bit of these explicitly specified top-level field numbers should be ignored when comparing for equality. Sub-fields must be specified explicitly (viaDescriptors.FieldDescriptor
) if they are to be ignored as well.Use
ignoringFieldAbsence()
instead to ignore the 'has' bit for all fields.- See Also:
for details
-
ignoringFieldAbsenceOfFields
public IterableOfProtosFluentAssertion<M> ignoringFieldAbsenceOfFields(Iterable<Integer> fieldNumbers)
Specifies that the 'has' bit of these explicitly specified top-level field numbers should be ignored when comparing for equality. Sub-fields must be specified explicitly (viaDescriptors.FieldDescriptor
) if they are to be ignored as well.Use
ignoringFieldAbsence()
instead to ignore the 'has' bit for all fields.- See Also:
for details
-
ignoringFieldAbsenceOfFieldDescriptors
public IterableOfProtosFluentAssertion<M> ignoringFieldAbsenceOfFieldDescriptors(Descriptors.FieldDescriptor firstFieldDescriptor, Descriptors.FieldDescriptor... rest)
Specifies that the 'has' bit of these explicitly specified field descriptors should be ignored when comparing for equality. Sub-fields must be specified explicitly if they are to be ignored as well.Use
ignoringFieldAbsence()
instead to ignore the 'has' bit for all fields.- See Also:
for details
-
ignoringFieldAbsenceOfFieldDescriptors
public IterableOfProtosFluentAssertion<M> ignoringFieldAbsenceOfFieldDescriptors(Iterable<Descriptors.FieldDescriptor> fieldDescriptors)
Specifies that the 'has' bit of these explicitly specified field descriptors should be ignored when comparing for equality. Sub-fields must be specified explicitly if they are to be ignored as well.Use
ignoringFieldAbsence()
instead to ignore the 'has' bit for all fields.- See Also:
for details
-
ignoringRepeatedFieldOrder
public IterableOfProtosFluentAssertion<M> ignoringRepeatedFieldOrder()
Specifies that the ordering of repeated fields, at all levels, should be ignored when comparing for equality.This setting applies to all repeated fields recursively, but it does not ignore structure. For example, with
ignoringRepeatedFieldOrder()
, a repeatedint32
fieldbar
, set inside a repeated message fieldfoo
, the following protos will all compare equal:message1: { foo: { bar: 1 bar: 2 } foo: { bar: 3 bar: 4 } } message2: { foo: { bar: 2 bar: 1 } foo: { bar: 4 bar: 3 } } message3: { foo: { bar: 4 bar: 3 } foo: { bar: 2 bar: 1 } }
However, the following message will compare equal to none of these:
message4: { foo: { bar: 1 bar: 3 } foo: { bar: 2 bar: 4 } }
This setting does not apply to map fields, for which field order is always ignored. The serialization order of map fields is undefined, and it may change from runtime to runtime.
-
ignoringRepeatedFieldOrderOfFields
public IterableOfProtosFluentAssertion<M> ignoringRepeatedFieldOrderOfFields(int firstFieldNumber, int... rest)
Specifies that the ordering of repeated fields for these explicitly specified top-level field numbers should be ignored when comparing for equality. Sub-fields must be specified explicitly (viaDescriptors.FieldDescriptor
) if their orders are to be ignored as well.Use
ignoringRepeatedFieldOrder()
instead to ignore order for all fields.- See Also:
for details.
-
ignoringRepeatedFieldOrderOfFields
public IterableOfProtosFluentAssertion<M> ignoringRepeatedFieldOrderOfFields(Iterable<Integer> fieldNumbers)
Specifies that the ordering of repeated fields for these explicitly specified top-level field numbers should be ignored when comparing for equality. Sub-fields must be specified explicitly (viaDescriptors.FieldDescriptor
) if their orders are to be ignored as well.Use
ignoringRepeatedFieldOrder()
instead to ignore order for all fields.- See Also:
for details.
-
ignoringRepeatedFieldOrderOfFieldDescriptors
public IterableOfProtosFluentAssertion<M> ignoringRepeatedFieldOrderOfFieldDescriptors(Descriptors.FieldDescriptor firstFieldDescriptor, Descriptors.FieldDescriptor... rest)
Specifies that the ordering of repeated fields for these explicitly specified field descriptors should be ignored when comparing for equality. Sub-fields must be specified explicitly if their orders are to be ignored as well.Use
ignoringRepeatedFieldOrder()
instead to ignore order for all fields.- See Also:
for details.
-
ignoringRepeatedFieldOrderOfFieldDescriptors
public IterableOfProtosFluentAssertion<M> ignoringRepeatedFieldOrderOfFieldDescriptors(Iterable<Descriptors.FieldDescriptor> fieldDescriptors)
Specifies that the ordering of repeated fields for these explicitly specified field descriptors should be ignored when comparing for equality. Sub-fields must be specified explicitly if their orders are to be ignored as well.Use
ignoringRepeatedFieldOrder()
instead to ignore order for all fields.- See Also:
for details.
-
ignoringExtraRepeatedFieldElements
public IterableOfProtosFluentAssertion<M> ignoringExtraRepeatedFieldElements()
Specifies that, for all repeated and map fields, any elements in the 'actual' proto which are not found in the 'expected' proto are ignored, with the exception of fields in the expected proto which are empty. To ignore empty repeated fields as well, usecomparingExpectedFieldsOnly()
.This rule is applied independently from
ignoringRepeatedFieldOrder()
. If ignoring repeated field order AND extra repeated field elements, all that is tested is that the expected elements comprise a subset of the actual elements. If not ignoring repeated field order, but still ignoring extra repeated field elements, the actual elements must contain a subsequence that matches the expected elements for the test to pass. (The subsequence rule does not apply to Map fields, which are always compared by key.)
-
ignoringExtraRepeatedFieldElementsOfFields
public IterableOfProtosFluentAssertion<M> ignoringExtraRepeatedFieldElementsOfFields(int firstFieldNumber, int... rest)
Specifies that extra repeated field elements for these explicitly specified top-level field numbers should be ignored. Sub-fields must be specified explicitly (viaDescriptors.FieldDescriptor
) if their extra elements are to be ignored as well.Use
ignoringExtraRepeatedFieldElements()
instead to ignore these for all fields.- See Also:
for details.
-
ignoringExtraRepeatedFieldElementsOfFields
public IterableOfProtosFluentAssertion<M> ignoringExtraRepeatedFieldElementsOfFields(Iterable<Integer> fieldNumbers)
Specifies that extra repeated field elements for these explicitly specified top-level field numbers should be ignored. Sub-fields must be specified explicitly (viaDescriptors.FieldDescriptor
) if their extra elements are to be ignored as well.Use
ignoringExtraRepeatedFieldElements()
instead to ignore these for all fields.- See Also:
for details.
-
ignoringExtraRepeatedFieldElementsOfFieldDescriptors
public IterableOfProtosFluentAssertion<M> ignoringExtraRepeatedFieldElementsOfFieldDescriptors(Descriptors.FieldDescriptor firstFieldDescriptor, Descriptors.FieldDescriptor... rest)
Specifies that extra repeated field elements for these explicitly specified field descriptors should be ignored. Sub-fields must be specified explicitly if their extra elements are to be ignored as well.Use
ignoringExtraRepeatedFieldElements()
instead to ignore these for all fields.- See Also:
for details.
-
ignoringExtraRepeatedFieldElementsOfFieldDescriptors
public IterableOfProtosFluentAssertion<M> ignoringExtraRepeatedFieldElementsOfFieldDescriptors(Iterable<Descriptors.FieldDescriptor> fieldDescriptors)
Specifies that extra repeated field elements for these explicitly specified field descriptors should be ignored. Sub-fields must be specified explicitly if their extra elements are to be ignored as well.Use
ignoringExtraRepeatedFieldElements()
instead to ignore these for all fields.- See Also:
for details.
-
usingDoubleTolerance
public IterableOfProtosFluentAssertion<M> usingDoubleTolerance(double tolerance)
Compares double fields as equal if they are both finite and their absolute difference is less than or equal totolerance
.- Parameters:
tolerance
- A finite, non-negative tolerance.
-
usingDoubleToleranceForFields
public IterableOfProtosFluentAssertion<M> usingDoubleToleranceForFields(double tolerance, int firstFieldNumber, int... rest)
Compares double fields with these explicitly specified top-level field numbers using the provided absolute tolerance.- Parameters:
tolerance
- A finite, non-negative tolerance.
-
usingDoubleToleranceForFields
public IterableOfProtosFluentAssertion<M> usingDoubleToleranceForFields(double tolerance, Iterable<Integer> fieldNumbers)
Compares double fields with these explicitly specified top-level field numbers using the provided absolute tolerance.- Parameters:
tolerance
- A finite, non-negative tolerance.
-
usingDoubleToleranceForFieldDescriptors
public IterableOfProtosFluentAssertion<M> usingDoubleToleranceForFieldDescriptors(double tolerance, Descriptors.FieldDescriptor firstFieldDescriptor, Descriptors.FieldDescriptor... rest)
Compares double fields with these explicitly specified fields using the provided absolute tolerance.- Parameters:
tolerance
- A finite, non-negative tolerance.
-
usingDoubleToleranceForFieldDescriptors
public IterableOfProtosFluentAssertion<M> usingDoubleToleranceForFieldDescriptors(double tolerance, Iterable<Descriptors.FieldDescriptor> fieldDescriptors)
Compares double fields with these explicitly specified fields using the provided absolute tolerance.- Parameters:
tolerance
- A finite, non-negative tolerance.
-
usingFloatTolerance
public IterableOfProtosFluentAssertion<M> usingFloatTolerance(float tolerance)
Compares float fields as equal if they are both finite and their absolute difference is less than or equal totolerance
.- Parameters:
tolerance
- A finite, non-negative tolerance.
-
usingFloatToleranceForFields
public IterableOfProtosFluentAssertion<M> usingFloatToleranceForFields(float tolerance, int firstFieldNumber, int... rest)
Compares float fields with these explicitly specified top-level field numbers using the provided absolute tolerance.- Parameters:
tolerance
- A finite, non-negative tolerance.
-
usingFloatToleranceForFields
public IterableOfProtosFluentAssertion<M> usingFloatToleranceForFields(float tolerance, Iterable<Integer> fieldNumbers)
Compares float fields with these explicitly specified top-level field numbers using the provided absolute tolerance.- Parameters:
tolerance
- A finite, non-negative tolerance.
-
usingFloatToleranceForFieldDescriptors
public IterableOfProtosFluentAssertion<M> usingFloatToleranceForFieldDescriptors(float tolerance, Descriptors.FieldDescriptor firstFieldDescriptor, Descriptors.FieldDescriptor... rest)
Compares float fields with these explicitly specified fields using the provided absolute tolerance.- Parameters:
tolerance
- A finite, non-negative tolerance.
-
usingFloatToleranceForFieldDescriptors
public IterableOfProtosFluentAssertion<M> usingFloatToleranceForFieldDescriptors(float tolerance, Iterable<Descriptors.FieldDescriptor> fieldDescriptors)
Compares float fields with these explicitly specified top-level field numbers using the provided absolute tolerance.- Parameters:
tolerance
- A finite, non-negative tolerance.
-
comparingExpectedFieldsOnly
public IterableOfProtosFluentAssertion<M> comparingExpectedFieldsOnly()
Limits the comparison of Protocol buffers to the fields set in the expected proto(s). When multiple protos are specified, the comparison is limited to the union of set fields in all the expected protos.The "expected proto(s)" are those passed to the method in
IterableOfProtosUsingCorrespondence
at the end of the call-chain.Fields not set in the expected proto(s) are ignored. In particular, proto3 fields which have their default values are ignored, as these are indistinguishable from unset fields. If you want to assert that a proto3 message has certain fields with default values, you cannot use this method.
-
withPartialScope
public IterableOfProtosFluentAssertion<M> withPartialScope(FieldScope fieldScope)
Limits the comparison of Protocol buffers to the definedFieldScope
.This method is additive and has well-defined ordering semantics. If the invoking
ProtoFluentAssertion
is already scoped to aFieldScope
X
, and this method is invoked withFieldScope
Y
, the resultantProtoFluentAssertion
is constrained to the intersection ofFieldScope
sX
andY
.By default,
ProtoFluentAssertion
is constrained toFieldScopes.all()
, that is, no fields are excluded from comparison.
-
ignoringFields
public IterableOfProtosFluentAssertion<M> ignoringFields(int firstFieldNumber, int... rest)
Excludes the top-level message fields with the given tag numbers from the comparison.This method adds on any previous
FieldScope
related settings, overriding previous changes to ensure the specified fields are ignored recursively. All sub-fields of these field numbers are ignored, and all sub-messages of typeM
will also have these field numbers ignored.If an invalid field number is supplied, the terminal comparison operation will throw a runtime exception.
-
ignoringFields
public IterableOfProtosFluentAssertion<M> ignoringFields(Iterable<Integer> fieldNumbers)
Excludes the top-level message fields with the given tag numbers from the comparison.This method adds on any previous
FieldScope
related settings, overriding previous changes to ensure the specified fields are ignored recursively. All sub-fields of these field numbers are ignored, and all sub-messages of typeM
will also have these field numbers ignored.If an invalid field number is supplied, the terminal comparison operation will throw a runtime exception.
-
ignoringFieldDescriptors
public IterableOfProtosFluentAssertion<M> ignoringFieldDescriptors(Descriptors.FieldDescriptor firstFieldDescriptor, Descriptors.FieldDescriptor... rest)
Excludes all message fields matching the givenDescriptors.FieldDescriptor
s from the comparison.This method adds on any previous
FieldScope
related settings, overriding previous changes to ensure the specified fields are ignored recursively. All sub-fields of these field descriptors are ignored, no matter where they occur in the tree.If a field descriptor which does not, or cannot occur in the proto structure is supplied, it is silently ignored.
-
ignoringFieldDescriptors
public IterableOfProtosFluentAssertion<M> ignoringFieldDescriptors(Iterable<Descriptors.FieldDescriptor> fieldDescriptors)
Excludes all message fields matching the givenDescriptors.FieldDescriptor
s from the comparison.This method adds on any previous
FieldScope
related settings, overriding previous changes to ensure the specified fields are ignored recursively. All sub-fields of these field descriptors are ignored, no matter where they occur in the tree.If a field descriptor which does not, or cannot occur in the proto structure is supplied, it is silently ignored.
-
ignoringFieldScope
public IterableOfProtosFluentAssertion<M> ignoringFieldScope(FieldScope fieldScope)
Excludes all specific field paths under the argumentFieldScope
from the comparison.This method is additive and has well-defined ordering semantics. If the invoking
ProtoFluentAssertion
is already scoped to aFieldScope
X
, and this method is invoked withFieldScope
Y
, the resultantProtoFluentAssertion
is constrained to the subtraction ofX - Y
.By default,
ProtoFluentAssertion
is constrained toFieldScopes.all()
, that is, no fields are excluded from comparison.
-
reportingMismatchesOnly
public IterableOfProtosFluentAssertion<M> reportingMismatchesOnly()
If set, in the event of a comparison failure, the error message printed will list only those specific fields that did not match between the actual and expected values. Useful for very large protocol buffers.This a purely cosmetic setting, and it has no effect on the behavior of the test.
-
unpackingAnyUsing
public IterableOfProtosFluentAssertion<M> unpackingAnyUsing(TypeRegistry typeRegistry, ExtensionRegistry extensionRegistry)
Specifies theTypeRegistry
andExtensionRegistry
to use forAny
messages.To compare the value of an
Any
message, ProtoTruth looks in the given type registry for a descriptor for the message's type URL:- If ProtoTruth finds a descriptor, it unpacks the value and compares it against the expected value, respecting any configuration methods used for the assertion.
- If ProtoTruth does not find a descriptor (or if the value can't be deserialized with the descriptor), it compares the raw, serialized bytes of the expected and actual values.
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
ExtensionRegistry
.- Since:
- 1.1
-
isInStrictOrder
@Deprecated public final void isInStrictOrder()
Deprecated.Protos do not implementComparable
, so you must supply a comparator.Description copied from class:IterableSubject
Fails if the iterable is not strictly ordered, according to the natural ordering of its elements. Strictly ordered means that each element in the iterable is strictly greater than the element that preceded it.- Overrides:
isInStrictOrder
in classIterableSubject
- Throws:
ClassCastException
- always
-
isInOrder
@Deprecated public final void isInOrder()
Deprecated.Protos do not implementComparable
, so you must supply a comparator.Description copied from class:IterableSubject
Fails if the iterable is not ordered, according to the natural ordering of its elements. Ordered means that each element in the iterable is greater than or equal to the element that preceded it.- Overrides:
isInOrder
in classIterableSubject
- Throws:
ClassCastException
- always
-
-