@Test
public void testDecodeOverlappingTimecodes() throws IOException {

  SsaDecoder decoder = new SsaDecoder();
  byte[] bytes =
      TestUtil.getByteArray(ApplicationProvider.getApplicationContext(), OVERLAPPING_TIMECODES);
  Subtitle subtitle = decoder.decode(bytes, bytes.length, false);
  assertThat(subtitle.getEventTime(0)).isEqualTo(1_000_000);
  assertThat(subtitle.getEventTime(1)).isEqualTo(2_000_000);
  assertThat(subtitle.getEventTime(2)).isEqualTo(4_230_000);
  assertThat(subtitle.getEventTime(3)).isEqualTo(5_230_000);
  assertThat(subtitle.getEventTime(4)).isEqualTo(6_000_000);
  assertThat(subtitle.getEventTime(5)).isEqualTo(8_440_000);
  assertThat(subtitle.getEventTime(6)).isEqualTo(9_440_000);
  assertThat(subtitle.getEventTime(7)).isEqualTo(10_720_000);
  assertThat(subtitle.getEventTime(8)).isEqualTo(13_220_000);
  assertThat(subtitle.getEventTime(9)).isEqualTo(14_220_000);
  assertThat(subtitle.getEventTime(10)).isEqualTo(15_650_000);
  String firstSubtitleText = "First subtitle - end overlaps second";
  String secondSubtitleText = "Second subtitle - beginning overlaps first";
  String thirdSubtitleText = "Third subtitle - out of order";
  String fourthSubtitleText = "Fourth subtitle - same timings as fifth";
  String fifthSubtitleText = "Fifth subtitle - same timings as fourth";
  String sixthSubtitleText = "Sixth subtitle - fully encompasses seventh";
  String seventhSubtitleText = "Seventh subtitle - nested fully inside sixth";
  assertThat(Iterables.transform(subtitle.getCues(1_000_010), cue -> cue.text.toString()))
      .containsExactly(firstSubtitleText);
  assertThat(Iterables.transform(subtitle.getCues(2_000_010), cue -> cue.text.toString()))
      .containsExactly(firstSubtitleText, secondSubtitleText);
  assertThat(Iterables.transform(subtitle.getCues(4_230_010), cue -> cue.text.toString()))
      .containsExactly(secondSubtitleText);
  assertThat(Iterables.transform(subtitle.getCues(5_230_010), cue -> cue.text.toString()))
      .isEmpty();
  assertThat(Iterables.transform(subtitle.getCues(6_000_010), cue -> cue.text.toString()))
      .containsExactly(thirdSubtitleText);
  assertThat(Iterables.transform(subtitle.getCues(8_440_010), cue -> cue.text.toString()))
      .containsExactly(fourthSubtitleText, fifthSubtitleText);
  assertThat(Iterables.transform(subtitle.getCues(9_440_010), cue -> cue.text.toString()))
      .isEmpty();
  assertThat(Iterables.transform(subtitle.getCues(10_720_010), cue -> cue.text.toString()))
      .containsExactly(sixthSubtitleText);
  assertThat(Iterables.transform(subtitle.getCues(13_220_010), cue -> cue.text.toString()))
      .containsExactly(sixthSubtitleText, seventhSubtitleText);
  assertThat(Iterables.transform(subtitle.getCues(14_220_010), cue -> cue.text.toString()))
      .containsExactly(sixthSubtitleText);
  assertThat(Iterables.transform(subtitle.getCues(15_650_010), cue -> cue.text.toString()))
      .isEmpty();
}