@SuppressWarnings("unchecked") private <T, Z> void registerFailFactory(Class<T> failModel, Class<Z> failResource) throws Exception { DataFetcher<Z> failFetcher = mock(DataFetcher.class); doAnswer(new Util.CallDataReady<>(null)) .when(failFetcher) .loadData(isA(Priority.class), isA(DataFetcher.DataCallback.class)); when(failFetcher.getDataClass()).thenReturn(failResource); ModelLoader<T, Z> failLoader = mock(ModelLoader.class); when(failLoader.buildLoadData(isA(failModel), anyInt(), anyInt(), isA(Options.class))) .thenReturn(new ModelLoader.LoadData<>(mock(Key.class), failFetcher)); when(failLoader.handles(isA(failModel))).thenReturn(true); ModelLoaderFactory<T, Z> failFactory = mock(ModelLoaderFactory.class); when(failFactory.build(isA(MultiModelLoaderFactory.class))).thenReturn(failLoader); Glide.get(getContext()).getRegistry().prepend(failModel, failResource, failFactory); }
private static <X, Y> void registerMockModelLoader(Class<X> modelClass, Class<Y> dataClass, Y loadedData, Registry registry) { DataFetcher<Y> mockStreamFetcher = mock(DataFetcher.class); when(mockStreamFetcher.getDataClass()).thenReturn(dataClass); try { doAnswer(new Util.CallDataReady<>(loadedData)) .when(mockStreamFetcher) .loadData(isA(Priority.class), isA(DataFetcher.DataCallback.class)); } catch (Exception e) { throw new RuntimeException(e); } ModelLoader<X, Y> mockUrlLoader = mock(ModelLoader.class); when(mockUrlLoader.buildLoadData(isA(modelClass), anyInt(), anyInt(), isA(Options.class))) .thenReturn(new ModelLoader.LoadData<>(mock(Key.class), mockStreamFetcher)); when(mockUrlLoader.handles(isA(modelClass))).thenReturn(true); ModelLoaderFactory<X, Y> mockUrlLoaderFactory = mock(ModelLoaderFactory.class); when(mockUrlLoaderFactory.build(isA(MultiModelLoaderFactory.class))) .thenReturn(mockUrlLoader); registry.replace(modelClass, dataClass, mockUrlLoaderFactory); }
@SuppressWarnings("unchecked") private <T, Z> void registerFailFactory(Class<T> failModel, Class<Z> failResource) { DataFetcher<Z> failFetcher = mock(DataFetcher.class); doAnswer(new Util.CallDataReady<>(null)) .when(failFetcher) .loadData(isA(Priority.class), isA(DataFetcher.DataCallback.class)); when(failFetcher.getDataClass()).thenReturn(failResource); ModelLoader<T, Z> failLoader = mock(ModelLoader.class); when(failLoader.buildLoadData(isA(failModel), anyInt(), anyInt(), isA(Options.class))) .thenReturn(new ModelLoader.LoadData<>(mock(Key.class), failFetcher)); when(failLoader.handles(isA(failModel))).thenReturn(true); ModelLoaderFactory<T, Z> failFactory = mock(ModelLoaderFactory.class); when(failFactory.build(isA(MultiModelLoaderFactory.class))).thenReturn(failLoader); Glide.get(context).getRegistry().prepend(failModel, failResource, failFactory); }
@SuppressWarnings("unchecked") private <T> void registerMockStreamModelLoader(final Class<T> modelClass) { ModelLoader<T, InputStream> modelLoader = mockStreamModelLoader(modelClass); ModelLoaderFactory<T, InputStream> modelLoaderFactory = mock(ModelLoaderFactory.class); when(modelLoaderFactory.build(isA(MultiModelLoaderFactory.class))).thenReturn(modelLoader); Glide.get(RuntimeEnvironment.application).getRegistry() .prepend(modelClass, InputStream.class, modelLoaderFactory); }
@SuppressWarnings("unchecked") private <T> void registerMockStreamModelLoader(final Class<T> modelClass) { ModelLoader<T, InputStream> modelLoader = mockStreamModelLoader(modelClass); ModelLoaderFactory<T, InputStream> modelLoaderFactory = mock(ModelLoaderFactory.class); when(modelLoaderFactory.build(isA(MultiModelLoaderFactory.class))).thenReturn(modelLoader); Glide.get(context).getRegistry() .prepend(modelClass, InputStream.class, modelLoaderFactory); }
@Override public ModelLoader<GlideUrl, InputStream> build(MultiModelLoaderFactory multiFactory) { return new OkHttpUrlLoader(client); }
@Override public ModelLoader<GlideUrl, InputStream> build(MultiModelLoaderFactory factory) { return new VolleyUrlLoader(requestQueue, requestFactory); }
@Override public ModelLoader<Api.GifResult, InputStream> build(MultiModelLoaderFactory multiFactory) { return new GiphyModelLoader(multiFactory.build(GlideUrl.class, InputStream.class)); }
@Override public ModelLoader<Photo, InputStream> build(MultiModelLoaderFactory multiFactory) { return new FlickrModelLoader(multiFactory.build(GlideUrl.class, InputStream.class), modelCache); }
@Override public ModelLoader<Uri, InputStream> build(MultiModelLoaderFactory multiFactory) { return new HttpUriLoader(multiFactory.build(GlideUrl.class, InputStream.class)); }
@Override public ModelLoader<URL, InputStream> build(MultiModelLoaderFactory multiFactory) { return new UrlLoader(multiFactory.build(GlideUrl.class, InputStream.class)); }
@Override public ModelLoader<Uri, InputStream> build(MultiModelLoaderFactory multiFactory) { return new MediaStoreVideoThumbLoader(context); }
@Override public ModelLoader<GlideUrl, InputStream> build(MultiModelLoaderFactory multiFactory) { return new HttpGlideUrlLoader(modelCache); }
@Override public ModelLoader<Uri, InputStream> build(MultiModelLoaderFactory multiFactory) { return new MediaStoreImageThumbLoader(context); }
@SuppressWarnings("deprecation") @Override public ModelLoader<GlideUrl, InputStream> build(MultiModelLoaderFactory multiFactory) { return new OkHttpUrlLoader(client); }
@Override public ModelLoader<WaitModel<Model>, Data> build( MultiModelLoaderFactory multiFactory) { return new WaitModelLoader<>(multiFactory.build(modelClass, dataClass)); }
@Override public ModelLoader<Photo, InputStream> build(MultiModelLoaderFactory multiFactory) { return new FlickrModelLoader( multiFactory.build(GlideUrl.class, InputStream.class), modelCache); }
@Override public ModelLoader<String, InputStream> build(MultiModelLoaderFactory multiFactory) { return new ArtworkModeLoader(); }
@Override public ModelLoader<String, InputStream> build(MultiModelLoaderFactory multiFactory) { return new PixelsModelLoader(multiFactory.build(GlideUrl.class, InputStream.class), urlCache); }
@Override public ModelLoader<StorageReference, InputStream> build(MultiModelLoaderFactory factory) { return new FirebaseImageLoader(); }
@NonNull @Override public ModelLoader<AppModel, InputStream> build(@NonNull MultiModelLoaderFactory multiFactory) { return new AppIconLoader(context); }
@Override public ModelLoader<GlideUrl, InputStream> build(MultiModelLoaderFactory multiFactory) { return new AppHttpUrlLoader(mOkHttpClient); }