public static SnapshotRef fromJson(String json) {
    Preconditions.checkArgument(
        json != null && !json.isEmpty(), "Cannot parse snapshot ref from invalid JSON: %s", json);
    return JsonUtil.parse(json, SnapshotRefParser::fromJson);
  }
@Test
  public void testFailWhenFieldsHaveInvalidValues() {
    String invalidSnapshotId =
        "{\"snapshot-id\":\"invalid-snapshot-id\",\"type\":\"not-a-valid-tag-type\"}";
    assertThatThrownBy(() -> SnapshotRefParser.fromJson(invalidSnapshotId))
        .isInstanceOf(IllegalArgumentException.class)
        .hasMessage("Cannot parse to a long value: snapshot-id: \"invalid-snapshot-id\"");

    String invalidTagType = "{\"snapshot-id\":1,\"type\":\"not-a-valid-tag-type\"}";
    assertThatThrownBy(() -> SnapshotRefParser.fromJson(invalidTagType))
        .isInstanceOf(IllegalArgumentException.class)
        .hasMessage("Invalid snapshot ref type: not-a-valid-tag-type");

    String invalidRefAge =
        "{\"snapshot-id\":1,\"type\":\"tag\",\"max-ref-age-ms\":\"not-a-valid-value\"}";
    assertThatThrownBy(() -> SnapshotRefParser.fromJson(invalidRefAge))
        .isInstanceOf(IllegalArgumentException.class)
        .hasMessage("Cannot parse to a long value: max-ref-age-ms: \"not-a-valid-value\"");

    String invalidSnapshotsToKeep =
        "{\"snapshot-id\":1,\"type\":\"branch\", "
            + "\"min-snapshots-to-keep\":\"invalid-number\"}";
    assertThatThrownBy(() -> SnapshotRefParser.fromJson(invalidSnapshotsToKeep))
        .isInstanceOf(IllegalArgumentException.class)
        .hasMessage("Cannot parse to an integer value: min-snapshots-to-keep: \"invalid-number\"");

    String invalidMaxSnapshotAge =
        "{\"snapshot-id\":1,\"type\":\"branch\", " + "\"max-snapshot-age-ms\":\"invalid-age\"}";
    assertThatThrownBy(() -> SnapshotRefParser.fromJson(invalidMaxSnapshotAge))
        .isInstanceOf(IllegalArgumentException.class)
        .hasMessage("Cannot parse to a long value: max-snapshot-age-ms: \"invalid-age\"");
  }