非同期メソッドをテストする必要があるシナリオがあります。XMLベースの構成があり、以下のようになります
<task:annotation-driven executor="myExecutor"
        scheduler="myScheduler" />
    <task:executor id="myExecutor" pool-size="5" />
    <task:scheduler id="myScheduler" pool-size="10" />
以下のようにコントローラーの元の Async メソッド
@Async
    public Future<ResponseEntity<?>> 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<>(new ApiResponse<Boolean>(response, true), HttpStatus.OK));
        }
        return new AsyncResult(new ResponseEntity<>(new ApiResponse<Boolean>(false, true), HttpStatus.OK));
    }
そして、私のテストケースは以下のようになります。
@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));
    }}
このテストを実行すると、async が true と予想されるが false として開始されたため、例外が発生します。
この問題を解決するにはどうすればよいですか。私は何かが足りない..?