summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
Diffstat (limited to 'platform')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/Mapbox.java11
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/MapboxTest.java26
2 files changed, 32 insertions, 5 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/Mapbox.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/Mapbox.java
index a809460375..6897cf66df 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/Mapbox.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/Mapbox.java
@@ -7,7 +7,6 @@ import android.net.NetworkInfo;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.UiThread;
-import android.text.TextUtils;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.exceptions.MapboxConfigurationException;
import com.mapbox.mapboxsdk.maps.Telemetry;
@@ -138,8 +137,12 @@ public final class Mapbox {
* @param accessToken the access token to validate
* @return true is valid, false otherwise
*/
- private static boolean isAccessTokenValid(String accessToken) {
- return !(TextUtils.isEmpty(accessToken)
- || (!accessToken.toLowerCase(MapboxConstants.MAPBOX_LOCALE).startsWith("pk.")));
+ static boolean isAccessTokenValid(String accessToken) {
+ if (accessToken == null) {
+ return false;
+ }
+
+ accessToken = accessToken.trim().toLowerCase(MapboxConstants.MAPBOX_LOCALE);
+ return accessToken.length() != 0 && (accessToken.startsWith("pk.") || accessToken.startsWith("sk."));
}
}
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/MapboxTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/MapboxTest.java
index e8d41ce2f1..7ddab4c49d 100644
--- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/MapboxTest.java
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/MapboxTest.java
@@ -3,7 +3,6 @@ package com.mapbox.mapboxsdk;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
-
import org.junit.Before;
import org.junit.Test;
@@ -46,6 +45,31 @@ public class MapboxTest {
}
@Test
+ public void testPkTokenValid() {
+ assertTrue(Mapbox.isAccessTokenValid("pk.0000000001"));
+ }
+
+ @Test
+ public void testSkTokenValid() {
+ assertTrue(Mapbox.isAccessTokenValid("sk.0000000001"));
+ }
+
+ @Test
+ public void testEmptyToken() {
+ assertFalse(Mapbox.isAccessTokenValid(""));
+ }
+
+ @Test
+ public void testNullToken() {
+ assertFalse(Mapbox.isAccessTokenValid(null));
+ }
+
+ @Test
+ public void testBlaBlaToken() {
+ assertFalse(Mapbox.isAccessTokenValid("blabla"));
+ }
+
+ @Test
public void testConnected() {
injectMapboxSingleton("dummy");