private static void writeWithExpectedLosses(
        MetadataVersion metadataVersion,
        List<String> expectedLosses,
        List<ApiMessageAndVersion> inputs,
        List<ApiMessageAndVersion> expectedOutputs
    ) {
        MockLossConsumer lossConsumer = new MockLossConsumer(metadataVersion);
        MetadataDelta delta = new MetadataDelta.Builder().build();
        RecordTestUtils.replayAll(delta, inputs);
        MetadataImage image = delta.apply(MetadataProvenance.EMPTY);
        RecordListWriter writer = new RecordListWriter();
        image.write(writer, new ImageWriterOptions.Builder().
                setMetadataVersion(metadataVersion).
                setLossHandler(lossConsumer).
                build());
        assertEquals(expectedLosses, lossConsumer.losses, "Failed to get expected metadata losses.");
        assertEquals(expectedOutputs, writer.records(), "Failed to get expected output records.");
    }
Test downgrading to a MetadataVersion that doesn't support ZK migration.
metadata/src/test/java/org/apache/kafka/image/ImageDowngradeTest.java