title: How to junit test a method with Mono return type
body: <p>What is the proper way to junit mono and get a body response?
  I expected &quot;Single Item Only&quot; to be in the body response of MockHttpServletResponse. But instead I see it's returned in Async.</p>
  <p><strong>Sample Method:</strong></p>
  <pre><code>public Mono&lt;String&gt; getData(final String data) {
      return this.webClient.get().uri(&quot;/dataValue/&quot; + data)
          .retrieve()
          .bodyToMono(String.class);
  }
  </code></pre>
  <p><strong>Sample Junit:</strong></p>
  <pre><code>@WebMvcTest(DataController.class)
  public class DataMockTest {
  
    @Autowired
    private MockMvc mockMvc;
  
    @MockBean
    private Service service;
  
  @Test
  public void getDataTest() throws Exception {
  
  Mono&lt;String&gt; strMono = Mono.just(&quot;Single Item Only&quot;);
  
  when(service.getData(&quot;DATA&quot;)).thenReturn(strMono);
  
  this.mockMvc.perform(get(&quot;/some/rest/toget/data&quot;)
      .contentType(MediaType.APPLICATION_JSON)
      .accept(MediaType.APPLICATION_JSON))
      .andDo(print())
      .andExpect(status()
          .isOk());
  }
  </code></pre>
  <p><strong>Test Response:</strong></p>
  <pre><code>MockHttpServletRequest:
        HTTP Method = GET
        Request URI = /some/rest/toget/data
         Parameters = {}
            Headers = [Content-Type:&quot;application/json;charset=UTF-8&quot;, Accept:&quot;application/json&quot;]
               Body = null
      Session Attrs = {}
  
  Async:
      Async started = true
       Async result = Single Item Only
  
  Resolved Exception:
               Type = null
  
  ModelAndView:
          View name = null
               View = null
              Model = null
  
  FlashMap:
         Attributes = null
  
  MockHttpServletResponse:
             Status = 200
      Error message = null
            Headers = []
       Content type = null
               Body = 
      Forwarded URL = null
     Redirected URL = null
            Cookies = []
  </code></pre>
  <p><strong>Updated Junit with StepVerifier:</strong></p>
  <pre><code>@WebMvcTest(DataController.class)
  public class DataMockTest {
  
    @Autowired
    private MockMvc mockMvc;
  
    @MockBean
    private Service service;
  
  @Test
  public void getDataTest() throws Exception {
  
  Mono&lt;String&gt; strMono = Mono.just(&quot;Single Item Only&quot;);
  
  when(service.getData(&quot;DATA&quot;)).thenReturn(strMono);
  
  //Added this which verifies the mono method. How to mock it so the API would return the mono value?
  StepVerifier.create(service.getDATA(&quot;DATA&quot;))
      .assertNext(data -&gt; {
        assertNotNull(data);
        assertEquals(&quot;Single Item Only&quot;, data);
      }).verifyComplete();
  
  
  this.mockMvc.perform(get(&quot;/some/rest/toget/data&quot;)
      .contentType(MediaType.APPLICATION_JSON)
      .accept(MediaType.APPLICATION_JSON))
      .andDo(print())
      .andExpect(status()
          .isOk());
  }
  </code></pre>