PlaylistProvider { public Song buildSong(Track track) { if (TextUtils.isEmpty(track.uri)) { return null; } Song song = new Song(); song.setId(track.uri); song.setTitle(track.name); song.setAlbum(track.album.name); List<Image> images = track.album.images; if (images.size() > 0) { song.setBackgroundImageUrl(images.get(0).url); song.setCardImageUrl(images.get(0).url); } List<ArtistSimple> artists = track.artists; if (artists.size() > 0) { song.setArtist(artists.get(0).name); song.setType(artists.get(0).type); } return song; }  static void setContext(Context context); static Context getContext(); static HashMap<String, List<Song>> getPlaylistList(); static HashMap<String, List<Song>> buildMedia(Context context, OnPlaylistLoaded callback); Song buildSong(Track track);  }
@Test public void test_buildSong() { Track track = new Track(); track.uri = "123"; track.name = "test track"; AlbumSimple album = new AlbumSimple(); album.name = "test album"; track.album = album; List<Image> images = new ArrayList<Image>(); Image image = new Image(); image.url = "www.google.com"; images.add(image); album.images = images; List<ArtistSimple> artists = new ArrayList<ArtistSimple>(); ArtistSimple artist = new ArtistSimple(); artist.name = "test artist"; artist.type = "test type"; artists.add(artist); track.artists = artists; Song song = provider.buildSong(track); assertEquals("123", song.getId()); assertEquals("test track", song.getTitle()); assertEquals("test album", song.getAlbum()); assertEquals("www.google.com", song.getBackgroundImageUrl()); assertEquals("www.google.com", song.getCardImageUrl()); assertEquals("test artist", song.getArtist()); assertEquals("test type", song.getType()); }
@Test public void test_buildSong_blankUri() { Track track = new Track(); track.uri = ""; Song song = provider.buildSong(track); assertNull(song); }
@Test public void test_buildSong_nullUri() { Track track = new Track(); track.uri = null; Song song = provider.buildSong(track); assertNull(song); }