Repository: apache/kafka
File: clients/src/test/java/org/apache/kafka/common/telemetry/internals/ClientTelemetryUtilsTest.java (Java)

Code before:
    @Test
    public void testValidateClientInstanceId() {
        assertThrows(IllegalArgumentException.class, () -> ClientTelemetryUtils.validateClientInstanceId(null));
        assertThrows(IllegalArgumentException.class, () -> ClientTelemetryUtils.validateClientInstanceId(Uuid.ZERO_UUID));

        Uuid uuid = Uuid.randomUuid();
        assertEquals(uuid, ClientTelemetryUtils.validateClientInstanceId(uuid));
    }

    @ParameterizedTest
    @ValueSource(ints = {300_000, Integer.MAX_VALUE - 1, Integer.MAX_VALUE})
    public void testValidateIntervalMsValid(int pushIntervalMs) {
        assertEquals(pushIntervalMs, ClientTelemetryUtils.validateIntervalMs(pushIntervalMs));
    }

    @ParameterizedTest
    @ValueSource(ints = {-1, 0})
    public void testValidateIntervalMsInvalid(int pushIntervalMs) {
        assertEquals(ClientTelemetryReporter.DEFAULT_PUSH_INTERVAL_MS, ClientTelemetryUtils.validateIntervalMs(pushIntervalMs));
    }

    @Test
    public void testPreferredCompressionType() {
        // Test with no unsupported types
        assertEquals(CompressionType.NONE, ClientTelemetryUtils.preferredCompressionType(List.of(), Set.of()));
        assertEquals(CompressionType.NONE, ClientTelemetryUtils.preferredCompressionType(Arrays.asList(CompressionType.NONE, CompressionType.GZIP), Set.of()));
        assertEquals(CompressionType.GZIP, ClientTelemetryUtils.preferredCompressionType(Arrays.asList(CompressionType.GZIP, CompressionType.NONE), Set.of()));

        // Test unsupported type filtering (returns first available type, or NONE if all are unsupported)
        assertEquals(CompressionType.LZ4, ClientTelemetryUtils.preferredCompressionType(Arrays.asList(CompressionType.GZIP, CompressionType.LZ4), Set.of(CompressionType.GZIP)));
        assertEquals(CompressionType.SNAPPY, ClientTelemetryUtils.preferredCompressionType(Arrays.asList(CompressionType.GZIP, CompressionType.LZ4, CompressionType.SNAPPY), Set.of(CompressionType.GZIP, CompressionType.LZ4)));
        assertEquals(CompressionType.NONE, ClientTelemetryUtils.preferredCompressionType(Arrays.asList(CompressionType.GZIP, CompressionType.LZ4), Set.of(CompressionType.GZIP, CompressionType.LZ4)));
        
        // Test edge case: no match between requested and supported types
        assertEquals(CompressionType.GZIP, ClientTelemetryUtils.preferredCompressionType(Arrays.asList(CompressionType.GZIP, CompressionType.LZ4), Set.of(CompressionType.SNAPPY)));

        // Test NullPointerException for null parameters
        assertThrows(NullPointerException.class, () ->
            ClientTelemetryUtils.preferredCompressionType(null, Set.of()));
        assertThrows(NullPointerException.class, () ->
            ClientTelemetryUtils.preferredCompressionType(Arrays.asList(CompressionType.GZIP, CompressionType.NONE), null));
    }

    @ParameterizedTest
    @EnumSource(CompressionType.class)
    public void testCompressDecompress(CompressionType compressionType) throws IOException {
        MetricsData metricsData = getMetricsData();
        byte[] raw = metricsData.toByteArray();
        ByteBuffer compressed = ClientTelemetryUtils.compress(metricsData, compressionType);
        assertNotNull(compressed);
        if (compressionType != CompressionType.NONE) {

Review comment (suggestion):
Use List.of instead of Arrays.asList, same else where. I thought comment [here](https://github.com/apache/kafka/pull/20144#discussion_r2285718764) will help you understand that other places can be corrected as well.

Code after:
        assertThrows(IllegalArgumentException.class, () -> ClientTelemetryUtils.validateClientInstanceId(null));
        assertThrows(IllegalArgumentException.class, () -> ClientTelemetryUtils.validateClientInstanceId(Uuid.ZERO_UUID));

        Uuid uuid = Uuid.randomUuid();
        assertEquals(uuid, ClientTelemetryUtils.validateClientInstanceId(uuid));
    }

    @ParameterizedTest
    @ValueSource(ints = {300_000, Integer.MAX_VALUE - 1, Integer.MAX_VALUE})
    public void testValidateIntervalMsValid(int pushIntervalMs) {
        assertEquals(pushIntervalMs, ClientTelemetryUtils.validateIntervalMs(pushIntervalMs));
    }

    @ParameterizedTest
    @ValueSource(ints = {-1, 0})
    public void testValidateIntervalMsInvalid(int pushIntervalMs) {
        assertEquals(ClientTelemetryReporter.DEFAULT_PUSH_INTERVAL_MS, ClientTelemetryUtils.validateIntervalMs(pushIntervalMs));
    }

    @Test
    public void testPreferredCompressionType() {
        // Test with no unsupported types
        assertEquals(CompressionType.NONE, ClientTelemetryUtils.preferredCompressionType(List.of(), Set.of()));
        assertEquals(CompressionType.NONE, ClientTelemetryUtils.preferredCompressionType(List.of(CompressionType.NONE, CompressionType.GZIP), Set.of()));
        assertEquals(CompressionType.GZIP, ClientTelemetryUtils.preferredCompressionType(List.of(CompressionType.GZIP, CompressionType.NONE), Set.of()));

        // Test unsupported type filtering (returns first available type, or NONE if all are unsupported)
        assertEquals(CompressionType.LZ4, ClientTelemetryUtils.preferredCompressionType(List.of(CompressionType.GZIP, CompressionType.LZ4), Set.of(CompressionType.GZIP)));
        assertEquals(CompressionType.SNAPPY, ClientTelemetryUtils.preferredCompressionType(List.of(CompressionType.GZIP, CompressionType.LZ4, CompressionType.SNAPPY), Set.of(CompressionType.GZIP, CompressionType.LZ4)));
        assertEquals(CompressionType.NONE, ClientTelemetryUtils.preferredCompressionType(List.of(CompressionType.GZIP, CompressionType.LZ4), Set.of(CompressionType.GZIP, CompressionType.LZ4)));
        
        // Test edge case: no match between requested and supported types
        assertEquals(CompressionType.GZIP, ClientTelemetryUtils.preferredCompressionType(List.of(CompressionType.GZIP, CompressionType.LZ4), Set.of(CompressionType.SNAPPY)));

        // Test NullPointerException for null parameters
        assertThrows(NullPointerException.class, () ->
            ClientTelemetryUtils.preferredCompressionType(null, Set.of()));
        assertThrows(NullPointerException.class, () ->
            ClientTelemetryUtils.preferredCompressionType(List.of(CompressionType.GZIP, CompressionType.NONE), null));
    }

    @ParameterizedTest
    @EnumSource(CompressionType.class)
    public void testCompressDecompress(CompressionType compressionType) throws IOException {
        MetricsData metricsData = getMetricsData();
        byte[] raw = metricsData.toByteArray();
        ByteBuffer compressed = ClientTelemetryUtils.compress(metricsData, compressionType);
        assertNotNull(compressed);
        if (compressionType != CompressionType.NONE) {
            assertTrue(compressed.limit() < raw.length);
        } else {