summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/ImageTest.java
blob: 0e4c8f3f2e266a0f3c961d35d2d7d883b01df52d (plain)
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
package com.mapbox.mapboxsdk.testapp.style;

import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.support.test.runner.AndroidJUnit4;

import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction;

import com.mapbox.mapboxsdk.testapp.activity.EspressoTest;
import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

/**
 * CRUD tests around Image
 */
@RunWith(AndroidJUnit4.class)
public class ImageTest extends EspressoTest {

  private static final String IMAGE_ID = "test.image";

  @Test
  public void testAddGetImage() {
    validateTestSetup();
    MapboxMapAction.invoke(mapboxMap, (uiController, mapboxMap) -> {
      Drawable drawable = rule.getActivity().getResources().getDrawable(R.drawable.ic_launcher_round);
      assertTrue(drawable instanceof BitmapDrawable);

      Bitmap bitmapSet = ((BitmapDrawable) drawable).getBitmap();
      mapboxMap.getStyle().addImage(IMAGE_ID, bitmapSet);

      // adding an image requires converting the image with an asynctask
      uiController.loopMainThreadForAtLeast(200);

      Bitmap bitmapGet = mapboxMap.getStyle().getImage(IMAGE_ID);
      assertTrue(bitmapGet.sameAs(bitmapSet));

      mapboxMap.getStyle().removeImage(IMAGE_ID);
      assertNull(mapboxMap.getStyle().getImage(IMAGE_ID));
    });
  }
}