Skip to content

Commit

Permalink
Add tests for GlideFutures
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 269698115
  • Loading branch information
sjudd authored and glide-copybara-robot committed Sep 18, 2019
1 parent e31e1e9 commit 3084bac
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
4 changes: 3 additions & 1 deletion integration/concurrent/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ dependencies {
implementation "com.google.guava:guava:${GUAVA_VERSION}"
implementation "androidx.concurrent:concurrent-futures:${ANDROID_X_FUTURES_VERSION}"

testImplementation project(':mocks')
testImplementation "androidx.legacy:legacy-support-v4:${ANDROID_X_VERSION}"
testImplementation "androidx.test:core:${ANDROIDX_TEST_VERSION}"
testImplementation "com.google.truth:truth:${TRUTH_VERSION}"
testImplementation "junit:junit:${JUNIT_VERSION}"
testImplementation "org.robolectric:robolectric:${ROBOLECTRIC_VERSION}"
testImplementation "androidx.legacy:legacy-support-v4:${ANDROID_X_VERSION}"
}

android {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.bumptech.glide.integration.concurrent;

import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertThrows;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import androidx.test.core.app.ApplicationProvider;
import com.bumptech.glide.Glide;
import com.bumptech.glide.GlideBuilder;
import com.bumptech.glide.load.engine.executor.GlideExecutor;
import com.bumptech.glide.load.engine.executor.MockGlideExecutor;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import java.util.concurrent.ExecutionException;
import org.junit.Before;
import org.junit.Test;
import org.junit.function.ThrowingRunnable;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;

@RunWith(RobolectricTestRunner.class)
public final class GlideFuturesTest {

private Context app;

@Before
public void setUp() {
app = ApplicationProvider.getApplicationContext();

GlideExecutor executor = MockGlideExecutor.newMainThreadExecutor();
Glide.init(
app,
new GlideBuilder()
.setAnimationExecutor(executor)
.setSourceExecutor(executor)
.setDiskCacheExecutor(executor));
}

@Test
public void testBaseLoad() throws Exception {
ColorDrawable expected = new ColorDrawable(Color.RED);
ListenableFuture<Drawable> future = GlideFutures.submit(Glide.with(app).load(expected));
assertThat(((ColorDrawable) Futures.getDone(future)).getColor()).isEqualTo(expected.getColor());
}

@Test
public void testErrorLoad() {
// Load some unsupported model.
final ListenableFuture<Bitmap> future =
GlideFutures.submit(Glide.with(app).asBitmap().load(app));
// Make sure that it throws.
assertThrows(
ExecutionException.class,
new ThrowingRunnable() {
@Override
public void run() throws Throwable {
Futures.getDone(future);
}
});
}
}

0 comments on commit 3084bac

Please sign in to comment.