@Test public void shouldCallTvMaze() throws Exception { ArgumentCaptor<TvInfo> tvInfoArgumentCaptor = ArgumentCaptor.forClass(TvInfo.class); for (MediaIdType type : Arrays.asList(MediaIdType.TVMAZE, MediaIdType.TVDB, MediaIdType.TVRAGE, MediaIdType.TVTITLE, MediaIdType.TVIMDB)) { reset(tvMazeHandlerMock); when(tvMazeHandlerMock.getInfos(anyString(), any(MediaIdType.class))).thenReturn(new TvMazeSearchResult("tvmazeId", "tvrageId", "tvdbId", "imdbId", "title", 0, "posterUrl")); testee.convert("value", type); verify(tvMazeHandlerMock).getInfos("value", type); } verify(tvInfoRepositoryMock).findByTvdbId("value"); verify(tvInfoRepositoryMock).findByTvrageId("value"); verify(tvInfoRepositoryMock).findByTvmazeId("value"); verify(tvInfoRepositoryMock).findByImdbId("ttvalue"); verify(tvInfoRepositoryMock, times(5)).save(tvInfoArgumentCaptor.capture()); assertEquals(5, tvInfoArgumentCaptor.getAllValues().size()); assertEquals("title", tvInfoArgumentCaptor.getValue().getTitle()); assertEquals("tvdbId", tvInfoArgumentCaptor.getValue().getTvdbId().get()); assertEquals("tvmazeId", tvInfoArgumentCaptor.getValue().getTvmazeId().get()); assertEquals("tvrageId", tvInfoArgumentCaptor.getValue().getTvrageId().get()); assertEquals("ttimdbId", tvInfoArgumentCaptor.getValue().getImdbId().get()); assertEquals(Integer.valueOf(0), tvInfoArgumentCaptor.getValue().getYear()); }
public MediaInfo convert(Map<MediaIdType, String> identifiers) throws InfoProviderException { for (MediaIdType idType : REAL_ID_TYPES) { if (identifiers.containsKey(idType) && identifiers.get(idType) != null) { return convert(identifiers.get(idType), idType); } } throw new InfoProviderException("Unable to find any convertable IDs"); }
InfoProvider { public MediaInfo convert(Map<MediaIdType, String> identifiers) throws InfoProviderException { for (MediaIdType idType : REAL_ID_TYPES) { if (identifiers.containsKey(idType) && identifiers.get(idType) != null) { return convert(identifiers.get(idType), idType); } } throw new InfoProviderException("Unable to find any convertable IDs"); } }
InfoProvider { public MediaInfo convert(Map<MediaIdType, String> identifiers) throws InfoProviderException { for (MediaIdType idType : REAL_ID_TYPES) { if (identifiers.containsKey(idType) && identifiers.get(idType) != null) { return convert(identifiers.get(idType), idType); } } throw new InfoProviderException("Unable to find any convertable IDs"); }  }
InfoProvider { public MediaInfo convert(Map<MediaIdType, String> identifiers) throws InfoProviderException { for (MediaIdType idType : REAL_ID_TYPES) { if (identifiers.containsKey(idType) && identifiers.get(idType) != null) { return convert(identifiers.get(idType), idType); } } throw new InfoProviderException("Unable to find any convertable IDs"); }  boolean canConvert(MediaIdType from, MediaIdType to); static Set<MediaIdType> getConvertibleFrom(MediaIdType from); boolean canConvertAny(Set<MediaIdType> from, Set<MediaIdType> to); MediaInfo convert(Map<MediaIdType, String> identifiers); @Cacheable(cacheNames = "infos", sync = true) //sync=true is currently apparently not supported by Caffeine. synchronizing by method is good enough because we'll likely rarely hit this method concurrently with different parameters synchronized MediaInfo convert(String value, MediaIdType fromType); TvInfo findTvInfoInDatabase(Map<MediaIdType, String> ids); MovieInfo findMovieInfoInDatabase(Map<MediaIdType, String> ids); @Cacheable(cacheNames = "titles", sync = true) List<MediaInfo> search(String title, MediaIdType titleType); }
InfoProvider { public MediaInfo convert(Map<MediaIdType, String> identifiers) throws InfoProviderException { for (MediaIdType idType : REAL_ID_TYPES) { if (identifiers.containsKey(idType) && identifiers.get(idType) != null) { return convert(identifiers.get(idType), idType); } } throw new InfoProviderException("Unable to find any convertable IDs"); }  boolean canConvert(MediaIdType from, MediaIdType to); static Set<MediaIdType> getConvertibleFrom(MediaIdType from); boolean canConvertAny(Set<MediaIdType> from, Set<MediaIdType> to); MediaInfo convert(Map<MediaIdType, String> identifiers); @Cacheable(cacheNames = "infos", sync = true) //sync=true is currently apparently not supported by Caffeine. synchronizing by method is good enough because we'll likely rarely hit this method concurrently with different parameters synchronized MediaInfo convert(String value, MediaIdType fromType); TvInfo findTvInfoInDatabase(Map<MediaIdType, String> ids); MovieInfo findMovieInfoInDatabase(Map<MediaIdType, String> ids); @Cacheable(cacheNames = "titles", sync = true) List<MediaInfo> search(String title, MediaIdType titleType); static Set<MediaIdType> TV_ID_TYPES; static Set<MediaIdType> MOVIE_ID_TYPES; static Set<MediaIdType> REAL_ID_TYPES; }