PodcastDirectoryHelper { public static String getITunesId(Uri uri) { if (uri == null) { throw new IllegalArgumentException("uri is null"); } String id = ""; List<String> segments = uri.getPathSegments(); for (int i = 0; segments != null && i < segments.size(); i++) { if (segments.get(i).startsWith("id")) { id = segments.get(i).replace("id", ""); break; } } return id; }  static Channel getChannelFromITunesJson(String jsonStr); static String getDirectoryUrl(int directoryType, String directoryId); static boolean containsITunesHost(Uri uri); static String getITunesId(Uri uri); static final int DIRECTORY_TYPE_ITUNES; }
@Test public void getITunesIdTest() { Uri uri = Mockito.mock(Uri.class); when(uri.getPathSegments()).thenReturn( Arrays.asList("us", "podcast", "the-vergecast", "id430333725")); String id = PodcastDirectoryHelper.getITunesId(uri); Assert.assertEquals("430333725", id); }
@Test(expected = IllegalArgumentException.class) public void nullUriTest() { PodcastDirectoryHelper.getITunesId(null); }
@Test public void nullPathSegments() { Uri uri = Mockito.mock(Uri.class); when(uri.getPathSegments()).thenReturn(null); String id = PodcastDirectoryHelper.getITunesId(uri); Assert.assertEquals("", id); }
@Test public void noITunesIdTest() { Uri uri = Mockito.mock(Uri.class); when(uri.getPathSegments()).thenReturn( Arrays.asList("us", "podcast", "the-vergecast", "430333725")); String id = PodcastDirectoryHelper.getITunesId(uri); Assert.assertEquals("", id); }
@Test public void noPathSegments() { Uri uri = Mockito.mock(Uri.class); when(uri.getPathSegments()).thenReturn(Collections.singletonList("")); String id = PodcastDirectoryHelper.getITunesId(uri); Assert.assertEquals("", id); }