TvShowParser extends ContentParser<TvShow> { @Override public TvShow parse(String input) { Matcher matcher = mainPattern.matcher(input); if(matcher.matches()){ String name = getName(matcher.group(1)); Integer season = Integer.valueOf(matcher.group(2)); Integer episode = Integer.valueOf(matcher.group(3)); Quality qualityEnum = Quality.STANDARD; matcher = qualityPattern.matcher(input); if(matcher.find()){ String quality = matcher.group(); if(quality.equals(QUALITY_HD)) qualityEnum = Quality.HD; else if(quality.equals(QUALITY_FULLHD)) qualityEnum = Quality.FULLHD; } return new TvShow(name, season, episode, qualityEnum); } else { return null; } }  @Override TvShow parse(String input);  }
@Test public void shouldReturnTvShowWhenParseTypeOfInput1() throws MalformedURLException { String tvShowInput1 = "Game.of.Thrones.S03E08.720p.HDTV.x264.AC3-Riding High"; assertEquals(getExpectedTvShow(), tvShowParser.parse(getMatchItem(tvShowInput1))); }
@Test public void shouldReturnTvShowWhenParseTypeOfInput2() throws MalformedURLException { String tvShowInput2 = "Game.of.Thrones.S03E08.720p.HDTV.x264.AC3-Riding High"; assertEquals(getExpectedTvShow(), tvShowParser.parse(getMatchItem(tvShowInput2))); }
@Test public void shouldReturnTvShowWhenParseTypeOfInput3() throws MalformedURLException { String tvShowInput3 = "Game.of.Thrones.S03E08.720p.HDTV.x264.AC3-Riding High"; assertEquals(getExpectedTvShow(), tvShowParser.parse(getMatchItem(tvShowInput3))); }
@Test public void shouldReturnTvShowWhenParseInputWithoutDots() throws MalformedURLException { String tvShowInput4 = "Game of Thrones S03E08 720p HDTV x264 AC3-Riding High"; assertEquals(getExpectedTvShow(), tvShowParser.parse(getMatchItem(tvShowInput4))); }
@Test public void shouldBeSameTVShow() throws MalformedURLException { String tvShowInput2 = "Game.of.Thrones.S03E08.720p.HDTV.x264.AC3-Riding High"; TvShow tvShow2 = tvShowParser.parse(getMatchItem(tvShowInput2)); assertEquals(getExpectedTvShow(), tvShow2); String tvShowInput3 = "Game.of.Thrones.S03E08.720p.HDTV.x264.AC3-Riding High"; final TvShow tvShow3 = tvShowParser.parse(getMatchItem(tvShowInput3)); assertEquals(getExpectedTvShow(), tvShow3); String tvShowInput4 = "Game of Thrones S03E08 720p HDTV x264 AC3-Riding High"; final TvShow tvShow4 = tvShowParser.parse(getMatchItem(tvShowInput4)); assertEquals(getExpectedTvShow(), tvShow4); final HashSet<Content> tvShows = Sets.<Content>newHashSet(tvShow2, tvShow3, tvShow4); assertEquals(1, tvShows.size()); }