public MessageType convert(Schema avroSchema) {
    if (!avroSchema.getType().equals(Schema.Type.RECORD)) {
      throw new IllegalArgumentException("Avro schema must be a record.");
    }
    return new MessageType(avroSchema.getFullName(), convertFields(avroSchema.getFields(), ""));
  }
@Test
  public void testTimestampMicrosType() throws Exception {
    Schema date = LogicalTypes.timestampMicros().addToSchema(Schema.create(LONG));
    Schema expected = Schema.createRecord(
        "myrecord", null, null, false, Arrays.asList(new Schema.Field("timestamp", date, null, null)));

    testRoundTripConversion(
        expected, "message myrecord {\n" + "  required int64 timestamp (TIMESTAMP(MICROS,true));\n" + "}\n");

    for (PrimitiveTypeName primitive :
        new PrimitiveTypeName[] {INT32, INT96, FLOAT, DOUBLE, BOOLEAN, BINARY, FIXED_LEN_BYTE_ARRAY}) {
      final PrimitiveType type;
      if (primitive == FIXED_LEN_BYTE_ARRAY) {
        type = new PrimitiveType(REQUIRED, primitive, 12, "test", TIMESTAMP_MICROS);
      } else {
        type = new PrimitiveType(REQUIRED, primitive, "test", TIMESTAMP_MICROS);
      }

      assertThrows(
          "Should not allow TIMESTAMP_MICROS with " + primitive,
          IllegalArgumentException.class,
          () -> new AvroSchemaConverter().convert(message(type)));
    }

    // Test that conversions for timestamp types only use APIs that are available in the user's Avro version
    for (String avroVersion : ImmutableSet.of("1.7.0", "1.8.0", "1.9.0", "1.10.0", "1.11.0")) {
      Mockito.when(AvroRecordConverter.getRuntimeAvroVersion()).thenReturn(avroVersion);
      final Schema converted = new AvroSchemaConverter()
          .convert(Types.buildMessage()
              .addField(Types.primitive(INT64, Type.Repetition.REQUIRED)
                  .as(LogicalTypeAnnotation.timestampType(
                      false, LogicalTypeAnnotation.TimeUnit.MICROS))
                  .length(1)
                  .named("timestamp_type"))
              .named("TestAvro"));

      assertEquals(
          avroVersion.matches("1\\.[789]\\.\\d+") ? "timestamp-micros" : "local-timestamp-micros",
          converted
              .getField("timestamp_type")
              .schema()
              .getLogicalType()
              .getName());
    }
  }