@Test
public void swapRecordTypes() {

    FileDescriptor updatedFile = mutateFile(fileBuilder -> {
        // Update the field of the union descriptor.
        fileBuilder.getMessageTypeBuilderList().forEach(messageType -> {
            if (messageType.getName().equals(RecordMetaDataBuilder.DEFAULT_UNION_NAME)) {
                messageType.getFieldBuilderList().forEach(field -> {
                    if (field.getName().equals("_MyOtherRecord")) {
                        field.setTypeName("MySimpleRecord");
                    }
                    if (field.getName().equals("_MySimpleRecord")) {
                        field.setTypeName("MyOtherRecord");
                    }
                });
            }
        });
    });
    RecordMetaDataBuilder metaDataBuilder = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
    metaDataBuilder.addIndex("MyOtherRecord", "num_value_3_indexed");
    RecordMetaData metaData1 = metaDataBuilder.getRecordMetaData();
    // Swap is noticed as the two records are not of compatible forms
    RecordMetaData metaData2 = replaceRecordsDescriptor(metaData1, updatedFile);
    assertInvalid("", metaData1, metaData2);
}