static Builder builder() {
    return new AutoValue_PubsubRowToMessage.Builder();
  }
@Test(expected = IllegalArgumentException.class)
  public void testExpandThrowsExceptions() {
    PayloadSerializer jsonPayloadSerializer =
        new JsonPayloadSerializerProvider().getSerializer(ALL_DATA_TYPES_SCHEMA, ImmutableMap.of());

    Instant embeddedTimestamp = Instant.now();
    Instant mockTimestamp = Instant.ofEpochMilli(embeddedTimestamp.getMillis() + 1000000L);

    Field attributesField = Field.of(DEFAULT_ATTRIBUTES_KEY_NAME, ATTRIBUTES_FIELD_TYPE);
    Schema withAttributesSchema = Schema.of(attributesField);
    Row withAttributes =
        Row.withSchema(withAttributesSchema).attachValues(ImmutableMap.of("aaa", "111"));

    Field timestampField = Field.of(DEFAULT_EVENT_TIMESTAMP_KEY_NAME, EVENT_TIMESTAMP_FIELD_TYPE);
    Schema withTimestampSchema = Schema.of(timestampField);
    Row withEmbeddedTimestamp = Row.withSchema(withTimestampSchema).attachValues(embeddedTimestamp);

    Field payloadBytesField = Field.of(DEFAULT_PAYLOAD_KEY_NAME, FieldType.BYTES);
    Schema withPayloadBytesSchema = Schema.of(payloadBytesField);
    Row withPayloadBytes =
        Row.withSchema(withPayloadBytesSchema).attachValues(new byte[] {1, 2, 3, 4});

    Row withAllDataTypes =
        rowWithAllDataTypes(
            true,
            (byte) 0,
            Instant.now().toDateTime(),
            BigDecimal.valueOf(1L),
            3.12345,
            4.1f,
            (short) 5,
            2,
            7L,
            "asdfjkl;");

    Field payloadRowField =
        Field.of(DEFAULT_PAYLOAD_KEY_NAME, FieldType.row(ALL_DATA_TYPES_SCHEMA));
    Schema withPayloadRowSchema = Schema.of(payloadRowField);
    Row withPayloadRow = Row.withSchema(withPayloadRowSchema).attachValues(withAllDataTypes);

    PubsubRowToMessage transformWithoutSerializer =
        PubsubRowToMessage.builder().setMockInstant(mockTimestamp).build();

    PubsubRowToMessage transformWithSerializer =
        PubsubRowToMessage.builder().setPayloadSerializer(jsonPayloadSerializer).build();

    // requires either payload or user fields
    errorsTestPipeline
        .apply(Create.of(withAttributes))
        .setRowSchema(withAttributesSchema)
        .apply(transformWithoutSerializer);

    // requires either payload or user fields
    errorsTestPipeline
        .apply(Create.of(withEmbeddedTimestamp))
        .setRowSchema(withTimestampSchema)
        .apply(transformWithoutSerializer);

    // payload bytes incompatible with non-null payload serializer
    errorsTestPipeline
        .apply(Create.of(withPayloadBytes))
        .setRowSchema(withPayloadBytesSchema)
        .apply(transformWithSerializer);

    // payload row requires payload serializer
    errorsTestPipeline
        .apply(Create.of(withPayloadRow))
        .setRowSchema(withPayloadRowSchema)
        .apply(transformWithoutSerializer);

    // user fields row requires payload serializer
    errorsTestPipeline
        .apply(Create.of(withAllDataTypes))
        .setRowSchema(ALL_DATA_TYPES_SCHEMA)
        .apply(transformWithoutSerializer);

    // input with both payload row and user fields incompatible
    errorsTestPipeline
        .apply(Create.of(merge(withPayloadRow, withAllDataTypes)))
        .setRowSchema(merge(withPayloadRowSchema, ALL_DATA_TYPES_SCHEMA))
        .apply(transformWithSerializer);
  }