Stay organized with collections Save and categorize content based on your preferences.

IntentMatchers

public final class IntentMatchers


A collection of hamcrest matchers for matching Intent objects.

Summary

Public constructors

Public methods

static Matcher<Intent>
static Matcher<Intent>
static Matcher<Intent>
doesNotHaveExtraWithKey(Matcher<String> keyMatcher)
static Matcher<Intent>
filterEquals(Intent expectedIntent)

Matches an intent if it Intent#filterEquals(Intent) the expected intent.

static Matcher<Intent>
hasAction(String action)
static Matcher<Intent>
hasAction(Matcher<String> actionMatcher)
static Matcher<Intent>
hasCategories(Set<String> categories)
static Matcher<Intent>
hasCategories(
    Matcher<? extends Iterable<? super String>> categoriesMatcher
)
static Matcher<Intent>
hasComponent(ComponentName componentName)

Returns a matcher that will only match intents targeted to the componentName's class, {@see * ComponentName#getClassName}.

static Matcher<Intent>
hasComponent(String className)

Returns a matcher that will only match intents targeted to a single class by using hasClassName.

static Matcher<Intent>
hasComponent(Matcher<ComponentName> componentMatcher)

Can match an intent by class name, package name or short class name.

static Matcher<Intent>
hasData(Uri uri)
static Matcher<Intent>
static Matcher<Intent>
hasData(Matcher<Uri> uriMatcher)
static Matcher<Intent>
hasDataString(Matcher<String> stringMatcher)
static Matcher<Intent>
<T> hasExtra(String key, T value)
static Matcher<Intent>
hasExtra(String key, Matcher<?> valueMatcher)
static Matcher<Intent>
hasExtra(Matcher<String> keyMatcher, Matcher<?> valueMatcher)
static Matcher<Intent>
static Matcher<Intent>
hasExtraWithKey(Matcher<String> keyMatcher)
static Matcher<Intent>
hasExtras(Matcher<Bundle> bundleMatcher)
static Matcher<Intent>
hasFlag(int flag)
static Matcher<Intent>
hasFlags(int[] flags)
static Matcher<Intent>
hasFlags(int flags)
static Matcher<Intent>
hasPackage(String packageName)
static Matcher<Intent>
hasPackage(Matcher<String> packageMatcher)
static Matcher<Intent>
static Matcher<Intent>
hasType(Matcher<String> typeMatcher)
static Matcher<Intent>

Matches an intent if its package is the same as the target package for the instrumentation test.

static Matcher<Intent>
toPackage(String packageName)

Matches an intent based on the package of activity which can handle the intent.

Public constructors

IntentMatchers

public IntentMatchers()

Public methods

anyIntent

public static Matcher<Intent> anyIntent()

doesNotHaveExtraWithKey

public static Matcher<Intent> doesNotHaveExtraWithKey(String key)

doesNotHaveExtraWithKey

public static Matcher<Intent> doesNotHaveExtraWithKey(Matcher<String> keyMatcher)

filterEquals

public static Matcher<Intent> filterEquals(Intent expectedIntent)

Matches an intent if it Intent#filterEquals(Intent) the expected intent.

hasAction

public static Matcher<Intent> hasAction(String action)

hasAction

public static Matcher<Intent> hasAction(Matcher<String> actionMatcher)

hasCategories

public static Matcher<Intent> hasCategories(Set<String> categories)

hasCategories

public static Matcher<Intent> hasCategories(
    Matcher<? extends Iterable<? super String>> categoriesMatcher
)

hasComponent

public static Matcher<Intent> hasComponent(ComponentName componentName)

Returns a matcher that will only match intents targeted to the componentName's class, {@see * ComponentName#getClassName}. For example: Intent intent = new Intent() .setComponentName(new ComponentName("com.google.provider", "com.google.provider.Notepad")); will match all intents targeted to Notepad.java.

Parameters
ComponentName componentName

a componentName that has the target class specified

hasComponent

public static Matcher<Intent> hasComponent(String className)

Returns a matcher that will only match intents targeted to a single class by using hasClassName. The input string must contain the package name + short class name. For example hasComponent("com.google.provider.NotePad").

Parameters
String className

complete class path

hasComponent

public static Matcher<Intent> hasComponent(Matcher<ComponentName> componentMatcher)

Can match an intent by class name, package name or short class name.

Parameters
Matcher<ComponentName> componentMatcher

can be the value of ComponentNameMatchers#hasClassName, hasPackageName or ComponentNameMatchers#hasShortClassName

hasData

public static Matcher<Intent> hasData(Uri uri)

hasData

public static Matcher<Intent> hasData(String uri)

hasData

public static Matcher<Intent> hasData(Matcher<Uri> uriMatcher)

hasDataString

public static Matcher<Intent> hasDataString(Matcher<String> stringMatcher)

hasExtra

public static Matcher<Intent> <T> hasExtra(String key, T value)

hasExtra

public static Matcher<Intent> hasExtra(String key, Matcher<?> valueMatcher)

hasExtra

public static Matcher<Intent> hasExtra(Matcher<String> keyMatcher, Matcher<?> valueMatcher)

hasExtraWithKey

public static Matcher<Intent> hasExtraWithKey(String key)

hasExtraWithKey

public static Matcher<Intent> hasExtraWithKey(Matcher<String> keyMatcher)

hasExtras

public static Matcher<Intent> hasExtras(Matcher<Bundle> bundleMatcher)

hasFlag

public static Matcher<Intent> hasFlag(int flag)

hasFlags

public static Matcher<Intent> hasFlags(int[] flags)

hasFlags

public static Matcher<Intent> hasFlags(int flags)

hasPackage

public static Matcher<Intent> hasPackage(String packageName)

hasPackage

public static Matcher<Intent> hasPackage(Matcher<String> packageMatcher)

hasType

public static Matcher<Intent> hasType(String type)

hasType

public static Matcher<Intent> hasType(Matcher<String> typeMatcher)

isInternal

public static Matcher<Intent> isInternal()

Matches an intent if its package is the same as the target package for the instrumentation test.

toPackage

public static Matcher<Intent> toPackage(String packageName)

Matches an intent based on the package of activity which can handle the intent.

Parameters
String packageName

packages of activity that can handle the intent