@Test
public void testSelectTracksPreferTrackWithinCapabilitiesOverSelectionFlag()
    throws Exception {

  Format exceededWithSelectionFlagFormat =
      Format.createAudioSampleFormat(
          "exceededFormat",
          MimeTypes.AUDIO_AAC,
          null,
          Format.NO_VALUE,
          Format.NO_VALUE,
          2,
          44100,
          null,
          null,
          C.SELECTION_FLAG_DEFAULT,
          null);
  Format supportedFormat =
      Format.createAudioSampleFormat("supportedFormat", MimeTypes.AUDIO_AAC, null,
          Format.NO_VALUE, Format.NO_VALUE, 2, 44100, null, null, 0, null);
  TrackGroupArray trackGroups = wrapFormats(exceededWithSelectionFlagFormat, supportedFormat);
  Map<String, Integer> mappedCapabilities = new HashMap<>();
  mappedCapabilities.put(supportedFormat.id, FORMAT_HANDLED);
  mappedCapabilities.put(exceededWithSelectionFlagFormat.id, FORMAT_EXCEEDS_CAPABILITIES);
  RendererCapabilities mappedAudioRendererCapabilities =
      new FakeMappedRendererCapabilities(C.TRACK_TYPE_AUDIO, mappedCapabilities);
  TrackSelectorResult result =
      trackSelector.selectTracks(
          new RendererCapabilities[] {mappedAudioRendererCapabilities},
          trackGroups,
          periodId,
          TIMELINE);
  assertFixedSelection(result.selections.get(0), trackGroups, supportedFormat);
}