Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Trying to test maps with Robolectric
public class ConnectivityBroadcastReceiver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
System.out.println("ConnectivityBroadcastReceiver onReceive");
@Implements(value = MapActivity.class, inheritImplementationMethods = true)
public class ExtendedShadowMapActivity extends ShadowMapActivity {
public void __constructor__() {
public void onResume() {
BroadcastReceiver connectivityBroadcastReceiver = new ConnectivityBroadcastReceiver();
registerReceiver(connectivityBroadcastReceiver, new IntentFilter());
try {
realActivity.getClass().getDeclaredField("mCalled").setBoolean(realActivity, true);
} catch (Exception e) {
@Config(manifest = TestUtility.ANDROID_MANIFEST_XML, shadows=ExtendedShadowMapActivity.class)
public class LocationsResultsMapTest {
private LocationsMainActivity activity;
private ActivityController<LocationsMainActivity> activityController;
public void setUp() throws Exception {
// activityController = Robolectric.buildActivity(LocationsMainActivity.class);
activity = Robolectric.buildActivity(LocationsMainActivity.class).create().get();
public void test() {
public class MockMapActivity extends MapActivity {
protected boolean isRouteDisplayed() {
return false;
protected void onCreate(Bundle arg0) {

Class under test changed to MockMapActivity, still same error.


do not extend ShadowMapActivity in your custom shadow , because in this case the call of
in your shadow will not have any effect. In ShadowMapActivity this method just blank.
Take code from here
rename class name and add changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.