public interface IterableOfProtosFluentAssertion<M extends com.google.protobuf.Message>
Methods may be chained in any order, but the chain should terminate with a method that doesn't
return an IterableOfProtosFluentAssertion, such as containsExactly(M...)
, or containsAnyIn(java.lang.Iterable<? extends M>)
.
The state of an IterableOfProtosFluentAssertion
object after each method is called is
left undefined. Users should not retain references to IterableOfProtosFluentAssertion
instances.
Modifier and Type | Method and Description |
---|---|
void |
contains(M expected)
Checks that the subject contains at least one element that corresponds to the given expected
element.
|
Ordered |
containsAllIn(Iterable<? extends M> expected)
Checks that the subject contains elements that corresponds to all of the expected elements,
i.e.
|
Ordered |
containsAllIn(M[] expected)
Checks that the subject contains elements that corresponds to all of the expected elements,
i.e.
|
Ordered |
containsAllOf(M first,
M second,
M... rest)
Checks that the subject contains elements that corresponds to all of the expected elements,
i.e.
|
void |
containsAnyIn(Iterable<? extends M> expected)
Checks that the subject contains at least one element that corresponds to at least one of the
expected elements.
|
void |
containsAnyIn(M[] expected)
Checks that the subject contains at least one element that corresponds to at least one of the
expected elements.
|
void |
containsAnyOf(M first,
M second,
M... rest)
Checks that the subject contains at least one element that corresponds to at least one of the
expected elements.
|
Ordered |
containsExactly(M... expected)
Checks that subject contains exactly elements that correspond to the expected elements, i.e.
|
Ordered |
containsExactlyElementsIn(Iterable<? extends M> expected)
Checks that subject contains exactly elements that correspond to the expected elements, i.e.
|
Ordered |
containsExactlyElementsIn(M[] expected)
Checks that subject contains exactly elements that correspond to the expected elements, i.e.
|
void |
containsNoneIn(Iterable<? extends M> excluded)
Checks that the subject contains no elements that correspond to any of the given elements.
|
void |
containsNoneIn(M[] excluded)
Checks that the subject contains no elements that correspond to any of the given elements.
|
void |
containsNoneOf(M firstExcluded,
M secondExcluded,
M... restOfExcluded)
Checks that the subject contains no elements that correspond to any of the given elements.
|
IterableSubject.UsingCorrespondence<M,M> |
displayingDiffsPairedBy(Function<? super M,?> keyFunction)
Specifies a way to pair up unexpected and missing elements in the message when an assertion
fails.
|
void |
doesNotContain(M excluded)
Checks that none of the actual elements correspond to the given element.
|
boolean |
equals(Object o)
Deprecated.
Do not call
equals() on a IterableOfProtosFluentAssertion . |
int |
hashCode()
Deprecated.
IterableOfProtosFluentAssertion does not support hashCode() . |
IterableOfProtosFluentAssertion<M> |
ignoringFieldAbsence()
Specifies that the 'has' bit of individual fields should be ignored when comparing for
equality.
|
IterableOfProtosFluentAssertion<M> |
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. |
IterableOfProtosFluentAssertion<M> |
ignoringFieldDescriptors(Iterable<com.google.protobuf.Descriptors.FieldDescriptor> fieldDescriptors)
Excludes all message fields matching the given
Descriptors.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 argument
FieldScope 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> |
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> |
usingDoubleTolerance(double tolerance)
Compares double fields as equal if they are both finite and their absolute difference is less
than or equal to
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 to
tolerance . |
IterableOfProtosFluentAssertion<M> |
withPartialScope(FieldScope fieldScope)
Limits the comparison of Protocol buffers to the defined
FieldScope . |
IterableOfProtosFluentAssertion<M> 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.
IterableOfProtosFluentAssertion<M> 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.
IterableOfProtosFluentAssertion<M> usingDoubleTolerance(double tolerance)
tolerance
.tolerance
- A finite, non-negative tolerance.IterableOfProtosFluentAssertion<M> usingFloatTolerance(float tolerance)
tolerance
.tolerance
- A finite, non-negative tolerance.IterableOfProtosFluentAssertion<M> withPartialScope(FieldScope fieldScope)
FieldScope
.
This method is additive and has well-defined ordering semantics. If the invoking IterableOfProtosFluentAssertion
is already scoped to a FieldScope
X
, and this
method is invoked with FieldScope
Y
, the resultant IterableOfProtosFluentAssertion
is constrained to the intersection of FieldScope
s
X
and Y
.
By default, IterableOfProtosFluentAssertion
is constrained to FieldScopes.all()
, that is, no fields are excluded from comparison.
IterableOfProtosFluentAssertion<M> 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.
IterableOfProtosFluentAssertion<M> 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.
IterableOfProtosFluentAssertion<M> 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.
IterableOfProtosFluentAssertion<M> 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.
IterableOfProtosFluentAssertion<M> ignoringFieldScope(FieldScope fieldScope)
FieldScope
from the comparison.
This method is additive and has well-defined ordering semantics. If the invoking IterableOfProtosFluentAssertion
is already scoped to a FieldScope
X
, and this
method is invoked with FieldScope
Y
, the resultant IterableOfProtosFluentAssertion
is constrained to the subtraction of X - Y
.
By default, IterableOfProtosFluentAssertion
is constrained to FieldScopes.all()
, that is, no fields are excluded from comparison.
IterableOfProtosFluentAssertion<M> reportingMismatchesOnly()
This a purely cosmetic setting, and it has no effect on the behavior of the test.
IterableSubject.UsingCorrespondence<M,M> displayingDiffsPairedBy(Function<? super M,?> keyFunction)
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
and expected
values with
keys actualKey
and expectedKey
, if actual
and expected
compare
equal given the rest of the directives such as ignoringRepeatedFieldOrder
and ignoringFields
, then it is guaranteed that actualKey
is equal to expectedKey
,
but there are cases where actualKey
is equal to expectedKey
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.
void contains(@Nullable M expected)
void doesNotContain(@Nullable M excluded)
@CanIgnoreReturnValue Ordered containsExactly(@Nullable M... expected)
To also test that the contents appear in the given order, make a call to inOrder()
on the object returned by this method.
To test that the iterable contains the same elements as an array, prefer containsExactlyElementsIn(Message[])
. It makes clear that the given array is a list of
elements, not an element itself.
@CanIgnoreReturnValue Ordered containsExactlyElementsIn(Iterable<? extends M> expected)
To also test that the contents appear in the given order, make a call to inOrder()
on the object returned by this method.
@CanIgnoreReturnValue Ordered containsExactlyElementsIn(M[] expected)
To also test that the contents appear in the given order, make a call to inOrder()
on the object returned by this method.
@CanIgnoreReturnValue Ordered containsAllOf(@Nullable M first, @Nullable M second, @Nullable M... rest)
To also test that the contents appear in the given order, make a call to inOrder()
on the object returned by this method. The elements must appear in the given order within the
subject, but they are not required to be consecutive.
@CanIgnoreReturnValue Ordered containsAllIn(Iterable<? extends M> expected)
To also test that the contents appear in the given order, make a call to inOrder()
on the object returned by this method. The elements must appear in the given order within the
subject, but they are not required to be consecutive.
@CanIgnoreReturnValue Ordered containsAllIn(M[] expected)
To also test that the contents appear in the given order, make a call to inOrder()
on the object returned by this method. The elements must appear in the given order within the
subject, but they are not required to be consecutive.
void containsAnyOf(@Nullable M first, @Nullable M second, @Nullable M... rest)
void containsAnyIn(Iterable<? extends M> expected)
void containsAnyIn(M[] expected)
void containsNoneOf(@Nullable M firstExcluded, @Nullable M secondExcluded, @Nullable M... restOfExcluded)
void containsNoneIn(Iterable<? extends M> excluded)
void containsNoneIn(M[] excluded)
@Deprecated boolean equals(Object o)
equals()
on a IterableOfProtosFluentAssertion
.equals
in class Object
Subject.equals(Object)
@Deprecated int hashCode()
IterableOfProtosFluentAssertion
does not support hashCode()
.hashCode
in class Object
Subject.hashCode()
Copyright © 2018. All rights reserved.