# Intents

Summary:[Methods](https://developer.android.com/reference/android/support/test/espresso/intent/Intents#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/support/test/espresso/intent/Intents#inhmethods)\|[\[Expand All\]](https://developer.android.com/reference/android/support/test/espresso/intent/Intents#)  

# Intents

| This package is part of the Android[support library](https://developer.android.com/topic/libraries/support-library)which is no longer maintained. The support library has been superseded by[AndroidX](https://developer.android.com/jetpack/androidx)which is part of[Jetpack](https://developer.android.com/jetpack). We recommend using the AndroidX libraries in all new projects. You should also consider[migrating](https://developer.android.com/jetpack/androidx/migrate)existing projects to AndroidX. To find the AndroidX class that maps to this deprecated class, see the AndroidX support library[class mappings](https://developer.android.com/jetpack/androidx/migrate/class-mappings).

`
public

final

class
Intents
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object.html)`


``


`

|---|----------------------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) ||
| ↳ | android.support.test.espresso.intent.Intents |

<br />

*** ** * ** ***

Intents enables validation and stubbing of intents sent out by the application under test.

An example test that simply validates an outgoing intent:

`
`  

     public void testValidateIntentSentToPackage() {
       // User action that results in an external "phone" activity being launched.
       user.clickOnView(system.getView(R.id.callButton));

       // Using a canned RecordedIntentMatcher to validate that an intent resolving
       // to the "phone" activity has been sent.
       intended(toPackage("com.android.phone"));
     }
     
`
`

An example test with intent stubbing:

`
`  

     public void testActivityResultIsHandledProperly() {
       // Build a result to return when a particular activity is launched.
       Intent resultData = new Intent();
       String phoneNumber = "123-345-6789";
       resultData.putExtra("phone", phoneNumber);
       ActivityResult result = new ActivityResult(Activity.RESULT_OK, resultData);

       // Set up result stubbing when an intent sent to "contacts" is seen.
       intending(toPackage("com.android.contacts")).respondWith(result));

       // User action that results in "contacts" activity being launched.
       // Launching activity expects phoneNumber to be returned and displays it on the screen.
       user.clickOnView(system.getView(R.id.pickButton));

       // Assert that data we set up above is shown.
       assertTrue(user.waitForText(phoneNumber));
     }
     
`
`

<br />

## Summary

|                                                                                                                                                                                                                                                                                                                                         ### Public methods                                                                                                                                                                                                                                                                                                                                         ||
|-----------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` static void`                                                                                                              | ` `[assertNoUnverifiedIntents](https://developer.android.com/reference/android/support/test/espresso/intent/Intents#assertNoUnverifiedIntents())`() ` Asserts that Intents does not have any unverified intents.                                                                                                                                                                                                                                                                                                                                                      |
| ` static void`                                                                                                              | ` `[init](https://developer.android.com/reference/android/support/test/espresso/intent/Intents#init())`() ` Initializes Intents and begins recording intents.                                                                                                                                                                                                                                                                                                                                                                                                         |
| ` static void`                                                                                                              | ` `[intended](https://developer.android.com/reference/android/support/test/espresso/intent/Intents#intended(org.hamcrest.Matcher<android.content.Intent>, android.support.test.espresso.intent.VerificationMode))`(Matcher<`[Intent](https://developer.android.com/reference/android/content/Intent.html)`> matcher, `[VerificationMode](https://developer.android.com/reference/android/support/test/espresso/intent/VerificationMode)` verificationMode) ` Asserts that the given matcher matches a specified number of intents sent by the application under test. |
| ` static void`                                                                                                              | ` `[intended](https://developer.android.com/reference/android/support/test/espresso/intent/Intents#intended(org.hamcrest.Matcher<android.content.Intent>))`(Matcher<`[Intent](https://developer.android.com/reference/android/content/Intent.html)`> matcher) ` Asserts that the given matcher matches one and only one intent sent by the application under test.                                                                                                                                                                                                    |
| ` static `[OngoingStubbing](https://developer.android.com/reference/android/support/test/espresso/intent/OngoingStubbing)   | ` `[intending](https://developer.android.com/reference/android/support/test/espresso/intent/Intents#intending(org.hamcrest.Matcher<android.content.Intent>))`(Matcher<`[Intent](https://developer.android.com/reference/android/content/Intent.html)`> matcher) ` Enables stubbing intent responses.                                                                                                                                                                                                                                                                  |
| ` static void`                                                                                                              | ` `[release](https://developer.android.com/reference/android/support/test/espresso/intent/Intents#release())`() ` Clears Intents state.                                                                                                                                                                                                                                                                                                                                                                                                                               |
| ` static `[VerificationMode](https://developer.android.com/reference/android/support/test/espresso/intent/VerificationMode) | ` `[times](https://developer.android.com/reference/android/support/test/espresso/intent/Intents#times(int))`(int times) ` Allows verifying a specific number of intents sent by the application under test.                                                                                                                                                                                                                                                                                                                                                           |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/test/espresso/intent/Intents#)From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object.html)` ` |-------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object.html)          | ` clone() `                                                                                | | ` boolean`                                                                          | ` equals(`[Object](https://developer.android.com/reference/java/lang/Object.html)` arg0) ` | | ` void`                                                                             | ` finalize() `                                                                             | | ` final `[Class](https://developer.android.com/reference/java/lang/Class.html)`<?>` | ` getClass() `                                                                             | | ` int`                                                                              | ` hashCode() `                                                                             | | ` final void`                                                                       | ` notify() `                                                                               | | ` final void`                                                                       | ` notifyAll() `                                                                            | | ` `[String](https://developer.android.com/reference/java/lang/String.html)          | ` toString() `                                                                             | | ` final void`                                                                       | ` wait(long arg0, int arg1) `                                                              | | ` final void`                                                                       | ` wait(long arg0) `                                                                        | | ` final void`                                                                       | ` wait() `                                                                                 | ||

## Public methods

### assertNoUnverifiedIntents

```
void assertNoUnverifiedIntents ()
```

Asserts that Intents does not have any unverified intents. You can use this method after you have verified your intents to make sure that nothing unexpected was sent out. This is an equivalent of verifyNoMoreInteractions() in Mockito.

<br />

### init

```
void init ()
```

Initializes Intents and begins recording intents. Must be called prior to triggering any actions that send out intents which need to be verified or stubbed. This is similar to MockitoAnnotations.initMocks.

<br />

### intended

```
void intended (Matcher<Intent> matcher, 
                VerificationMode verificationMode)
```

Asserts that the given matcher matches a specified number of intents sent by the application under test. This is an equivalent of verify(mock, times(num)) in Mockito. Verification does not have to occur in the same order as the intents were sent. Intents are recorded from the time that Intents.init is called.

<br />

|                                                                    Parameters                                                                     ||
|--------------------|-------------------------------------------------------------------------------------------------------------------------------|
| `matcher`          | `Matcher`: the[Matcher](https://developer.android.com/reference/org/hamcrest/Matcher)to be applied to captured intents <br /> |
| `verificationMode` | `VerificationMode` <br />                                                                                                     |

|                                                                   Throws                                                                    ||
|---|------------------------------------------------------------------------------------------------------------------------------------------|
|   | if the given[Matcher](https://developer.android.com/reference/org/hamcrest/Matcher)did not match the expected number of recorded intents |

### intended

```
void intended (Matcher<Intent> matcher)
```

Asserts that the given matcher matches one and only one intent sent by the application under test. This is an equivalent of verify(mock, times(1)) in Mockito. Verification does not have to occur in the same order as the intents were sent. Intents are recorded from the time that Intents.init is called.

<br />

|                                                                Parameters                                                                ||
|-----------|-------------------------------------------------------------------------------------------------------------------------------|
| `matcher` | `Matcher`: the[Matcher](https://developer.android.com/reference/org/hamcrest/Matcher)to be applied to captured intents <br /> |

|                                                                          Throws                                                                          ||
|---|-------------------------------------------------------------------------------------------------------------------------------------------------------|
|   | if the given[Matcher](https://developer.android.com/reference/org/hamcrest/Matcher)did not match any or matched more than one of the recorded intents |

### intending

```
OngoingStubbing intending (Matcher<Intent> matcher)
```

Enables stubbing intent responses. This method is similar to Mockito.when and is particularly useful when the activity launching the intent expects data to be returned (and especially in the case when the destination activity is external). In this case, the test author can call intending(matcher).thenRespond(myResponse) and validate that the launching activity handles the result correctly.**Note:**the destination activity will not be launched.

<br />

|                                                                                Parameters                                                                                 ||
|-----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `matcher` | `Matcher`: the[Matcher](https://developer.android.com/reference/org/hamcrest/Matcher)that matches intents for which stubbed response should be provided <br /> |

|                                                                                                                                Returns                                                                                                                                ||
|-----------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------|
| [OngoingStubbing](https://developer.android.com/reference/android/support/test/espresso/intent/OngoingStubbing) | [OngoingStubbing](https://developer.android.com/reference/android/support/test/espresso/intent/OngoingStubbing)object to set stubbed response <br /> |

### release

```
void release ()
```

Clears Intents state. Must be called after each test case.

<br />

### times

```
VerificationMode times (int times)
```

Allows verifying a specific number of intents sent by the application under test. This is an equivalent of times(num) in Mockito.

<br />

|                                  Parameters                                   ||
|---------|----------------------------------------------------------------------|
| `times` | `int`: the number of times that the intent should be matched. <br /> |

|                                                          Returns                                                          ||
|-------------------------------------------------------------------------------------------------------------------|--------|
| [VerificationMode](https://developer.android.com/reference/android/support/test/espresso/intent/VerificationMode) | <br /> |

-

  ## Interfaces

  - [ActivityResultFunction](https://developer.android.com/reference/android/support/test/espresso/intent/ActivityResultFunction)
  - [ResettingStubber](https://developer.android.com/reference/android/support/test/espresso/intent/ResettingStubber)
  - [ResolvedIntent](https://developer.android.com/reference/android/support/test/espresso/intent/ResolvedIntent)
  - [VerifiableIntent](https://developer.android.com/reference/android/support/test/espresso/intent/VerifiableIntent)
  - [VerificationMode](https://developer.android.com/reference/android/support/test/espresso/intent/VerificationMode)
-

  ## Classes

  - [Checks](https://developer.android.com/reference/android/support/test/espresso/intent/Checks)
  - [Intents](https://developer.android.com/reference/android/support/test/espresso/intent/Intents)
  - [OngoingStubbing](https://developer.android.com/reference/android/support/test/espresso/intent/OngoingStubbing)
  - [ResettingStubberImpl](https://developer.android.com/reference/android/support/test/espresso/intent/ResettingStubberImpl)
  - [VerificationModes](https://developer.android.com/reference/android/support/test/espresso/intent/VerificationModes)