use of com.google.protobuf.FieldMask in project core-java by SpineEventEngine.
the class FieldMasksShould method apply_only_non_empty_mask_to_collection.
@SuppressWarnings({ "ObjectEquality", "MethodWithMultipleLoops" })
@Test
public void apply_only_non_empty_mask_to_collection() {
final FieldMask emptyMask = Given.fieldMask();
final Collection<Project> original = new LinkedList<>();
final int count = 5;
for (int i = 0; i < count; i++) {
final Project project = Given.newProject(format("test-data--%s", i));
original.add(project);
}
final Collection<Project> processed = FieldMasks.applyMask(emptyMask, original, Given.TYPE);
assertSize(original.size(), processed);
// The argument is not returned
assertFalse(original == processed);
// A copy of the argument is returned (Collection type may differ)
final Iterator<Project> processedProjects = processed.iterator();
for (Project anOriginal : original) {
assertTrue(processedProjects.next().equals(anOriginal));
}
}
use of com.google.protobuf.FieldMask in project core-java by SpineEventEngine.
the class FieldMasksShould method create_masks_for_given_field_tags.
@Test
public void create_masks_for_given_field_tags() {
final Descriptors.Descriptor descriptor = Project.getDescriptor();
final int[] fieldNumbers = { 1, 2, 3 };
@SuppressWarnings("DuplicateStringLiteralInspection") final String[] fieldNames = { "id", "name", "task" };
final FieldMask mask = FieldMasks.maskOf(descriptor, fieldNumbers);
final List<String> paths = mask.getPathsList();
assertSize(fieldNumbers.length, paths);
for (int i = 0; i < paths.size(); i++) {
final String expectedPath = descriptor.getFullName() + '.' + fieldNames[i];
assertEquals(expectedPath, paths.get(i));
}
}
use of com.google.protobuf.FieldMask in project core-java by SpineEventEngine.
the class FieldMasksShould method apply_mask_to_message_collections.
@SuppressWarnings({ "MethodWithMultipleLoops", "ObjectEquality" })
@Test
public void apply_mask_to_message_collections() {
final FieldMask fieldMask = Given.fieldMask(Project.STATUS_FIELD_NUMBER, Project.TASK_FIELD_NUMBER);
final int count = 5;
final Collection<Project> original = new LinkedList<>();
for (int i = 0; i < count; i++) {
final Project project = Given.newProject(format("project-%s", i));
original.add(project);
}
final Collection<Project> masked = FieldMasks.applyMask(fieldMask, original, Given.TYPE);
assertSize(original.size(), masked);
// Collection references are not the same
assertFalse(original == masked);
for (Project project : masked) {
assertMatchesMask(project, fieldMask);
// Can't check repeated fields with assertMatchesMask
assertFalse(project.getTaskList().isEmpty());
}
}
use of com.google.protobuf.FieldMask in project core-java by SpineEventEngine.
the class FieldMasksShould method retrieve_default_field_mask_if_no_field_tags_requested.
@Test
public void retrieve_default_field_mask_if_no_field_tags_requested() {
final Descriptors.Descriptor descriptor = Project.getDescriptor();
final FieldMask mask = FieldMasks.maskOf(descriptor);
assertEquals(FieldMask.getDefaultInstance(), mask);
}
use of com.google.protobuf.FieldMask in project core-java by SpineEventEngine.
the class DefaultEntityStorageConverterShould method create_instance_with_FieldMask.
@Test
public void create_instance_with_FieldMask() throws Exception {
final FieldMask fieldMask = FieldMask.newBuilder().addPaths("foo.bar").build();
final EntityStorageConverter<Long, TestEntity, StringValue> withMasks = converter.withFieldMask(fieldMask);
assertEquals(fieldMask, withMasks.getFieldMask());
}
Aggregations