Skip to content

Instantly share code, notes, and snippets.

@leviwilson
Created August 28, 2012 17:30
Show Gist options
  • Save leviwilson/3501169 to your computer and use it in GitHub Desktop.
Save leviwilson/3501169 to your computer and use it in GitHub Desktop.
Using the ShadowConnectivityManager in Robolectric
public class SomeActivityTest {
SomeActivity activity;
@Before
public void setUp() {
activity = new SomeActivity();
ConnectivityManager connectivityManager = getConnectivityManager();
Robolectric.shadowOf(connectivityManager).setNetworkInfo(TYPE_MOBILE, new NetworkInfo());
}
@Test
public void itDoesNotBlowUp() {
createActivity();
// validate something here
}
private void createActivity() {
Robolectric.shadowOf(activity).create();
}
private ConnectivityManager getConnectivityManager() {
return (ConnectivityManager) Robolectric.application.getSystemService(Context.CONNECTIVITY_SERVICE);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment