/** * 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)); }