public static List<UpdateRequirement> forUpdateTable(
      TableMetadata base, List<MetadataUpdate> metadataUpdates) {
    Preconditions.checkArgument(null != base, "Invalid table metadata: null");
    Preconditions.checkArgument(null != metadataUpdates, "Invalid metadata updates: null");
    Builder builder = new Builder(base, false);
    builder.require(new UpdateRequirement.AssertTableUUID(base.uuid()));
    metadataUpdates.forEach(builder::update);
    return builder.build();
  }
@Test
  public void setAndRemoveSnapshotRef() {
    long snapshotId = 14L;
    String refName = "branch";
    SnapshotRef snapshotRef = mock(SnapshotRef.class);
    when(snapshotRef.snapshotId()).thenReturn(snapshotId);
    when(metadata.ref(refName)).thenReturn(snapshotRef);

    List<UpdateRequirement> requirements =
        UpdateRequirements.forUpdateTable(
            metadata,
            ImmutableList.of(
                new MetadataUpdate.SetSnapshotRef(
                    refName, snapshotId, SnapshotRefType.BRANCH, 0, 0L, 0L),
                new MetadataUpdate.SetSnapshotRef(
                    refName, snapshotId + 1, SnapshotRefType.BRANCH, 0, 0L, 0L),
                new MetadataUpdate.SetSnapshotRef(
                    refName, snapshotId + 2, SnapshotRefType.BRANCH, 0, 0L, 0L)));
    requirements.forEach(req -> req.validate(metadata));

    assertThat(requirements)
        .hasSize(2)
        .hasOnlyElementsOfTypes(
            UpdateRequirement.AssertTableUUID.class, UpdateRequirement.AssertRefSnapshotID.class);

    assertTableUUID(requirements);

    UpdateRequirement.AssertRefSnapshotID assertRefSnapshotID =
        (UpdateRequirement.AssertRefSnapshotID) requirements.get(1);
    assertThat(assertRefSnapshotID.snapshotId()).isEqualTo(snapshotId);
    assertThat(assertRefSnapshotID.refName()).isEqualTo(refName);

    requirements =
        UpdateRequirements.forUpdateTable(
            metadata, ImmutableList.of(new MetadataUpdate.RemoveSnapshot(0L)));
    requirements.forEach(req -> req.validate(metadata));

    assertThat(requirements)
        .hasSize(1)
        .hasOnlyElementsOfTypes(UpdateRequirement.AssertTableUUID.class);

    assertTableUUID(requirements);
  }