void validate(Schema schema) {

    if (schema.getFieldCount() == 0) {
      throw new IllegalArgumentException(
          String.format("Schema must contain at least one field. Schema: %s", schema));
    }

    validateAttributesField(schema);
    validateSourceEventTimeStampField(schema);
    validateSerializableFields(schema);
  }
@Test
  public void testValidate() {
    PubsubRowToMessage pubsubRowToMessage = PubsubRowToMessage.builder().build();
    PayloadSerializer jsonPayloadSerializer =
        new JsonPayloadSerializerProvider().getSerializer(ALL_DATA_TYPES_SCHEMA, ImmutableMap.of());

    assertThrows(
        IllegalArgumentException.class,
        () -> pubsubRowToMessage.validate(Schema.builder().build()));

    assertThrows(
        IllegalArgumentException.class,
        () ->
            pubsubRowToMessage.validate(
                Schema.of(Field.of(DEFAULT_ATTRIBUTES_KEY_NAME, FieldType.STRING))));

    assertThrows(
        IllegalArgumentException.class,
        () ->
            pubsubRowToMessage.validate(
                Schema.of(
                    Field.of(
                        DEFAULT_ATTRIBUTES_KEY_NAME,
                        FieldType.map(FieldType.STRING, FieldType.BYTES)))));

    assertThrows(
        IllegalArgumentException.class,
        () ->
            pubsubRowToMessage.validate(
                Schema.of(
                    Field.of(
                        DEFAULT_ATTRIBUTES_KEY_NAME,
                        FieldType.map(FieldType.BYTES, FieldType.STRING)))));
    assertThrows(
        IllegalArgumentException.class,
        () ->
            pubsubRowToMessage.validate(
                Schema.of(Field.of(DEFAULT_EVENT_TIMESTAMP_KEY_NAME, FieldType.STRING))));

    assertThrows(
        IllegalArgumentException.class,
        () -> PubsubRowToMessage.builder().build().validate(ALL_DATA_TYPES_SCHEMA));

    assertThrows(
        IllegalArgumentException.class,
        () -> PubsubRowToMessage.builder().build().validate(NON_USER_WITH_ROW_PAYLOAD));

    assertThrows(
        IllegalArgumentException.class,
        () ->
            PubsubRowToMessage.builder()
                .setPayloadSerializer(jsonPayloadSerializer)
                .build()
                .validate(NON_USER_WITH_BYTES_PAYLOAD));

    assertThrows(
        IllegalArgumentException.class,
        () ->
            PubsubRowToMessage.builder()
                .build()
                .validate(merge(ALL_DATA_TYPES_SCHEMA, NON_USER_WITH_BYTES_PAYLOAD)));

    assertThrows(
        IllegalArgumentException.class,
        () ->
            PubsubRowToMessage.builder()
                .build()
                .validate(merge(ALL_DATA_TYPES_SCHEMA, NON_USER_WITH_ROW_PAYLOAD)));
  }