Repository: apache/kafka
File: server-common/src/test/java/org/apache/kafka/server/common/MetadataVersionTest.java (Java)

Code before:
        // 3.8-IV0 is the latest production version in the 3.8 line
        assertEquals(IBP_3_8_IV0, MetadataVersion.fromVersionString("3.8", true));
        assertEquals(IBP_3_8_IV0, MetadataVersion.fromVersionString("3.8-IV0", true));

        // 3.9-IV0 is the latest production version in the 3.9 line
        assertEquals(IBP_3_9_IV0, MetadataVersion.fromVersionString("3.9", true));
        assertEquals(IBP_3_9_IV0, MetadataVersion.fromVersionString("3.9-IV0", true));

        // 4.0-IV3 is the latest production version in the 4.0 line
        assertEquals(IBP_4_0_IV3, MetadataVersion.fromVersionString("4.0", true));
        assertEquals(IBP_4_0_IV0, MetadataVersion.fromVersionString("4.0-IV0", true));
        assertEquals(IBP_4_0_IV1, MetadataVersion.fromVersionString("4.0-IV1", true));
        assertEquals(IBP_4_0_IV2, MetadataVersion.fromVersionString("4.0-IV2", true));
        assertEquals(IBP_4_0_IV3, MetadataVersion.fromVersionString("4.0-IV3", true));

        // 4.1-IV1 is the latest production version in the 4.1 line
        assertEquals(IBP_4_1_IV1, MetadataVersion.fromVersionString("4.1", true));
        assertEquals(IBP_4_1_IV0, MetadataVersion.fromVersionString("4.1-IV0", true));
        assertEquals(IBP_4_1_IV1, MetadataVersion.fromVersionString("4.1-IV1", true));

        assertEquals(IBP_4_2_IV0, MetadataVersion.fromVersionString("4.2-IV0", true));
        assertEquals(IBP_4_2_IV1, MetadataVersion.fromVersionString("4.2-IV1", true));

        // Throws exception when unstableFeatureVersionsEnabled is false
        assertThrows(IllegalArgumentException.class, () -> MetadataVersion.fromVersionString("4.2-IV0", false));
        assertThrows(IllegalArgumentException.class, () -> MetadataVersion.fromVersionString("4.2-IV1", false));
    }

    @Test
    public void testMetadataVersionsToString() {
        assertEquals("3.5-IV0, 3.5-IV1, 3.5-IV2, 3.6-IV0",
            MetadataVersion.metadataVersionsToString(MetadataVersion.IBP_3_5_IV0, MetadataVersion.IBP_3_6_IV0));
    }

    @Test
    public void testShortVersion() {
        assertEquals("3.3", IBP_3_3_IV3.shortVersion());
        assertEquals("3.4", IBP_3_4_IV0.shortVersion());
        assertEquals("3.5", IBP_3_5_IV0.shortVersion());
        assertEquals("3.5", IBP_3_5_IV1.shortVersion());
        assertEquals("3.5", IBP_3_5_IV2.shortVersion());
        assertEquals("3.6", IBP_3_6_IV0.shortVersion());
        assertEquals("3.6", IBP_3_6_IV1.shortVersion());
        assertEquals("3.6", IBP_3_6_IV2.shortVersion());
        assertEquals("3.7", IBP_3_7_IV0.shortVersion());
        assertEquals("3.7", IBP_3_7_IV1.shortVersion());
        assertEquals("3.7", IBP_3_7_IV2.shortVersion());
        assertEquals("3.7", IBP_3_7_IV3.shortVersion());
        assertEquals("3.7", IBP_3_7_IV4.shortVersion());
        assertEquals("3.8", IBP_3_8_IV0.shortVersion());
        assertEquals("3.9", IBP_3_9_IV0.shortVersion());

Review comment (suggestion):
the case `MetadataVersion.fromVersionString("4.2-IV1", true)` should be included

Code after:
        // 3.8-IV0 is the latest production version in the 3.8 line
        assertEquals(IBP_3_8_IV0, MetadataVersion.fromVersionString("3.8", true));
        assertEquals(IBP_3_8_IV0, MetadataVersion.fromVersionString("3.8-IV0", true));

        // 3.9-IV0 is the latest production version in the 3.9 line
        assertEquals(IBP_3_9_IV0, MetadataVersion.fromVersionString("3.9", true));
        assertEquals(IBP_3_9_IV0, MetadataVersion.fromVersionString("3.9-IV0", true));

        // 4.0-IV3 is the latest production version in the 4.0 line
        assertEquals(IBP_4_0_IV3, MetadataVersion.fromVersionString("4.0", true));
        assertEquals(IBP_4_0_IV0, MetadataVersion.fromVersionString("4.0-IV0", true));
        assertEquals(IBP_4_0_IV1, MetadataVersion.fromVersionString("4.0-IV1", true));
        assertEquals(IBP_4_0_IV2, MetadataVersion.fromVersionString("4.0-IV2", true));
        assertEquals(IBP_4_0_IV3, MetadataVersion.fromVersionString("4.0-IV3", true));

        // 4.1-IV1 is the latest production version in the 4.1 line
        assertEquals(IBP_4_1_IV1, MetadataVersion.fromVersionString("4.1", true));
        assertEquals(IBP_4_1_IV0, MetadataVersion.fromVersionString("4.1-IV0", true));
        assertEquals(IBP_4_1_IV1, MetadataVersion.fromVersionString("4.1-IV1", true));

        assertEquals(IBP_4_2_IV0, MetadataVersion.fromVersionString("4.2-IV0", true));
        assertEquals(IBP_4_2_IV1, MetadataVersion.fromVersionString("4.2-IV1", true));

        // Throws exception when unstableFeatureVersionsEnabled is false
        assertEquals("Unknown metadata.version '4.2-IV0'. Supported metadata.version are: 3.3-IV3, 3.4-IV0, 3.5-IV0, 3.5-IV1, 3.5-IV2, "
            + "3.6-IV0, 3.6-IV1, 3.6-IV2, 3.7-IV0, 3.7-IV1, 3.7-IV2, 3.7-IV3, 3.7-IV4, 3.8-IV0, 3.9-IV0, 4.0-IV0, 4.0-IV1, 4.0-IV2, 4.0-IV3, 4.1-IV0, 4.1-IV1",
            assertThrows(IllegalArgumentException.class, () -> fromVersionString("4.2-IV0", false)).getMessage());
        assertEquals("Unknown metadata.version '4.2-IV1'. Supported metadata.version are: 3.3-IV3, 3.4-IV0, 3.5-IV0, 3.5-IV1, 3.5-IV2, "
                + "3.6-IV0, 3.6-IV1, 3.6-IV2, 3.7-IV0, 3.7-IV1, 3.7-IV2, 3.7-IV3, 3.7-IV4, 3.8-IV0, 3.9-IV0, 4.0-IV0, 4.0-IV1, 4.0-IV2, 4.0-IV3, 4.1-IV0, 4.1-IV1",
            assertThrows(IllegalArgumentException.class, () -> fromVersionString("4.2-IV1", false)).getMessage());
    }

    @Test
    public void testMetadataVersionsToString() {
        assertEquals("3.5-IV0, 3.5-IV1, 3.5-IV2, 3.6-IV0",
            MetadataVersion.metadataVersionsToString(MetadataVersion.IBP_3_5_IV0, MetadataVersion.IBP_3_6_IV0));
    }

    @Test
    public void testShortVersion() {
        assertEquals("3.3", IBP_3_3_IV3.shortVersion());
        assertEquals("3.4", IBP_3_4_IV0.shortVersion());
        assertEquals("3.5", IBP_3_5_IV0.shortVersion());
        assertEquals("3.5", IBP_3_5_IV1.shortVersion());
        assertEquals("3.5", IBP_3_5_IV2.shortVersion());
        assertEquals("3.6", IBP_3_6_IV0.shortVersion());
        assertEquals("3.6", IBP_3_6_IV1.shortVersion());
        assertEquals("3.6", IBP_3_6_IV2.shortVersion());
        assertEquals("3.7", IBP_3_7_IV0.shortVersion());
        assertEquals("3.7", IBP_3_7_IV1.shortVersion());
        assertEquals("3.7", IBP_3_7_IV2.shortVersion());