private <T> ThriftStructMetadata<T> testMetadataBuild(
      Class<T> structClass, int expectedConstructorParameters, int expectedMethodInjections) {
    ThriftCatalog catalog = new ThriftCatalog();
    ThriftUnionMetadataBuilder<T> builder = new ThriftUnionMetadataBuilder<>(catalog, structClass);
    assertNotNull(builder);

    assertNotNull(builder.getMetadataErrors());
    builder.getMetadataErrors().throwIfHasErrors();
    assertEquals(builder.getMetadataErrors().getWarnings().size(), 0);

    ThriftStructMetadata<T> metadata = builder.build();
    assertNotNull(metadata);
    assertEquals(MetadataType.UNION, metadata.getMetadataType());

    verifyField(metadata, 1, "stringValue");
    verifyField(metadata, 2, "longValue");
    verifyField(metadata, 3, "fruitValue");

    if (expectedConstructorParameters == 0) {
      assertTrue(metadata.getConstructorInjection().isPresent());
      ThriftConstructorInjection constructorInjection = metadata.getConstructorInjection().get();
      assertEquals(constructorInjection.getParameters().size(), 0);
    } else {
      for (ThriftFieldMetadata fieldMetadata : metadata.getFields(FieldType.THRIFT_FIELD)) {
        assertTrue(fieldMetadata.getConstructorInjection().isPresent());
        assertEquals(
            fieldMetadata.getConstructorInjection().get().getParameters().size(),
            expectedConstructorParameters);
      }
    }

    assertEquals(metadata.getMethodInjections().size(), expectedMethodInjections);

    return metadata;
  }