@Test
public void splitTypes() {

    // Add a second "MyOtherRecord" to the union descriptor
    FileDescriptor updatedDescriptor = mutateFile(fileBuilder ->
            fileBuilder.getMessageTypeBuilderList().forEach(message -> {
                if (message.getName().equals(RecordMetaDataBuilder.DEFAULT_UNION_NAME)) {
                    message.addField(DescriptorProtos.FieldDescriptorProto.newBuilder()
                            .setLabel(DescriptorProtos.FieldDescriptorProto.Label.LABEL_OPTIONAL)
                            .setType(DescriptorProtos.FieldDescriptorProto.Type.TYPE_MESSAGE)
                            .setTypeName("MyOtherRecord")
                            .setName("_MyOtherOtherRecord")
                            .setNumber(message.getFieldList().stream().mapToInt(DescriptorProtos.FieldDescriptorProto::getNumber).max().orElse(0) + 1));
                }
            })
    );
    RecordMetaData metaData1 = RecordMetaData.build(updatedDescriptor);
    assertThat(metaData1.getRecordTypes().keySet(), containsInAnyOrder("MySimpleRecord", "MyOtherRecord"));
    FileDescriptor secondDescriptor = mutateFile(updatedDescriptor, fileBuilder -> {
        DescriptorProtos.DescriptorProto newMessageType = fileBuilder.getMessageTypeList().stream()
                .filter(message -> message.getName().equals("MyOtherRecord"))
                .findFirst()
                .get()
                .toBuilder()
                .setName("MyOtherOtherRecord")
                .build();
        fileBuilder.addMessageType(newMessageType);
        fileBuilder.getMessageTypeBuilderList().forEach(message -> {
            if (message.getName().equals(RecordMetaDataBuilder.DEFAULT_UNION_NAME)) {
                message.getFieldBuilderList().forEach(field -> {
                    if (field.getName().equals("_MyOtherOtherRecord")) {
                        field.setTypeName("MyOtherOtherRecord");
                    }
                });
            }
        });
    });
    RecordMetaData metaData2 = replaceRecordsDescriptor(metaData1, secondDescriptor, metaDataProtoBuilder ->
            metaDataProtoBuilder.addRecordTypes(RecordMetaDataProto.RecordType.newBuilder()
                    .setName("MyOtherOtherRecord")
                    .setPrimaryKey(Key.Expressions.field("rec_no").toKeyExpression())
            )
    );
    assertThat(metaData2.getRecordTypes().keySet(), containsInAnyOrder("MySimpleRecord", "MyOtherRecord", "MyOtherOtherRecord"));
    assertInvalid("record type corresponds to multiple types in new meta-data", metaData1, metaData2);
}