private void loadNet() { Uri uri = Uri.parse("http://www.clker.com/cliparts/u/Z/2/b/a/6/android-toy-h.svg"); requestBuilder.load(uri).into(imageViewNet); } }
@Override public void runTest() { getNullModelRequest().into(imageView); } });
/** * Set the target the resource will be loaded into. * * @param target The target to load the resource into. * @return The given target. * @see RequestManager#clear(Target) */ @NonNull public <Y extends Target<TranscodeType>> Y into(@NonNull Y target) { return into(target, /*targetListener=*/ null, Executors.mainThreadExecutor()); }
@Test public void testByteData() { byte[] data = new byte[] { 1, 2, 3, 4, 5, 6 }; requestManager.load(data).into(target); }
@Test public void testLoadBitmap_asDrawable() { Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); requestManager .load(bitmap) .into(target); ArgumentCaptor<Object> captor = ArgumentCaptor.forClass(Object.class); verify(target).onResourceReady(captor.capture(), any(Transition.class)); BitmapDrawable drawable = (BitmapDrawable) captor.getValue(); assertThat(drawable.getBitmap()).isEqualTo(bitmap); }
@Test public void testLoadDrawable() { Drawable drawable = new ColorDrawable(Color.RED); requestManager .load(drawable) .into(target); ArgumentCaptor<Drawable> drawableCaptor = ArgumentCaptor.forClass(Drawable.class); verify(target).onResourceReady(drawableCaptor.capture(), any(Transition.class)); assertThat(((ColorDrawable) drawableCaptor.getValue()).getColor()).isEqualTo(Color.RED); }
@Test @SuppressWarnings("unchecked") public void testNonDefaultModelWithRegisteredFactoryDoesNotThrow() { registerMockStreamModelLoader(Float.class); requestManager.load(0.5f).into(target); }
@Test public void testGetNextFrameDoesStartLoadAfterLoadCompletesIfStarted() { loader.onFrameReady(mock(DelayTarget.class)); verify(requestBuilder, times(2)).into(aTarget()); }
@Test public void testStartDoesNotStartIfAlreadyRunning() { loader.subscribe(mock(FrameCallback.class)); verify(requestBuilder, times(1)).into(aTarget()); }
private void runTestFileDefaultLoader() { File file = new File("fake"); mockUri(Uri.fromFile(file)); requestManager.load(file).into(target); requestManager.load(file).into(imageView); verify(target).onResourceReady(isA(BitmapDrawable.class), isA(Transition.class)); verify(target).setRequest((Request) notNull()); assertNotNull(imageView.getDrawable()); }
@Test public void testNullModelPrefersErrorDrawable() { Drawable placeholder = new ColorDrawable(Color.GREEN); Drawable error = new ColorDrawable(Color.RED); requestManager .load(NULL) .apply(placeholderOf(placeholder) .error(error)) .into(target); verify(target).onLoadFailed(eq(error)); }
@Test public void testGetNextFrameIncrementsSignatureAndAdvancesDecoderBeforeStartingLoad() { InOrder order = inOrder(gifDecoder, requestBuilder); order.verify(gifDecoder).advance(); order.verify(requestBuilder).apply(isA(RequestOptions.class)); order.verify(requestBuilder).into(aTarget()); }
@Test public void testGetNextFrameDoesNotStartLoadIfLoadIsInProgress() { loader.unsubscribe(callback); loader.subscribe(callback); verify(requestBuilder, times(1)).into(aTarget()); }
@Test public void testGetNextFrameDoesStartLoadIfRestartedAndNoLoadIsInProgress() { loader.unsubscribe(callback); loader.onFrameReady(mock(DelayTarget.class)); loader.subscribe(callback); verify(requestBuilder, times(2)).into(aTarget()); }
@Test public void testReceivesThumbnails() { String full = mockUri("content://full"); String thumb = mockUri("content://thumb"); requestManager .load(full) .thumbnail(requestManager.load(thumb)) .into(target); verify(target, times(2)).onResourceReady(isA(Drawable.class), isA(Transition.class)); }
@Override protected void onAttachedToWindow() { super.onAttachedToWindow(); Glide.with(getContext()).asDrawable().load(android.R.drawable.ic_menu_rotate).into(this); } }
@Test public void testReceivesRecursiveThumbnailWithPercentage() { requestManager.load(mockUri("content://first")) .thumbnail(requestManager.load(mockUri("content://second")).thumbnail(0.5f)) .into(target); verify(target, times(3)).onResourceReady(isA(Drawable.class), isA(Transition.class)); }
@Test public void testAsBitmapOption() { Uri uri = Uri.parse("content://something/else"); mockUri(uri); requestManager.asBitmap().load(uri).into(target); verify(target).onResourceReady(isA(Bitmap.class), isA(Transition.class)); }
@Test public void testReceivesBitmapBytes() { String fakeUri = "content://fake"; mockUri(fakeUri); requestManager.as(byte[].class).apply(decodeTypeOf(Bitmap.class)).load(fakeUri).into(target); verify(target).onResourceReady(isA(byte[].class), isA(Transition.class)); }