Created
August 28, 2012 17:30
-
-
Save leviwilson/3501169 to your computer and use it in GitHub Desktop.
Using the ShadowConnectivityManager in Robolectric
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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