robolectric/robolectric — pull request #703 by coreydowning (2013-09-23 23:07:19+00:00)
Title: Add optional check for Activity presence on `startActivity`

This adds an optional check to `startActivity` for whether the Action of the passed `Intent` is present in the Applications's `PackageManager`. You could use it like so:

```java
@Test
public void clickingButton_startsMyActivity() throws Exception {
Robolectric.checkActivities(true); // Probably better to do this in TestRunner

activity.findViewById(R.id.button).performClick();

String action = shadowOf(activity).getNextStartedActivity().getAction();
assertThat(action).isEqualTo("com.example.MyActivity");
}
```

Currently the code and assertion would pass if the `startActivity` call used the correct Action. However, with `checkActivities` enabled the code will throw an `ActivityNotFoundException` if `com.example.MyActivity` does not exist in the app's manifest (manifest Activities are auto added to the Package Manager now). This means that you can drive out the correct launch and setup for your Activity.

It also allows simulation of different packages existing on the phone. For instance, you could test functionality that relies on apps existing on the phone work correctly with and without that app present by setting up the package manager for your test using `RobolectricPackageManager#addResolveInfoForIntent(Intent, ResolveInfo)`.

This motivated by a feature request in #693. We think it could possibly be default behavior but seems like a large breaking change and should be left optional for the moment.