@Test public void testArtistFetching2NoImagesFails() throws IOException { ArtInfo artInfo = ArtInfo.forArtist("pretty lights feat. talib kweli", null); when(mPreferences.getBoolean(ArtworkPreferences.ONLY_ON_WIFI, true)).thenReturn(false); NetworkInfo networkInfo = mock(NetworkInfo.class); when(networkInfo.isConnectedOrConnecting()).thenReturn(true); when(mConnectivityManager.getActiveNetworkInfo()).thenReturn(networkInfo); when(mL2Cache.containsKey(artInfo.cacheKey())).thenReturn(false); when(mPreferences.getBoolean(ArtworkPreferences.DOWNLOAD_MISSING_ARTIST_IMAGES, true)).thenReturn(true); mServer.enqueue(new MockResponse().setBody(IOUtils.toString(getClass().getClassLoader() .getResourceAsStream("lfm_artist_pretty_lights_feat_talib_kweli.xml")))); mFetcher.fetch(artInfo, mListener); verify(mListener, never()).onNext(Matchers.<Bitmap>any()); verify(mListener, never()).onCompleted(); verify(mListener).onError(Matchers.<Throwable>any()); assertThat(mFetcher.originalUri).isNullOrEmpty(); verifyZeroInteractions(mContext); }
public Subscription fetch(ArtInfo artInfo, CompletionListener l) { if (artInfo.forArtist) { if (StringUtils.isEmpty(artInfo.artistName)) { return Observable.<Bitmap>error(new Exception("Invalid artInfo: " + "must have artistName set")).subscribe(l); } else { return fetchArtistImage(artInfo).observeOn(mObserveOn).subscribe(l); } } else { if ((StringUtils.isEmpty(artInfo.artistName) && StringUtils.isEmpty(artInfo.albumName)) && (Uri.EMPTY.equals(artInfo.artworkUri))) { return Observable.<Bitmap>error(new Exception("Invalid artInfo: must have artistName " + "and albumName set or valid artworkUri")).subscribe(l); } else { return fetchAlbumCover(artInfo).observeOn(mObserveOn).subscribe(l); } } }
ArtworkFetcherManager { public Subscription fetch(ArtInfo artInfo, CompletionListener l) { if (artInfo.forArtist) { if (StringUtils.isEmpty(artInfo.artistName)) { return Observable.<Bitmap>error(new Exception("Invalid artInfo: " + "must have artistName set")).subscribe(l); } else { return fetchArtistImage(artInfo).observeOn(mObserveOn).subscribe(l); } } else { if ((StringUtils.isEmpty(artInfo.artistName) && StringUtils.isEmpty(artInfo.albumName)) && (Uri.EMPTY.equals(artInfo.artworkUri))) { return Observable.<Bitmap>error(new Exception("Invalid artInfo: must have artistName " + "and albumName set or valid artworkUri")).subscribe(l); } else { return fetchAlbumCover(artInfo).observeOn(mObserveOn).subscribe(l); } } } }
ArtworkFetcherManager { public Subscription fetch(ArtInfo artInfo, CompletionListener l) { if (artInfo.forArtist) { if (StringUtils.isEmpty(artInfo.artistName)) { return Observable.<Bitmap>error(new Exception("Invalid artInfo: " + "must have artistName set")).subscribe(l); } else { return fetchArtistImage(artInfo).observeOn(mObserveOn).subscribe(l); } } else { if ((StringUtils.isEmpty(artInfo.artistName) && StringUtils.isEmpty(artInfo.albumName)) && (Uri.EMPTY.equals(artInfo.artworkUri))) { return Observable.<Bitmap>error(new Exception("Invalid artInfo: must have artistName " + "and albumName set or valid artworkUri")).subscribe(l); } else { return fetchAlbumCover(artInfo).observeOn(mObserveOn).subscribe(l); } } } @Inject  ArtworkFetcherManager(
            @ForApplication Context mContext,
            ArtworkPreferences mPreferences,
            BitmapDiskCache mL2Cache,
            ConnectivityManager mConnectivityManager,
            @Named("ObserveOnScheduler") Scheduler mObserveOn,
            @Named("SubscribeOnScheduler") Scheduler mSubscribeOn,
            LastFM mLastFM,
            CoverArtArchive mCoverArtArchive,
            OkHttpClient mOkHttpClient
    ); }
ArtworkFetcherManager { public Subscription fetch(ArtInfo artInfo, CompletionListener l) { if (artInfo.forArtist) { if (StringUtils.isEmpty(artInfo.artistName)) { return Observable.<Bitmap>error(new Exception("Invalid artInfo: " + "must have artistName set")).subscribe(l); } else { return fetchArtistImage(artInfo).observeOn(mObserveOn).subscribe(l); } } else { if ((StringUtils.isEmpty(artInfo.artistName) && StringUtils.isEmpty(artInfo.albumName)) && (Uri.EMPTY.equals(artInfo.artworkUri))) { return Observable.<Bitmap>error(new Exception("Invalid artInfo: must have artistName " + "and albumName set or valid artworkUri")).subscribe(l); } else { return fetchAlbumCover(artInfo).observeOn(mObserveOn).subscribe(l); } } } @Inject  ArtworkFetcherManager(
            @ForApplication Context mContext,
            ArtworkPreferences mPreferences,
            BitmapDiskCache mL2Cache,
            ConnectivityManager mConnectivityManager,
            @Named("ObserveOnScheduler") Scheduler mObserveOn,
            @Named("SubscribeOnScheduler") Scheduler mSubscribeOn,
            LastFM mLastFM,
            CoverArtArchive mCoverArtArchive,
            OkHttpClient mOkHttpClient
    ); Subscription fetch(ArtInfo artInfo, CompletionListener l); void clearCaches(); void onDestroy(); static boolean isLocalArtwork(Uri u); }
ArtworkFetcherManager { public Subscription fetch(ArtInfo artInfo, CompletionListener l) { if (artInfo.forArtist) { if (StringUtils.isEmpty(artInfo.artistName)) { return Observable.<Bitmap>error(new Exception("Invalid artInfo: " + "must have artistName set")).subscribe(l); } else { return fetchArtistImage(artInfo).observeOn(mObserveOn).subscribe(l); } } else { if ((StringUtils.isEmpty(artInfo.artistName) && StringUtils.isEmpty(artInfo.albumName)) && (Uri.EMPTY.equals(artInfo.artworkUri))) { return Observable.<Bitmap>error(new Exception("Invalid artInfo: must have artistName " + "and albumName set or valid artworkUri")).subscribe(l); } else { return fetchAlbumCover(artInfo).observeOn(mObserveOn).subscribe(l); } } } @Inject  ArtworkFetcherManager(
            @ForApplication Context mContext,
            ArtworkPreferences mPreferences,
            BitmapDiskCache mL2Cache,
            ConnectivityManager mConnectivityManager,
            @Named("ObserveOnScheduler") Scheduler mObserveOn,
            @Named("SubscribeOnScheduler") Scheduler mSubscribeOn,
            LastFM mLastFM,
            CoverArtArchive mCoverArtArchive,
            OkHttpClient mOkHttpClient
    ); Subscription fetch(ArtInfo artInfo, CompletionListener l); void clearCaches(); void onDestroy(); static boolean isLocalArtwork(Uri u);  }