public FinalizedFeatures(
        MetadataVersion metadataVersion,
        Map<String, Short> finalizedFeatures,
        long finalizedFeaturesEpoch,
        boolean kraftMode
    ) {
        this.metadataVersion = metadataVersion;
        this.finalizedFeatures = new HashMap<>(finalizedFeatures);
        this.finalizedFeaturesEpoch = finalizedFeaturesEpoch;
        // In KRaft mode, we always include the metadata version in the features map.
        // In ZK mode, we never include it.
        if (kraftMode) {
            this.finalizedFeatures.put(MetadataVersion.FEATURE_NAME, metadataVersion.featureLevel());
        } else {
            this.finalizedFeatures.remove(MetadataVersion.FEATURE_NAME);
        }
    }
@Test
    public void testKRaftModeFeatures() {
        FinalizedFeatures finalizedFeatures = new FinalizedFeatures(MINIMUM_KRAFT_VERSION,
                Collections.singletonMap("foo", (short) 2), 123, true);
        assertEquals(MINIMUM_KRAFT_VERSION.featureLevel(),
                finalizedFeatures.finalizedFeatures().get(FEATURE_NAME));
        assertEquals((short) 2,
                finalizedFeatures.finalizedFeatures().get("foo"));
        assertEquals(2, finalizedFeatures.finalizedFeatures().size());
    }