public interface ProtoFluentAssertion
Methods may be chained in any order, but the chain should terminate with isEqualTo(Object)
or isNotEqualTo(Object)
.
The state of a ProtoFluentAssertion
object after each method is called is left
undefined. Users should not retain references to ProtoFluentAssertion
instances.
Modifier and Type | Method and Description |
---|---|
ProtoFluentAssertion |
comparingExpectedFieldsOnly()
Limits the comparison of Protocol buffers to the fields set in the expected proto(s).
|
boolean |
equals(Object o)
Deprecated.
Do not call
equals() on a ProtoFluentAssertion . Use isEqualTo(Object) instead. |
int |
hashCode()
Deprecated.
ProtoFluentAssertion does not support hashCode() . Use isEqualTo(Object) for testing. |
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.
|
ProtoFluentAssertion |
ignoringFieldAbsence()
Specifies that the 'has' bit of individual fields should be ignored when comparing for
equality.
|
ProtoFluentAssertion |
ignoringFieldDescriptors(com.google.protobuf.Descriptors.FieldDescriptor firstFieldDescriptor,
com.google.protobuf.Descriptors.FieldDescriptor... rest)
Excludes all message fields matching the given
Descriptors.FieldDescriptor s from the comparison. |
ProtoFluentAssertion |
ignoringFieldDescriptors(Iterable<com.google.protobuf.Descriptors.FieldDescriptor> fieldDescriptors)
Excludes all message fields matching the given
Descriptors.FieldDescriptor s from the comparison. |
ProtoFluentAssertion |
ignoringFields(int firstFieldNumber,
int... rest)
Excludes the top-level message fields with the given tag numbers from the comparison.
|
ProtoFluentAssertion |
ignoringFields(Iterable<Integer> fieldNumbers)
Excludes the top-level message fields with the given tag numbers from the comparison.
|
ProtoFluentAssertion |
ignoringFieldScope(FieldScope fieldScope)
Excludes all specific field paths under the argument
FieldScope from the comparison. |
ProtoFluentAssertion |
ignoringRepeatedFieldOrder()
Specifies that the ordering of repeated fields, at all levels, should be ignored when comparing
for equality.
|
void |
isEqualTo(Object expected)
Compares the subject of the assertion to
expected , using all of the rules specified by
earlier operations. |
void |
isNotEqualTo(Object expected)
Compares the subject of the assertion to
expected , expecting a difference, using all of
the rules specified by earlier operations. |
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.
|
ProtoFluentAssertion |
usingDoubleTolerance(double tolerance)
Compares double fields as equal if they are both finite and their absolute difference is less
than or equal to
tolerance . |
ProtoFluentAssertion |
usingFloatTolerance(float tolerance)
Compares float fields as equal if they are both finite and their absolute difference is less
than or equal to
tolerance . |
ProtoFluentAssertion |
withPartialScope(FieldScope fieldScope)
Limits the comparison of Protocol buffers to the defined
FieldScope . |
ProtoFluentAssertion ignoringFieldAbsence()
For version 2 Protocol Buffers, this setting determines whether two protos with the same
value for a primitive 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 has no effect. Primitive fields set to their default value are indistinguishable from unset fields in proto 3. Proto 3 also eliminates unknown fields, so this setting has no effect there either.
ProtoFluentAssertion ignoringRepeatedFieldOrder()
This setting applies to all repeated fields recursively, but it does not ignore structure.
For example, with ignoringRepeatedFieldOrder()
, a repeated int32
field bar
, set inside a repeated message field foo
, 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.
ProtoFluentAssertion ignoringExtraRepeatedFieldElements()
comparingExpectedFieldsOnly()
.
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.)
ProtoFluentAssertion usingDoubleTolerance(double tolerance)
tolerance
.tolerance
- A finite, non-negative tolerance.ProtoFluentAssertion usingFloatTolerance(float tolerance)
tolerance
.tolerance
- A finite, non-negative tolerance.ProtoFluentAssertion comparingExpectedFieldsOnly()
The "expected proto(s)" are those passed to the void method at the end of the ProtoFluentAssertion
call-chain: For example, isEqualTo(Object)
, or isNotEqualTo(Object)
.
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.
ProtoFluentAssertion withPartialScope(FieldScope fieldScope)
FieldScope
.
This method is additive and has well-defined ordering semantics. If the invoking ProtoFluentAssertion
is already scoped to a FieldScope
X
, and this method is
invoked with FieldScope
Y
, the resultant ProtoFluentAssertion
is
constrained to the intersection of FieldScope
s X
and Y
.
By default, ProtoFluentAssertion
is constrained to FieldScopes.all()
, that
is, no fields are excluded from comparison.
ProtoFluentAssertion ignoringFields(int firstFieldNumber, int... rest)
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 type M
will also have these field numbers
ignored.
If an invalid field number is supplied, the terminal comparison operation will throw a runtime exception.
ProtoFluentAssertion ignoringFields(Iterable<Integer> fieldNumbers)
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 type M
will also have these field numbers
ignored.
If an invalid field number is supplied, the terminal comparison operation will throw a runtime exception.
ProtoFluentAssertion ignoringFieldDescriptors(com.google.protobuf.Descriptors.FieldDescriptor firstFieldDescriptor, com.google.protobuf.Descriptors.FieldDescriptor... rest)
Descriptors.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.
ProtoFluentAssertion ignoringFieldDescriptors(Iterable<com.google.protobuf.Descriptors.FieldDescriptor> fieldDescriptors)
Descriptors.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.
ProtoFluentAssertion ignoringFieldScope(FieldScope fieldScope)
FieldScope
from the comparison.
This method is additive and has well-defined ordering semantics. If the invoking ProtoFluentAssertion
is already scoped to a FieldScope
X
, and this method is
invoked with FieldScope
Y
, the resultant ProtoFluentAssertion
is
constrained to the subtraction of X - Y
.
By default, ProtoFluentAssertion
is constrained to FieldScopes.all()
, that
is, no fields are excluded from comparison.
ProtoFluentAssertion reportingMismatchesOnly()
This a purely cosmetic setting, and it has no effect on the behavior of the test.
void isEqualTo(@NullableDecl Object expected)
expected
, using all of the rules specified by
earlier operations. If no settings are changed, this invokes the default equals
implementation of the subject Message
.void isNotEqualTo(@NullableDecl Object expected)
expected
, expecting a difference, using all of
the rules specified by earlier operations. If no settings are changed, this invokes the default
equals
implementation of the subject Message
.@Deprecated boolean equals(Object o)
equals()
on a ProtoFluentAssertion
. Use isEqualTo(Object)
instead.equals
in class Object
Subject.equals(Object)
@Deprecated int hashCode()
ProtoFluentAssertion
does not support hashCode()
. Use isEqualTo(Object)
for testing.hashCode
in class Object
Subject.hashCode()
Copyright © 2018. All rights reserved.