MovieMeterPlugin extends ImdbPlugin { public String getMovieId(Movie movie) { String id = movie.getId(MOVIEMETER_PLUGIN_ID); if (isValidString(id) && StringUtils.isNumeric(id)) { return id; } id = movie.getId(IMDB_PLUGIN_ID); if (isValidString(id)) { try { FilmInfo mm = api.getFilm(id); id = Integer.toString(mm.getId()); movie.setId(MOVIEMETER_PLUGIN_ID, mm.getId()); return id; } catch (MovieMeterException ex) { LOG.warn("Failed to get MovieMeter ID for {}: {}", movie.getBaseName(), ex.getMessage(), ex); } } if (isNotValidString(id)) { id = getMovieId(movie.getTitle(), movie.getYear()); if (isNotValidString(id)) { id = getMovieId(movie.getOriginalTitle(), movie.getYear()); } } return id; } MovieMeterPlugin(); @Override String getPluginID(); @Override boolean scan(Movie movie); String getMovieId(Movie movie); String getMovieId(final String title, final String year); @Override boolean scanNFO(String nfo, Movie movie); static final String MOVIEMETER_PLUGIN_ID; }
@Test public void testGetMovieId_Movie() { LOG.info("getMovieId - Movie"); Movie movie; String result; for (TestData td : TEST_DATA) { movie = new Movie(); movie.setTitle(td.title, "TEST"); movie.setYear(td.year, "TEST"); result = plugin.getMovieId(movie); assertEquals("Failed to get the correct ID for " + td.title, td.id, result); } }
@Test public void testGetMovieId_String_String() { LOG.info("getMovieId - Title & Year"); for (TestData td : TEST_DATA) { LOG.info("Testing {} ({}), expecting {}", td.title, td.year, td.id); String result = plugin.getMovieId(td.title, td.year); assertEquals("Failed to get the correct ID for " + td.title, td.id, result); } }