This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[android] - don't load default style if style json string was set (#1…
- Loading branch information
Showing
2 changed files
with
78 additions
and
7 deletions.
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
77 changes: 77 additions & 0 deletions
77
...idSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/StyleLoaderTest.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,77 @@ | ||
package com.mapbox.mapboxsdk.testapp.style; | ||
|
||
|
||
import android.support.test.espresso.UiController; | ||
|
||
import com.mapbox.mapboxsdk.maps.MapView; | ||
import com.mapbox.mapboxsdk.maps.MapboxMap; | ||
import com.mapbox.mapboxsdk.testapp.R; | ||
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction; | ||
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest; | ||
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity; | ||
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 BaseActivityTest { | ||
|
||
|
||
@Override | ||
protected Class getActivityClass() { | ||
return EspressoTestActivity.class; | ||
} | ||
|
||
@Test | ||
public void testSetGetStyleJsonString() throws Exception { | ||
validateTestSetup(); | ||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { | ||
@Override | ||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { | ||
try { | ||
String expected = ResourceUtils.readRawResource(rule.getActivity(), R.raw.local_style); | ||
mapboxMap.setStyleJson(expected); | ||
String actual = mapboxMap.getStyleJson(); | ||
assertEquals("Style json should match", expected, actual); | ||
} catch (IOException exception) { | ||
exception.printStackTrace(); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
@Test | ||
public void testDefaultStyleLoadWithActivityLifecycleChange() throws Exception { | ||
validateTestSetup(); | ||
invoke(mapboxMap, new MapboxMapAction.OnInvokeActionListener() { | ||
@Override | ||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) { | ||
try { | ||
String expected = ResourceUtils.readRawResource(rule.getActivity(), R.raw.local_style); | ||
mapboxMap.setStyleJson(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.getStyleJson(); | ||
assertEquals("Style URL should be empty", "", mapboxMap.getStyleUrl()); | ||
assertEquals("Style json should match", expected, actual); | ||
} catch (IOException exception) { | ||
exception.printStackTrace(); | ||
} | ||
} | ||
}); | ||
} | ||
} |