コード例 #1
0
  /**
   * 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());
  }
コード例 #2
0
  /**
   * 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));
  }
コード例 #3
0
 /**
  * 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));
 }
コード例 #4
0
  /**
   * 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);
  }
コード例 #5
0
 /**
  * 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());
 }
コード例 #6
0
 /** 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);
 }