public void write(ImageWriter writer, ImageWriterOptions options) {
        if (options.metadataVersion().isDelegationTokenSupported()) {
            for (Entry<String, DelegationTokenData> entry : tokens.entrySet()) {
                writer.write(0, entry.getValue().toRecord());
            }
        } else {
            if (!tokens.isEmpty()) {
                List<String> tokenIds = new ArrayList<>(tokens.keySet());
                String delegationTokenImageString = "DelegationTokenImage(" + String.join(", ", tokenIds) + ")";
                options.handleLoss(delegationTokenImageString);
            } 
        }
    }
@Test
    public void testImage1withInvalidIBP() {
        ImageWriterOptions imageWriterOptions = new ImageWriterOptions.Builder().
                setMetadataVersion(MetadataVersion.IBP_3_5_IV2).build();
        RecordListWriter writer = new RecordListWriter();
        try {
            IMAGE1.write(writer, imageWriterOptions);
            fail("expected exception writing IMAGE with Delegation Token records for MetadataVersion.IBP_3_5_IV2");
        } catch (Exception expected) {
            // ignore, expected
        }
    }