Interface ProtoFluentAssertion
-
public interface ProtoFluentAssertionFluent API to perform detailed, customizable comparison of Protocol buffers.Methods may be chained in any order, but the chain should terminate with
isEqualTo(Message)orisNotEqualTo(Message).The state of a
ProtoFluentAssertionobject after each method is called is left undefined. Users should not retain references toProtoFluentAssertioninstances.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description ProtoFluentAssertioncomparingExpectedFieldsOnly()Limits the comparison of Protocol buffers to the fields set in the expected proto(s).booleanequals(Object o)Deprecated.Do not callequals()on aProtoFluentAssertion.inthashCode()Deprecated.ProtoFluentAssertiondoes not supporthashCode().ProtoFluentAssertionignoringExtraRepeatedFieldElements()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.ProtoFluentAssertionignoringExtraRepeatedFieldElementsOfFieldDescriptors(Descriptors.FieldDescriptor firstFieldDescriptor, Descriptors.FieldDescriptor... rest)Specifies that extra repeated field elements for these explicitly specified field descriptors should be ignored.ProtoFluentAssertionignoringExtraRepeatedFieldElementsOfFieldDescriptors(Iterable<Descriptors.FieldDescriptor> fieldDescriptors)Specifies that extra repeated field elements for these explicitly specified field descriptors should be ignored.ProtoFluentAssertionignoringExtraRepeatedFieldElementsOfFields(int firstFieldNumber, int... rest)Specifies that extra repeated field elements for these explicitly specified top-level field numbers should be ignored.ProtoFluentAssertionignoringExtraRepeatedFieldElementsOfFields(Iterable<Integer> fieldNumbers)Specifies that extra repeated field elements for these explicitly specified top-level field numbers should be ignored.ProtoFluentAssertionignoringFieldAbsence()Specifies that the 'has' bit of individual fields should be ignored when comparing for equality.ProtoFluentAssertionignoringFieldAbsenceOfFieldDescriptors(Descriptors.FieldDescriptor firstFieldDescriptor, Descriptors.FieldDescriptor... rest)Specifies that the 'has' bit of these explicitly specified field descriptors should be ignored when comparing for equality.ProtoFluentAssertionignoringFieldAbsenceOfFieldDescriptors(Iterable<Descriptors.FieldDescriptor> fieldDescriptors)Specifies that the 'has' bit of these explicitly specified field descriptors should be ignored when comparing for equality.ProtoFluentAssertionignoringFieldAbsenceOfFields(int firstFieldNumber, int... rest)Specifies that the 'has' bit of these explicitly specified top-level field numbers should be ignored when comparing for equality.ProtoFluentAssertionignoringFieldAbsenceOfFields(Iterable<Integer> fieldNumbers)Specifies that the 'has' bit of these explicitly specified top-level field numbers should be ignored when comparing for equality.ProtoFluentAssertionignoringFieldDescriptors(Descriptors.FieldDescriptor firstFieldDescriptor, Descriptors.FieldDescriptor... rest)Excludes all message fields matching the givenDescriptors.FieldDescriptors from the comparison.ProtoFluentAssertionignoringFieldDescriptors(Iterable<Descriptors.FieldDescriptor> fieldDescriptors)Excludes all message fields matching the givenDescriptors.FieldDescriptors from the comparison.ProtoFluentAssertionignoringFields(int firstFieldNumber, int... rest)Excludes the top-level message fields with the given tag numbers from the comparison.ProtoFluentAssertionignoringFields(Iterable<Integer> fieldNumbers)Excludes the top-level message fields with the given tag numbers from the comparison.ProtoFluentAssertionignoringFieldScope(FieldScope fieldScope)Excludes all specific field paths under the argumentFieldScopefrom the comparison.ProtoFluentAssertionignoringRepeatedFieldOrder()Specifies that the ordering of repeated fields, at all levels, should be ignored when comparing for equality.ProtoFluentAssertionignoringRepeatedFieldOrderOfFieldDescriptors(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.ProtoFluentAssertionignoringRepeatedFieldOrderOfFieldDescriptors(Iterable<Descriptors.FieldDescriptor> fieldDescriptors)Specifies that the ordering of repeated fields for these explicitly specified field descriptors should be ignored when comparing for equality.ProtoFluentAssertionignoringRepeatedFieldOrderOfFields(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.ProtoFluentAssertionignoringRepeatedFieldOrderOfFields(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.voidisEqualTo(@Nullable Message expected)Compares the subject of the assertion toexpected, using all of the rules specified by earlier operations.voidisNotEqualTo(@Nullable Message expected)Compares the subject of the assertion toexpected, expecting a difference, using all of the rules specified by earlier operations.ProtoFluentAssertionreportingMismatchesOnly()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.ProtoFluentAssertionunpackingAnyUsing(TypeRegistry typeRegistry, ExtensionRegistry extensionRegistry)ProtoFluentAssertionusingDoubleTolerance(double tolerance)Compares double fields as equal if they are both finite and their absolute difference is less than or equal totolerance.ProtoFluentAssertionusingDoubleToleranceForFieldDescriptors(double tolerance, Descriptors.FieldDescriptor firstFieldDescriptor, Descriptors.FieldDescriptor... rest)Compares double fields with these explicitly specified fields using the provided absolute tolerance.ProtoFluentAssertionusingDoubleToleranceForFieldDescriptors(double tolerance, Iterable<Descriptors.FieldDescriptor> fieldDescriptors)Compares double fields with these explicitly specified fields using the provided absolute tolerance.ProtoFluentAssertionusingDoubleToleranceForFields(double tolerance, int firstFieldNumber, int... rest)Compares double fields with these explicitly specified top-level field numbers using the provided absolute tolerance.ProtoFluentAssertionusingDoubleToleranceForFields(double tolerance, Iterable<Integer> fieldNumbers)Compares double fields with these explicitly specified top-level field numbers using the provided absolute tolerance.ProtoFluentAssertionusingFloatTolerance(float tolerance)Compares float fields as equal if they are both finite and their absolute difference is less than or equal totolerance.ProtoFluentAssertionusingFloatToleranceForFieldDescriptors(float tolerance, Descriptors.FieldDescriptor firstFieldDescriptor, Descriptors.FieldDescriptor... rest)Compares float fields with these explicitly specified fields using the provided absolute tolerance.ProtoFluentAssertionusingFloatToleranceForFieldDescriptors(float tolerance, Iterable<Descriptors.FieldDescriptor> fieldDescriptors)Compares float fields with these explicitly specified top-level field numbers using the provided absolute tolerance.ProtoFluentAssertionusingFloatToleranceForFields(float tolerance, int firstFieldNumber, int... rest)Compares float fields with these explicitly specified top-level field numbers using the provided absolute tolerance.ProtoFluentAssertionusingFloatToleranceForFields(float tolerance, Iterable<Integer> fieldNumbers)Compares float fields with these explicitly specified top-level field numbers using the provided absolute tolerance.ProtoFluentAssertionwithPartialScope(FieldScope fieldScope)Limits the comparison of Protocol buffers to the definedFieldScope.
-
-
-
Method Detail
-
ignoringFieldAbsence
ProtoFluentAssertion 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
ProtoFluentAssertion 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
ProtoFluentAssertion 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
ProtoFluentAssertion 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
ProtoFluentAssertion 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
ProtoFluentAssertion 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 repeatedint32fieldbar, 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
ProtoFluentAssertion 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
ProtoFluentAssertion 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
ProtoFluentAssertion 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
ProtoFluentAssertion 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
ProtoFluentAssertion 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
ProtoFluentAssertion 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
ProtoFluentAssertion 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
ProtoFluentAssertion 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
ProtoFluentAssertion 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
ProtoFluentAssertion 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
ProtoFluentAssertion 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
ProtoFluentAssertion 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
ProtoFluentAssertion 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
ProtoFluentAssertion 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
ProtoFluentAssertion 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
ProtoFluentAssertion 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
ProtoFluentAssertion 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
ProtoFluentAssertion 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
ProtoFluentAssertion 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
ProtoFluentAssertion 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 void method at the end of the
ProtoFluentAssertioncall-chain: For example,isEqualTo(Message), orisNotEqualTo(Message).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
ProtoFluentAssertion 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
ProtoFluentAssertionis already scoped to aFieldScopeX, and this method is invoked withFieldScopeY, the resultantProtoFluentAssertionis constrained to the intersection ofFieldScopesXandY.By default,
ProtoFluentAssertionis constrained toFieldScopes.all(), that is, no fields are excluded from comparison.
-
ignoringFields
ProtoFluentAssertion 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
FieldScoperelated 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 typeMwill also have these field numbers ignored.If an invalid field number is supplied, the terminal comparison operation will throw a runtime exception.
-
ignoringFields
ProtoFluentAssertion ignoringFields(Iterable<Integer> fieldNumbers)
Excludes the top-level message fields with the given tag numbers from the comparison.This method adds on any previous
FieldScoperelated 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 typeMwill also have these field numbers ignored.If an invalid field number is supplied, the terminal comparison operation will throw a runtime exception.
-
ignoringFieldDescriptors
ProtoFluentAssertion ignoringFieldDescriptors(Descriptors.FieldDescriptor firstFieldDescriptor, Descriptors.FieldDescriptor... rest)
Excludes all message fields matching the givenDescriptors.FieldDescriptors from the comparison.This method adds on any previous
FieldScoperelated 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
ProtoFluentAssertion ignoringFieldDescriptors(Iterable<Descriptors.FieldDescriptor> fieldDescriptors)
Excludes all message fields matching the givenDescriptors.FieldDescriptors from the comparison.This method adds on any previous
FieldScoperelated 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
ProtoFluentAssertion ignoringFieldScope(FieldScope fieldScope)
Excludes all specific field paths under the argumentFieldScopefrom the comparison.This method is additive and has well-defined ordering semantics. If the invoking
ProtoFluentAssertionis already scoped to aFieldScopeX, and this method is invoked withFieldScopeY, the resultantProtoFluentAssertionis constrained to the subtraction ofX - Y.By default,
ProtoFluentAssertionis constrained toFieldScopes.all(), that is, no fields are excluded from comparison.
-
reportingMismatchesOnly
ProtoFluentAssertion 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
ProtoFluentAssertion unpackingAnyUsing(TypeRegistry typeRegistry, ExtensionRegistry extensionRegistry)
Specifies theTypeRegistryandExtensionRegistryto use forAnymessages.To compare the value of an
Anymessage, 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
-
isEqualTo
void isEqualTo(@Nullable Message expected)
Compares the subject of the assertion toexpected, using all of the rules specified by earlier operations. If no settings are changed, this invokes the defaultequalsimplementation of the subjectMessage.
-
isNotEqualTo
void isNotEqualTo(@Nullable Message expected)
Compares the subject of the assertion toexpected, expecting a difference, using all of the rules specified by earlier operations. If no settings are changed, this invokes the defaultequalsimplementation of the subjectMessage.
-
equals
@Deprecated boolean equals(Object o)
Deprecated.- Overrides:
equalsin classObject- See Also:
Subject.equals(Object)
-
hashCode
@Deprecated int hashCode()
Deprecated.- Overrides:
hashCodein classObject- See Also:
Subject.hashCode()
-
-