/**
   * Test method for {@link SubtitleProvider#loadSubtitles(Path)}. Check that multiple subtitles are
   * loaded.
   *
   * @throws IOException if there was an I/O error.
   */
  @Test
  public void testLoadSubtitles() throws IOException {
    final SubtitleFormat subtitleFormat = mock(SubtitleFormat.class);
    final SubtitleReader subtitleReader = mock(SubtitleReader.class);
    final SubtitleFile subtitleFile = mock(SubtitleFile.class);
    final SubtitleFile secondSubtitle = mock(SubtitleFile.class);
    final Path folder = subtitleFolder.newFolder().toPath();
    final Path file = folder.resolve("single.srt");
    final Path second = folder.resolve("other.srt");
    Files.createFile(file);
    Files.createFile(second);
    Files.createFile(folder.resolve("test.sub"));

    when(subtitleFormatManager.getFormatByPath(file))
        .thenReturn(new HashSet<>(Arrays.asList(subtitleFormat)));
    when(subtitleFormatManager.getFormatByPath(second))
        .thenReturn(new HashSet<>(Arrays.asList(subtitleFormat)));
    when(subtitleFormat.getReader()).thenReturn(subtitleReader);
    when(subtitleReader.readFile(file)).thenReturn(subtitleFile);
    when(subtitleReader.readFile(second)).thenReturn(secondSubtitle);
    final Map<SubtitleFile, SubtitleFormat> subtitles = subtitleProvider.loadSubtitles(folder);
    assertEquals(2, subtitles.size());
    //		final Entry<SubtitleFile, SubtitleFormat> loaded = subtitles.entrySet().iterator().next();
    //		assertEquals(subtitleFile, loaded.getKey());
    //		assertEquals(subtitleFormat, loaded.getValue());
  }
  /**
   * Test with a subtitle with multiple format to read.
   *
   * @throws IOException if there was an I/O error.
   */
  @Test
  public void testMultipleFormatSubtitle() throws IOException {
    final SubtitleFormat subtitleFormat = mock(SubtitleFormat.class);
    final SubtitleReader subtitleReader = mock(SubtitleReader.class);
    final SubtitleFile subtitleFile = mock(SubtitleFile.class);
    final Path file = subtitleFolder.newFile("single.srt").toPath();

    when(subtitleFormatManager.getFormatByPath(file))
        .thenReturn(new HashSet<>(Arrays.asList(subtitleFormat, mock(SubtitleFormat.class))));
    when(userPrompt.askChoice(
            anyCollectionOf(SubtitleFormat.class),
            eq(TRANSLATION_KEY.chooseSubtitleFormat()),
            eq(file)))
        .thenReturn(subtitleFormat);
    when(subtitleFormat.getReader()).thenReturn(subtitleReader);
    when(subtitleReader.readFile(file)).thenReturn(subtitleFile);
    final Map<SubtitleFile, SubtitleFormat> subtitles = subtitleProvider.loadSubtitles(file);
    assertEquals(1, subtitles.size());
    final Entry<SubtitleFile, SubtitleFormat> loaded = subtitles.entrySet().iterator().next();
    assertEquals(subtitleFile, loaded.getKey());
    assertEquals(subtitleFormat, loaded.getValue());
    verify(userPrompt)
        .askChoice(
            anyCollectionOf(SubtitleFormat.class),
            eq(TRANSLATION_KEY.chooseSubtitleFormat()),
            eq(file));
  }
 /**
  * Test with a subtitle which has no proper format to read.
  *
  * @throws IOException if there was an I/O error.
  */
 @Test
 public void testSingleSubtitleWithBadFormat() throws IOException {
   final Path file = subtitleFolder.newFile("single.srt").toPath();
   when(subtitleFormatManager.getFormatByPath(file)).thenReturn(new HashSet<SubtitleFormat>());
   final Map<SubtitleFile, SubtitleFormat> subtitles = subtitleProvider.loadSubtitles(file);
   assertTrue(subtitles.isEmpty());
   verify(userPrompt)
       .askChoice(
           anyCollectionOf(SubtitleFormat.class),
           eq(TRANSLATION_KEY.chooseSubtitleFormat()),
           eq(file));
 }
  /**
   * Test when a {@link SubtitleReader} throws an exception.
   *
   * @throws IOException if there is an I/O error.
   */
  @Test
  public void testLoadSubtitleReaderError() throws IOException {
    final SubtitleFormat subtitleFormat = mock(SubtitleFormat.class);
    final SubtitleReader subtitleReader = mock(SubtitleReader.class);
    final Path file = subtitleFolder.newFile("readexception.srt").toPath();

    when(subtitleFormatManager.getFormatByPath(file))
        .thenReturn(new HashSet<>(Arrays.asList(subtitleFormat)));
    when(subtitleFormat.getReader()).thenReturn(subtitleReader);
    when(subtitleReader.readFile(file)).thenThrow(IOException.class);
    final Map<SubtitleFile, SubtitleFormat> subtitles = subtitleProvider.loadSubtitles(file);
    assertTrue(subtitles.isEmpty());
    verify(userPrompt).warning(TRANSLATION_KEY.subtitleFileReadError(), file);
  }