@SuppressWarnings("unchecked")
    public void doFunctionDelegationCheck() {
        if (mockConfigurationFunction == null || wrapperFunctionApplier == null ||
            mockFunctionReturnValueTransformation == null ||
            mockConsumer != null || wrapperConsumer != null) {
            throwExceptionForIllegalTestSetup();
        }
        // configure the mock to behave as desired
        when(mockConfigurationFunction.apply(mock)).thenAnswer(invocation -> {
            persistentCollectionMethodInvokedCorrectly = true;
            return mockFunctionReturnValue;
        });
        // invoke the wrapper, which should invoke the mock as desired
        T wrapperReturnValue = wrapperFunctionApplier.apply(wrapper);
        // assert that the expected delegation to the mock actually occurred, including any return value transformation
        assertTrue(persistentCollectionMethodInvokedCorrectly);
        Object transformedMockFunctionReturnValue = mockFunctionReturnValueTransformation.apply(mockFunctionReturnValue);
        if (this.expectWrapperToWrapMockFunctionReturnValue) {
            assertEquals(transformedMockFunctionReturnValue, unwrap((W) wrapperReturnValue));
        } else {
            assertEquals(transformedMockFunctionReturnValue, wrapperReturnValue);
        }
    }
@param wrapper the wrapper
@return the underlying delegate for the given wrapper
server-common/src/test/java/org/apache/kafka/server/immutable/DelegationChecker.java