Repository: netty/netty
File: codec-http3/src/test/java/io/netty/handler/codec/http3/Http3SettingsTest.java (Java)

Code before:

    @Test
    void testVerifyStandardSettingValidCases() {
        Http3Settings settings = new Http3Settings();
        settings.put(Http3SettingIdentifier.HTTP3_SETTINGS_ENABLE_CONNECT_PROTOCOL.id(), 1L);
        settings.put(Http3SettingIdentifier.HTTP3_SETTINGS_ENABLE_CONNECT_PROTOCOL.id(), 1L);
        settings.put(Http3SettingIdentifier.HTTP3_SETTINGS_QPACK_MAX_TABLE_CAPACITY.id(), 0L);
        settings.put(Http3SettingIdentifier.HTTP3_SETTINGS_QPACK_BLOCKED_STREAMS.id(), 5L);
        settings.put(Http3SettingIdentifier.HTTP3_SETTINGS_MAX_FIELD_SECTION_SIZE.id(), 4096L);

        assertEquals(Boolean.TRUE, settings.connectProtocolEnabled());
        assertEquals(4096L, settings.maxFieldSectionSize());
    }

    @Test
    void testCustomSettingsIgnored() {
        Http3Settings settings = new Http3Settings();
        long customKey = 0xdeadbeefL;
        settings.put(customKey, 123L);
        assertNull(settings.get(customKey));
    }

    @Test
    void testCustomSettingsNotIgnoredWithValidator() {
        long customKey = 0xdeadbeefL;
        Http3Settings settings = new Http3Settings((id, v) -> customKey == id);
        settings.put(customKey, 123L);
        assertNotNull(settings.get(customKey));
    }

    @Test
    void testDefaultSettingsBuilderPattern() {
        Http3Settings s = new Http3Settings()
                .qpackMaxTableCapacity(10)
                .enableConnectProtocol(false)
                .qpackBlockedStreams(1)
                .maxFieldSectionSize(100);

        assertEquals(10L, s.qpackMaxTableCapacity());
        assertEquals(Boolean.FALSE, s.connectProtocolEnabled());
        assertEquals(1L, s.qpackBlockedStreams());
        assertEquals(100L, s.maxFieldSectionSize());
    }

    @Test
    void testToStringAndKeyToStringIndirectly() {
        Http3Settings settings = new Http3Settings()
                .qpackMaxTableCapacity(1)
                .qpackBlockedStreams(2)
                .enableConnectProtocol(true);


Review comment (suggestion):
@normanmaurer please add this too

```
@Test
void testCustomSettingsValidatorAllowsAndRejectsMultipleKeys() {
    Set<Long> allowedKeys = Set.of(
        0xdeadbeefL,
        0xcafebabeL
    );

    long rejectedKey = 0xfeedfaceL;

    Http3Settings settings = new Http3Settings(
        (id, v) -> allowedKeys.contains(id)
    );

    // Allowed keys
    allowedKeys.forEach(key -> {
        settings.put(key, 1L);
        assertNotNull(settings.get(key));
    });

    // Rejected key
    settings.put(rejectedKey, 1L);
    assertNull(settings.get(rejectedKey));
}

```

Code after:
        assertThrows(IllegalArgumentException.class,
                () -> settings.put(Http3SettingIdentifier.HTTP3_SETTINGS_ENABLE_CONNECT_PROTOCOL.id(), 15L));
    }

    @Test
    void testVerifyStandardSettingValidCases() {
        Http3Settings settings = new Http3Settings();
        settings.put(Http3SettingIdentifier.HTTP3_SETTINGS_ENABLE_CONNECT_PROTOCOL.id(), 1L);
        settings.put(Http3SettingIdentifier.HTTP3_SETTINGS_ENABLE_CONNECT_PROTOCOL.id(), 1L);
        settings.put(Http3SettingIdentifier.HTTP3_SETTINGS_QPACK_MAX_TABLE_CAPACITY.id(), 0L);
        settings.put(Http3SettingIdentifier.HTTP3_SETTINGS_QPACK_BLOCKED_STREAMS.id(), 5L);
        settings.put(Http3SettingIdentifier.HTTP3_SETTINGS_MAX_FIELD_SECTION_SIZE.id(), 4096L);

        assertEquals(Boolean.TRUE, settings.connectProtocolEnabled());
        assertEquals(4096L, settings.maxFieldSectionSize());
    }

    @Test
    void testCustomSettingsIgnored() {
        Http3Settings settings = new Http3Settings();
        long customKey = 0xdeadbeefL;
        settings.put(customKey, 123L);
        assertNull(settings.get(customKey));
    }

    @Test
    void testCustomSettingsNotIgnoredWithValidator() {
        long customKey = 0xdeadbeefL;
        Http3Settings settings = new Http3Settings((id, v) -> customKey == id);
        settings.put(customKey, 123L);
        assertNotNull(settings.get(customKey));
    }

    @Test
    void testCustomSettingsValidatorAllowsAndRejectsMultipleKeys() {
        Set<Long> allowedKeys = new HashSet<>(Arrays.asList(
                0xdeadbeefL,
                0xcafebabeL
        ));

        long rejectedKey = 0xfeedfaceL;

        Http3Settings settings = new Http3Settings(
                (id, v) -> allowedKeys.contains(id)
        );

        // Allowed keys
        allowedKeys.forEach(key -> {
            settings.put(key, 1L);
            assertNotNull(settings.get(key));
        });