title: Spring. JUnit5. WebClient. How to test async calls
body: <p>I have a Spring boot project with a service, which basically calls a private method, which does:</p>
  
  <pre><code>webClient.post().uri().accept(...).body(...).exchange()
  </code></pre>
  
  <p>and then puts a <code>subscribe(...)</code> on it, which simply logs the result.</p>
  
  <p>Everything works fine, but now I need to test this, and this is where things start to get interesting. </p>
  
  <p>By far, I've tried MockServer, okhttp, Spring's WebMockServer(or something), and only MockServer was willing to work at some point properly, while okhttp latest wants junit.rules.* (which is problematic to 
  achieve), WebMockServer specifically wants RestTemplate.</p>
  
  <p>Google does give out examples, in which a webClient logic method is left without a <code>.exchange()</code> call, giving a chance to call <code>.block()</code> in the test, but I'm not willing to expose a private method just in order to workaround the async calls.</p>
  
  <p>Currently I'm struggling with DEEP_STUB strategy of Mockito to mock out the actual webClient chain, but this fails to work from the box, and I'm trying to make it work while writing this question.</p>
  
  <p>So the question is - is there a proper way to test a webClient with an async call (maybe a MockServer with a timeout to the verification or something)?</p>