title: Testing ASync method with JUnit in Spring MVC
body: <p>I have a scenario where i need to test async method.
  I have XML based configuration and is looks like below</p>
  
  <pre><code>&lt;task:annotation-driven executor="myExecutor"
          scheduler="myScheduler" /&gt;
      &lt;task:executor id="myExecutor" pool-size="5" /&gt;
      &lt;task:scheduler id="myScheduler" pool-size="10" /&gt;
  </code></pre>
  
  <p>Original Async method in controller as below</p>
  
  <pre><code>@Async
      public Future&lt;ResponseEntity&lt;?&gt;&gt; saveData(@RequestParam("file") MultipartFile file) {
          byte[] gzipContents = null;
          try {
              gzipContents = file.getBytes();
          } catch (IOException ioEx) {
          }
          if (gzipContents != null) {
              FileDTO fileDTO = new FileDTO(gzipContents);
              boolean response = storingService.processData(fileDTO);
              return new AsyncResult(new ResponseEntity&lt;&gt;(new ApiResponse&lt;Boolean&gt;(response, true), HttpStatus.OK));
          }
          return new AsyncResult(new ResponseEntity&lt;&gt;(new ApiResponse&lt;Boolean&gt;(false, true), HttpStatus.OK));
  
      }
  </code></pre>
  
  <p>And my test case looks as below.</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @Transactional
  public class TestSave extends BaseIntegrationTest {
  
          @Test
          public void testTrackingDataSave() throws Exception {
              // setup
              MvcResult mvcResult = this.mockMvc
                      .perform(MockMvcRequestBuilders.fileUpload(API_TESTER_SAVETRACKINGDATA)
                              .file("file", readFileBytesFromClasspath("testdata/output_sample1.txt"))
                              .header("certificate", testerCertificate))
                      .andExpect(request().asyncStarted()).andReturn();
  
              this.mockMvc.perform(asyncDispatch(mvcResult)).andExpect(status().isOk())
                      .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
                      .andExpect(status().is(200));
      }}
  </code></pre>
  
  <p>When u run this test i am getting exception as async started expected as true but false.</p>
  
  <p>How do need to proceed to fix this problem. Am i missing something..?</p>