static void sanityCheckTypical(Builder builder) {
    int numSetTypical = builder._typicalBrokerId != DEFAULT_OPTIONAL_INT ? 1 : 0;
    if (builder._typicalBrokerCapacity != DEFAULT_OPTIONAL_DOUBLE) {
      numSetTypical++;
    }

    if (numSetTypical == 1) {
      throw new IllegalArgumentException(
          String.format("Typical broker id must be specified with its capacity (Id:%s Capacity:%s).",
                        builder._typicalBrokerId == DEFAULT_OPTIONAL_INT ? "-" : String.valueOf(builder._typicalBrokerId),
                        builder._typicalBrokerCapacity == DEFAULT_OPTIONAL_DOUBLE ? "-" : String.valueOf(builder._typicalBrokerCapacity)));
    } else if (numSetTypical == 2) {
      if (builder._numBrokers == DEFAULT_OPTIONAL_INT) {
        throw new IllegalArgumentException("Typical broker id and capacity cannot be specified without number of brokers.");
      } else if (builder._resource == null) {
        throw new IllegalArgumentException("Typical broker id and capacity cannot be specified without the resource.");
      }
    }
  }
@Test
  public void testSanityCheckTypical() {
    // Set a typical broker id without its capacity.
    assertThrows(IllegalArgumentException.class, () -> ProvisionRecommendation.sanityCheckTypical(
        new ProvisionRecommendation.Builder(ProvisionStatus.UNDER_PROVISIONED).numBrokers(1).typicalBrokerId(1).resource(Resource.CPU)));

    // Skip setting numBrokers.
    assertThrows(IllegalArgumentException.class, () -> ProvisionRecommendation.sanityCheckTypical(
        new ProvisionRecommendation.Builder(ProvisionStatus.UNDER_PROVISIONED).typicalBrokerId(1).typicalBrokerCapacity(1.0)
                                                                              .resource(Resource.CPU)));

    // Skip setting resource.
    assertThrows(IllegalArgumentException.class, () -> ProvisionRecommendation.sanityCheckTypical(
        new ProvisionRecommendation.Builder(ProvisionStatus.UNDER_PROVISIONED).typicalBrokerId(1).typicalBrokerCapacity(1.0).numBrokers(1)));
  }