-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
.../concurrent/src/test/java/com/bumptech/glide/integration/concurrent/GlideFuturesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); | ||
} | ||
} |