public final class FieldScopes extends Object
FieldScope
instances.Modifier and Type | Method and Description |
---|---|
static FieldScope |
all()
Returns a
FieldScope which matches all fields without exception. |
static FieldScope |
allowingFieldDescriptors(com.google.protobuf.Descriptors.FieldDescriptor firstFieldDescriptor,
com.google.protobuf.Descriptors.FieldDescriptor... rest)
Returns a
FieldScope which matches nothing except the provided field descriptors for
the message. |
static FieldScope |
allowingFieldDescriptors(Iterable<com.google.protobuf.Descriptors.FieldDescriptor> fieldDescriptors)
Returns a
FieldScope which matches nothing except the provided field descriptors for
the message. |
static FieldScope |
allowingFields(int firstFieldNumber,
int... rest)
Returns a
FieldScope which matches nothing except the provided field numbers for the
top level message type. |
static FieldScope |
allowingFields(Iterable<Integer> fieldNumbers)
Returns a
FieldScope which matches nothing except the provided field numbers for the
top level message type. |
static FieldScope |
fromSetFields(Iterable<? extends com.google.protobuf.Message> messages)
Creates a
FieldScope covering the fields set in every message in the provided list of
messages, with the same semantics as in fromSetFields(Message) . |
static FieldScope |
fromSetFields(com.google.protobuf.Message message)
Returns a
FieldScope which is constrained to precisely those specific field paths that
are explicitly set in the message. |
static FieldScope |
fromSetFields(com.google.protobuf.Message firstMessage,
com.google.protobuf.Message secondMessage,
com.google.protobuf.Message... rest)
Creates a
FieldScope covering the fields set in every message in the provided list of
messages, with the same semantics as in fromSetFields(Message) . |
static FieldScope |
ignoringFieldDescriptors(com.google.protobuf.Descriptors.FieldDescriptor firstFieldDescriptor,
com.google.protobuf.Descriptors.FieldDescriptor... rest)
Returns a
FieldScope which matches everything except the provided field descriptors for
the message. |
static FieldScope |
ignoringFieldDescriptors(Iterable<com.google.protobuf.Descriptors.FieldDescriptor> fieldDescriptors)
Returns a
FieldScope which matches everything except the provided field descriptors for
the message. |
static FieldScope |
ignoringFields(int firstFieldNumber,
int... rest)
Returns a
FieldScope which matches everything except the provided field numbers for the
top level message type. |
static FieldScope |
ignoringFields(Iterable<Integer> fieldNumbers)
Returns a
FieldScope which matches everything except the provided field numbers for the
top level message type. |
static FieldScope |
none()
Returns a
FieldScope which matches no fields. |
public static FieldScope fromSetFields(com.google.protobuf.Message message)
FieldScope
which is constrained to precisely those specific field paths that
are explicitly set in the message. Note that, for version 3 protobufs, such a FieldScope
will omit fields in the provided message which are set to default values.
This can be used limit the scope of a comparison to a complex set of fields in a very brief
statement. Often, message
is the expected half of a comparison about to be performed.
Example usage:
Foo actual = Foo.newBuilder().setBar(3).setBaz(4).build();
Foo expected = Foo.newBuilder().setBar(3).setBaz(5).build();
// Fails, because actual.getBaz() != expected.getBaz().
assertThat(actual).isEqualTo(expected);
Foo scope = Foo.newBuilder().setBar(2).build();
// Succeeds, because only the field 'bar' is compared.
assertThat(actual).withPartialScope(FieldScopes.fromSetFields(scope)).isEqualTo(expected);
The returned FieldScope
does not respect repeated field indices nor map keys. For
example, if the provided message sets different field values for different elements of a
repeated field, like so:
sub_message: {
foo: "foo"
}
sub_message: {
bar: "bar"
}
The FieldScope
will contain sub_message.foo
and sub_message.bar
for
*all* repeated sub_messages
, including those beyond index 1.
public static FieldScope fromSetFields(com.google.protobuf.Message firstMessage, com.google.protobuf.Message secondMessage, com.google.protobuf.Message... rest)
FieldScope
covering the fields set in every message in the provided list of
messages, with the same semantics as in fromSetFields(Message)
.
This can be thought of as the union of the FieldScope
s for each individual message,
or the FieldScope
for the merge of all the messages. These are equivalent.
public static FieldScope fromSetFields(Iterable<? extends com.google.protobuf.Message> messages)
FieldScope
covering the fields set in every message in the provided list of
messages, with the same semantics as in fromSetFields(Message)
.
This can be thought of as the union of the FieldScope
s for each individual message,
or the FieldScope
for the merge of all the messages. These are equivalent.
public static FieldScope ignoringFields(int firstFieldNumber, int... rest)
FieldScope
which matches everything except the provided field numbers for the
top level message type.
The field numbers are ignored recursively on this type. That is, if YourMessage
contains another YourMessage
somewhere within its subtree, field number X
will
be ignored for all submessages of type YourMessage
, as well as for the top-level
message.
FieldScope.ignoringFields(int, int...)
public static FieldScope ignoringFields(Iterable<Integer> fieldNumbers)
FieldScope
which matches everything except the provided field numbers for the
top level message type.
The field numbers are ignored recursively on this type. That is, if YourMessage
contains another YourMessage
somewhere within its subtree, field number X
will
be ignored for all submessages of type YourMessage
, as well as for the top-level
message.
FieldScope.ignoringFields(Iterable)
public static FieldScope ignoringFieldDescriptors(com.google.protobuf.Descriptors.FieldDescriptor firstFieldDescriptor, com.google.protobuf.Descriptors.FieldDescriptor... rest)
FieldScope
which matches everything except the provided field descriptors for
the message.FieldScope#ignoringFieldDescriptors(FieldDescriptor, FieldDescriptor...)
public static FieldScope ignoringFieldDescriptors(Iterable<com.google.protobuf.Descriptors.FieldDescriptor> fieldDescriptors)
FieldScope
which matches everything except the provided field descriptors for
the message.public static FieldScope allowingFields(int firstFieldNumber, int... rest)
FieldScope
which matches nothing except the provided field numbers for the
top level message type.FieldScope.allowingFields(int, int...)
public static FieldScope allowingFields(Iterable<Integer> fieldNumbers)
FieldScope
which matches nothing except the provided field numbers for the
top level message type.FieldScope.allowingFields(Iterable)
public static FieldScope allowingFieldDescriptors(com.google.protobuf.Descriptors.FieldDescriptor firstFieldDescriptor, com.google.protobuf.Descriptors.FieldDescriptor... rest)
FieldScope
which matches nothing except the provided field descriptors for
the message.FieldScope#allowingFieldDescriptors(FieldDescriptor, FieldDescriptor...)
public static FieldScope allowingFieldDescriptors(Iterable<com.google.protobuf.Descriptors.FieldDescriptor> fieldDescriptors)
FieldScope
which matches nothing except the provided field descriptors for
the message.public static FieldScope all()
FieldScope
which matches all fields without exception. Generally not needed,
since the other factory functions will build on top of this for you.public static FieldScope none()
FieldScope
which matches no fields. A comparison made using this scope alone
will always trivially pass. Generally not needed, since the other factory functions will build
on top of this for you.Copyright © 2018. All rights reserved.