@Test
public void captureStageTransitionTest() throws Exception {

  myServices.enableCpuCaptureStage(false);
  myServices.enableEventsPipeline(true);
  // Needs to be set true else null is inserted into the capture parser.
  myServices.setShouldProceedYesNoDialog(true);
  // Try to parse a simpleperf trace with ART config.
  ProfilingConfiguration config = new ProfilingConfiguration("My Config",
                                                             Cpu.CpuTraceType.ART,
                                                             Cpu.CpuTraceMode.SAMPLED);
  CpuProfilerTestUtils.captureSuccessfully(myStage, myCpuService, myTransportService, CpuProfilerTestUtils.readValidTrace());
  myStage.getProfilerConfigModel().setProfilingConfiguration(config);
  assertThat(myStage.getStudioProfilers().getStage()).isEqualTo(myStage);
  myServices.enableCpuCaptureStage(true);
  myTimer.setCurrentTimeNs(1);  // Update the timer to generate a different trace id for the second trace.
  // Don't pass a capture to the test utils for now as we don't want to block on parsing.
  CpuProfilerTestUtils.captureSuccessfully(myStage, myCpuService, myTransportService, CpuProfilerTestUtils.readValidTrace());
  // Force a flush of the UI event queue.
  assertThat(myStage.getStudioProfilers().getStage().getClass()).isAssignableTo(CpuCaptureStage.class);
}