@Test
public void rangeIntersectionReturnsASingleTraceId() {

  int traceId1 = 1;
  int traceId2 = 2;
  addTraceInfoHelper(traceId1, FAKE_DEVICE_ID, FAKE_PROCESS.getPid(), TimeUnit.MICROSECONDS.toNanos(10),
                     TimeUnit.MICROSECONDS.toNanos(20), Cpu.CpuTraceConfiguration.getDefaultInstance());
  addTraceInfoHelper(traceId2, FAKE_DEVICE_ID, FAKE_PROCESS.getPid(), TimeUnit.MICROSECONDS.toNanos(30),
                     TimeUnit.MICROSECONDS.toNanos(40), Cpu.CpuTraceConfiguration.getDefaultInstance());
  // No intersection.
  CpuTraceInfo traceInfo = myStage.getIntersectingTraceInfo(new Range(0, 5));
  assertThat(traceInfo).isNull();
  // Intersecting only with trace 1.
  traceInfo = myStage.getIntersectingTraceInfo(new Range(5, 15));
  assertThat(traceInfo).isNotNull();
  assertThat(traceInfo.getTraceId()).isEqualTo(traceId1);
  // Intersecting only with trace 2.
  traceInfo = myStage.getIntersectingTraceInfo(new Range(25, 35));
  assertThat(traceInfo).isNotNull();
  assertThat(traceInfo.getTraceId()).isEqualTo(traceId2);
  // Intersecting with both traces. First trace is returned.
  traceInfo = myStage.getIntersectingTraceInfo(new Range(0, 50));
  assertThat(traceInfo).isNotNull();
  assertThat(traceInfo.getTraceId()).isEqualTo(traceId1);
}