/** * Captures the last received metadata for a stub. Useful for testing * * @param stub to capture for * @param headersCapture to record the last received headers * @param trailersCapture to record the last received trailers * @return an implementation of the stub that allows to access the last received call's * headers and trailers via {@code headersCapture} and {@code trailersCapture}. */ @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1789") public static <T extends AbstractStub<T>> T captureMetadata( T stub, AtomicReference<Metadata> headersCapture, AtomicReference<Metadata> trailersCapture) { return stub.withInterceptors( newCaptureMetadataInterceptor(headersCapture, trailersCapture)); }