[android] clear singleton instance of Mapbox after running unit test suite

This commit is contained in:
Łukasz Paczos
2019-02-26 13:38:25 +01:00
committed by Łukasz Paczos
parent 19e66c8bfa
commit 5e41fd44f2

View File

@@ -2,6 +2,7 @@ package com.mapbox.mapboxsdk;
import android.content.Context;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -68,6 +69,11 @@ public class MapboxTest {
assertFalse(Mapbox.isAccessTokenValid("blabla"));
}
@After
public void after() {
clearMapboxSingleton();
}
private void injectMapboxSingleton(String accessToken) {
Mapbox mapbox = new Mapbox(context, accessToken);
try {
@@ -78,4 +84,14 @@ public class MapboxTest {
throw new AssertionError();
}
}
private void clearMapboxSingleton() {
try {
Field field = Mapbox.class.getDeclaredField("INSTANCE");
field.setAccessible(true);
field.set(field, null);
} catch (Exception exception) {
throw new AssertionError();
}
}
}