@Test
    public void testInvalidSaslAuthenticateRequest() {
        short version = (short) 1; // choose a version with fixed length encoding, for simplicity
        byte[] b = new byte[] {
            0x11, 0x1f, 0x15, 0x2c,
            0x5e, 0x2a, 0x20, 0x26,
            0x6c, 0x39, 0x45, 0x1f,
            0x25, 0x1c, 0x2d, 0x25,
            0x43, 0x2a, 0x11, 0x76
        };
        SaslAuthenticateRequestData data = new SaslAuthenticateRequestData().setAuthBytes(b);
        AbstractRequest request = new SaslAuthenticateRequest(data, version);
        ByteBuffer serializedBytes = request.serialize();

        // corrupt the length of the bytes array
        serializedBytes.putInt(0, Integer.MAX_VALUE);

        String msg = assertThrows(RuntimeException.class, () -> AbstractRequest.
                parseRequest(request.apiKey(), request.version(), serializedBytes)).getMessage();
        assertEquals("Error reading byte array of 2147483647 byte(s): only 20 byte(s) available", msg);
    }
Check that all error codes in the response get included in {@link AbstractResponse#errorCounts()}.
clients/src/test/java/org/apache/kafka/common/requests/RequestResponseTest.java