Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] - expose setAccesToken on Mapbox.java
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun committed Dec 5, 2018
1 parent efe4f4c commit 0540f59
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static synchronized Mapbox getInstance(@NonNull Context context, @Nullabl
}

/**
* Access token for this application.
* Get the current active access token for this application.
*
* @return Mapbox access token
*/
Expand All @@ -78,6 +78,15 @@ public static String getAccessToken() {
return INSTANCE.accessToken;
}

/**
* Set the current active accessToken.
*/
public static void setAccessToken(String accessToken) {
validateMapbox();
INSTANCE.accessToken = accessToken;
FileSource.getInstance(getApplicationContext()).setAccessToken(accessToken);
}

/**
* Application context
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
import org.junit.Test;

import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertSame;
import static junit.framework.Assert.assertTrue;

public class MapboxTest extends BaseActivityTest {

private static final String ACCESS_TOKEN = "pk.0000000001";
private static final String ACCESS_TOKEN_2 = "pk.0000000002";

@Override
protected Class getActivityClass() {
return EspressoTestActivity.class;
Expand All @@ -30,4 +34,15 @@ public void testConnected() {
Mapbox.setConnected(null);
assertTrue(Mapbox.isConnected());
}

@Test
public void setAccessToken() {
validateTestSetup();
String realToken = Mapbox.getAccessToken();
Mapbox.setAccessToken(ACCESS_TOKEN);
assertSame(ACCESS_TOKEN, Mapbox.getAccessToken());
Mapbox.setAccessToken(ACCESS_TOKEN_2);
assertSame(ACCESS_TOKEN_2, Mapbox.getAccessToken());
Mapbox.setAccessToken(realToken);
}
}

0 comments on commit 0540f59

Please sign in to comment.