void validateSnapshotsUpdate(
      TableMetadata metadata, List<Snapshot> addedSnapshots, List<Snapshot> deletedSnapshots) {
    if (metadata.currentSnapshot() == null) {
      // no need to verify attempt to delete current snapshot if it doesn't exist
      // deletedSnapshots is necessarily empty when original snapshots list is empty
      return;
    }
    if (!addedSnapshots.isEmpty()) {
      // latest snapshot can be deleted if new snapshots are added.
      return;
    }
    long latestSnapshotId = metadata.currentSnapshot().snapshotId();
    if (!deletedSnapshots.isEmpty()
        && deletedSnapshots.get(deletedSnapshots.size() - 1).snapshotId() == latestSnapshotId) {
      throw new InvalidIcebergSnapshotException(
          String.format("Cannot delete the latest snapshot %s", latestSnapshotId));
    }
  }
@Test
  void testValidateSnapshotsUpdateWithNoSnapshotMetadata() throws IOException {

    List<Snapshot> testSnapshots = IcebergTestUtil.getSnapshots();
    // No exception since added as well deleted snapshots are allowed to support replication
    // use case which performs table commit with added and deleted snapshots.
    Assertions.assertDoesNotThrow(
        () ->
            snapshotInspector.validateSnapshotsUpdate(
                noSnapshotsMetadata, testSnapshots.subList(0, 1), testSnapshots.subList(1, 4)));
    Assertions.assertDoesNotThrow(
        () ->
            snapshotInspector.validateSnapshotsUpdate(
                noSnapshotsMetadata, testSnapshots, Collections.emptyList()));
    Assertions.assertDoesNotThrow(
        () ->
            snapshotInspector.validateSnapshotsUpdate(
                noSnapshotsMetadata, Collections.emptyList(), testSnapshots));
  }