static void sanityCheckResources(Builder builder) {
    int numSetResources = builder._numBrokers != DEFAULT_OPTIONAL_INT ? 1 : 0;
    if (builder._numRacks != DEFAULT_OPTIONAL_INT) {
      numSetResources++;
    }
    if (builder._numDisks != DEFAULT_OPTIONAL_INT) {
      numSetResources++;
    }
    if (builder._numPartitions != DEFAULT_OPTIONAL_INT) {
      numSetResources++;
    }

    if (numSetResources != 1) {
      throw new IllegalArgumentException(
          String.format("Exactly one resource type must be set (Brokers:%s Racks:%s Disks:%s Partitions:%s).",
                        builder._numBrokers == DEFAULT_OPTIONAL_INT ? "-" : String.valueOf(builder._numBrokers),
                        builder._numRacks == DEFAULT_OPTIONAL_INT ? "-" : String.valueOf(builder._numRacks),
                        builder._numDisks == DEFAULT_OPTIONAL_INT ? "-" : String.valueOf(builder._numDisks),
                        builder._numPartitions == DEFAULT_OPTIONAL_INT ? "-" : String.valueOf(builder._numPartitions)));
    }

    if (builder._numPartitions != DEFAULT_OPTIONAL_INT) {
      if (builder._status != ProvisionStatus.UNDER_PROVISIONED) {
        throw new IllegalArgumentException("When the resource type is partition, the cluster must be under provisioned.");
      } else if (builder._topicPattern == null) {
        throw new IllegalArgumentException("When the resource type is partition, the corresponding topic regex must be specified.");
      }
    } else if (builder._topicPattern != null) {
      throw new IllegalArgumentException("When the resource type is not partition, topic regex cannot be specified.");
    }
  }
@Test
  public void testSanityCheckResources() {
    // Set multiple resources
    assertThrows(IllegalArgumentException.class, () -> ProvisionRecommendation.sanityCheckResources(
        new ProvisionRecommendation.Builder(ProvisionStatus.UNDER_PROVISIONED).numBrokers(1).numRacks(1)));

    // Set numPartitions under over-provisioned state
    assertThrows(IllegalArgumentException.class, () -> ProvisionRecommendation.sanityCheckResources(
        new ProvisionRecommendation.Builder(ProvisionStatus.OVER_PROVISIONED).numPartitions(1)));

    // Set numPartitions without the topic
    assertThrows(IllegalArgumentException.class, () -> ProvisionRecommendation.sanityCheckResources(
        new ProvisionRecommendation.Builder(ProvisionStatus.UNDER_PROVISIONED).numPartitions(1)));
  }