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

Code before:
    @ParameterizedTest
    @MethodSource("teIsTrailersTruthTable")
    void whenTeIsNotTrailerOrNotSWithNameAsciiStringAndValueString(
            AsciiString headerName, AsciiString headerValue, boolean result) {
        assertEquals(result, HttpHeaderValidationUtil.isTeNotTrailers(headerName, headerValue.toString()));
    }

    @ParameterizedTest
    @MethodSource("teIsTrailersTruthTable")
    void whenTeIsNotTrailerOrNotSWithNametringAndValueAsciiString(
            AsciiString headerName, AsciiString headerValue, boolean result) {
        assertEquals(result, HttpHeaderValidationUtil.isTeNotTrailers(headerName.toString(), headerValue));
    }

    public static List<AsciiString> illegalFirstChar() {
        List<AsciiString> list = new ArrayList<AsciiString>();

        for (byte i = 0; i < 0x21; i++) {
            asciiStrings(new byte[]{i, 'a'}, list);
        }
        asciiStrings(new byte[]{0x7F, 'a'}, list);

        return list;
    }

    public static void asciiStrings(byte[] chars, List<AsciiString> out) {
        out.add(new AsciiString(chars));
        out.add(new AsciiString(Arrays.copyOf(chars, chars.length + 1), 0, chars.length, false));

        byte[] cs = Arrays.copyOf(chars, chars.length + 1);
        System.arraycopy(cs, 0, cs, 1, chars.length);
        out.add(new AsciiString(cs, 1, chars.length, false));

        cs = Arrays.copyOf(chars, chars.length + 2);
        System.arraycopy(cs, 0, cs, 1, chars.length);
        out.add(new AsciiString(cs, 1, chars.length, false));
    }

    @ParameterizedTest
    @MethodSource("illegalFirstChar")
    void decodingInvalidHeaderValuesMustFailIfFirstCharIsIllegalAsciiString(AsciiString value) {
        assertEquals(0, validateValidHeaderValue(value));
    }

    @ParameterizedTest
    @MethodSource("illegalFirstChar")
    void decodingInvalidHeaderValuesMustFailIfFirstCharIsIllegalCharSequence(AsciiString value) {
        assertEquals(0, validateValidHeaderValue(asCharSequence(value)));
    }

    public static List<AsciiString> legalFirstChar() {

Review comment (suggestion):
```suggestion
    private static void asciiStrings(byte[] chars, List<AsciiString> out) {
```

Code after:
    @ParameterizedTest
    @MethodSource("teIsTrailersTruthTable")
    void whenTeIsNotTrailerOrNotSWithNameAsciiStringAndValueString(
            AsciiString headerName, AsciiString headerValue, boolean result) {
        assertEquals(result, HttpHeaderValidationUtil.isTeNotTrailers(headerName, headerValue.toString()));
    }

    @ParameterizedTest
    @MethodSource("teIsTrailersTruthTable")
    void whenTeIsNotTrailerOrNotSWithNametringAndValueAsciiString(
            AsciiString headerName, AsciiString headerValue, boolean result) {
        assertEquals(result, HttpHeaderValidationUtil.isTeNotTrailers(headerName.toString(), headerValue));
    }

    public static List<AsciiString> illegalFirstChar() {
        List<AsciiString> list = new ArrayList<AsciiString>();

        for (byte i = 0; i < 0x21; i++) {
            asciiStrings(new byte[]{i, 'a'}, list);
        }
        asciiStrings(new byte[]{0x7F, 'a'}, list);

        return list;
    }

    private static void asciiStrings(byte[] chars, List<AsciiString> out) {
        out.add(new AsciiString(chars));
        out.add(new AsciiString(Arrays.copyOf(chars, chars.length + 1), 0, chars.length, false));

        byte[] cs = Arrays.copyOf(chars, chars.length + 1);
        System.arraycopy(cs, 0, cs, 1, chars.length);
        out.add(new AsciiString(cs, 1, chars.length, false));

        cs = Arrays.copyOf(chars, chars.length + 2);
        System.arraycopy(cs, 0, cs, 1, chars.length);
        out.add(new AsciiString(cs, 1, chars.length, false));
    }

    @ParameterizedTest
    @MethodSource("illegalFirstChar")
    void decodingInvalidHeaderValuesMustFailIfFirstCharIsIllegalAsciiString(AsciiString value) {
        assertEquals(0, validateValidHeaderValue(value));
    }

    @ParameterizedTest
    @MethodSource("illegalFirstChar")
    void decodingInvalidHeaderValuesMustFailIfFirstCharIsIllegalCharSequence(AsciiString value) {
        assertEquals(0, validateValidHeaderValue(asCharSequence(value)));
    }

    public static List<AsciiString> legalFirstChar() {