/**
   * 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);
  }
 /**
  * Test with an empty directory.
  *
  * @throws IOException if there was an I/O error.
  */
 @Test
 public void testEmptyDirectory() throws IOException {
   assertTrue(subtitleProvider.loadSubtitles(subtitleFolder.newFolder().toPath()).isEmpty());
   verify(userPrompt).warning(TRANSLATION_KEY.noSubtitleToCorrect());
 }
 /** Test that no subtitles are loaded when the path does not exists. */
 @Test
 public void testLoadNonExistingPath() {
   final Path path = Paths.get("abcdefghijkl", "mnopqrstuvwxyz");
   assertTrue(subtitleProvider.loadSubtitles(path).isEmpty());
   verify(userPrompt).error(TRANSLATION_KEY.noAccess(), path);
 }