summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/StyleLoaderTest.java
blob: fd666d9fd3569d7faa64389df4ae30296cfad60e (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
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.mapbox.mapboxsdk.testapp.style;

import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.Style;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.activity.EspressoTest;
import com.mapbox.mapboxsdk.testapp.utils.ResourceUtils;
import org.junit.Test;

import java.io.IOException;

import static com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke;
import static org.junit.Assert.assertEquals;

/**
 * Tests around style loading
 */
public class StyleLoaderTest extends EspressoTest {

  @Test
  public void testSetGetStyleJsonString() {
    validateTestSetup();
    invoke(mapboxMap, (uiController, mapboxMap) -> {
      try {
        String expected = ResourceUtils.readRawResource(rule.getActivity(), R.raw.local_style);
        mapboxMap.setStyle(new Style.Builder().fromJson(expected));
        String actual = mapboxMap.getStyle().getJson();
        assertEquals("Style json should match", expected, actual);
      } catch (IOException exception) {
        exception.printStackTrace();
      }
    });
  }

  @Test
  public void testDefaultStyleLoadWithActivityLifecycleChange() {
    validateTestSetup();
    invoke(mapboxMap, (uiController, mapboxMap) -> {
      try {
        String expected = ResourceUtils.readRawResource(rule.getActivity(), R.raw.local_style);
        mapboxMap.setStyle(new Style.Builder().fromJson(expected));

        // fake activity stop/start
        MapView mapView = (MapView) rule.getActivity().findViewById(R.id.mapView);
        mapView.onPause();
        mapView.onStop();

        mapView.onStart();
        mapView.onResume();

        String actual = mapboxMap.getStyle().getJson();
        assertEquals("Style URL should be empty", "", mapboxMap.getStyle().getUrl());
        assertEquals("Style json should match", expected, actual);
      } catch (IOException exception) {
        exception.printStackTrace();
      }
    });
  }
}