PausedRequestsTest.java 1.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
package com.bumptech.glide;

import static com.google.common.truth.Truth.assertThat;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.test.InstrumentationRegistry;
import android.widget.ImageView;
import com.bumptech.glide.test.ConcurrencyHelper;
import com.bumptech.glide.test.GlideApp;
import com.bumptech.glide.test.GlideRequests;
import com.bumptech.glide.test.ResourceIds;
import com.bumptech.glide.test.TearDownGlide;
import org.junit.Rule;
import org.junit.Test;

/**
 * Tests how {@link com.bumptech.glide.request.Request}s behave when the corresponding
 * {@link RequestManager} is paused.
 */
public final class PausedRequestsTest {
  @Rule public final TearDownGlide tearDownGlide = new TearDownGlide();
  private final ConcurrencyHelper concurrency = new ConcurrencyHelper();
  private final Context context = InstrumentationRegistry.getTargetContext();

  @SuppressWarnings("unchecked")
  @Test
  public void load_withPlaceHolderSet_requestsPaused_displaysPlaceholder() {
    final ImageView imageView = new ImageView(context);

    final GlideRequests requests = GlideApp.with(context);
    concurrency.runOnMainThread(new Runnable() {
      @Override
      public void run() {
        requests.pauseAllRequests();
      }
    });

    final ColorDrawable expected = new ColorDrawable(Color.RED);
    concurrency.runOnMainThread(
        new Runnable() {
          @Override
          public void run() {
            requests
                .load(ResourceIds.drawable.bitmap_alias)
                .placeholder(expected)
                .into(imageView);
          }
        });

    assertThat(imageView.getDrawable()).isEqualTo(expected);
  }
}