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 setSnapshotRefFailure() {
    long snapshotId = 14L;
    String refName = "random_branch";
    SnapshotRef snapshotRef = mock(SnapshotRef.class);
    when(snapshotRef.isBranch()).thenReturn(true);
    when(snapshotRef.snapshotId()).thenReturn(snapshotId);

    ImmutableList<MetadataUpdate> metadataUpdates =
        ImmutableList.of(
            new MetadataUpdate.SetSnapshotRef(
                refName, snapshotId, SnapshotRefType.BRANCH, 0, 0L, 0L));

    when(metadata.ref(refName)).thenReturn(null);
    when(updated.ref(refName)).thenReturn(snapshotRef);
    assertThatThrownBy(
            () ->
                UpdateRequirements.forUpdateTable(metadata, metadataUpdates)
                    .forEach(req -> req.validate(updated)))
        .isInstanceOf(CommitFailedException.class)
        .hasMessage("Requirement failed: branch random_branch was created concurrently");

    when(metadata.ref(refName)).thenReturn(snapshotRef);
    when(updated.ref(refName)).thenReturn(null);
    assertThatThrownBy(
            () ->
                UpdateRequirements.forUpdateTable(metadata, metadataUpdates)
                    .forEach(req -> req.validate(updated)))
        .isInstanceOf(CommitFailedException.class)
        .hasMessage("Requirement failed: branch or tag random_branch is missing, expected 14");

    SnapshotRef snapshotRefUpdated = mock(SnapshotRef.class);
    when(snapshotRefUpdated.isBranch()).thenReturn(true);
    when(snapshotRefUpdated.snapshotId()).thenReturn(snapshotId + 1);
    when(updated.ref(refName)).thenReturn(snapshotRefUpdated);
    assertThatThrownBy(
            () ->
                UpdateRequirements.forUpdateTable(metadata, metadataUpdates)
                    .forEach(req -> req.validate(updated)))
        .isInstanceOf(CommitFailedException.class)
        .hasMessage("Requirement failed: branch random_branch has changed: expected id 14 != 15");
  }