@CheckReturnValue
public final class IntentMatchers


A collection of hamcrest matchers for matching Intent objects.

Summary

Public methods

static Matcher<Intent>
static @NonNull Matcher<Intent>
static @NonNull Matcher<Intent>
static Matcher<Intent>
filterEquals(Intent expectedIntent)

Matches an intent if it filterEquals the expected intent.

static Matcher<Intent>
hasAction(Matcher<String> actionMatcher)
static Matcher<Intent>
hasAction(String action)
static Matcher<Intent>
hasCategories(Matcher<Iterable<String>> categoriesMatcher)
static Matcher<Intent>
hasCategories(Set<String> categories)
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>
hasComponent(ComponentName componentName)

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

static Matcher<Intent>
hasData(Matcher<Uri> uriMatcher)
static Matcher<Intent>
static Matcher<Intent>
hasData(Uri uri)
static Matcher<Intent>
hasDataString(Matcher<String> stringMatcher)
static Matcher<Intent>
hasExtra(Matcher<String> keyMatcher, Matcher<Object> valueMatcher)
static Matcher<Intent>
<T> hasExtra(String key, T value)
static Matcher<Intent>
hasExtra(String key, Matcher<Object> valueMatcher)
static Matcher<Intent>
static Matcher<Intent>
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(Matcher<String> packageMatcher)
static Matcher<Intent>
hasPackage(String packageName)
static Matcher<Intent>
hasType(Matcher<String> typeMatcher)
static Matcher<Intent>
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 methods

anyIntent

public static Matcher<IntentanyIntent()

doesNotHaveExtraWithKey

public static @NonNull Matcher<IntentdoesNotHaveExtraWithKey(@NonNull Matcher<String> keyMatcher)

doesNotHaveExtraWithKey

public static @NonNull Matcher<IntentdoesNotHaveExtraWithKey(@NonNull String key)

filterEquals

public static Matcher<IntentfilterEquals(Intent expectedIntent)

Matches an intent if it filterEquals the expected intent.

hasAction

public static Matcher<IntenthasAction(Matcher<String> actionMatcher)

hasAction

public static Matcher<IntenthasAction(String action)

hasCategories

public static Matcher<IntenthasCategories(Matcher<Iterable<String>> categoriesMatcher)

hasCategories

public static Matcher<IntenthasCategories(Set<String> categories)

hasComponent

public static Matcher<IntenthasComponent(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<IntenthasComponent(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 hasClassName, hasPackageName or hasShortClassName

hasComponent

public static Matcher<IntenthasComponent(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

hasData

public static Matcher<IntenthasData(Matcher<Uri> uriMatcher)

hasData

public static Matcher<IntenthasData(String uri)

hasData

public static Matcher<IntenthasData(Uri uri)

hasDataString

public static Matcher<IntenthasDataString(Matcher<String> stringMatcher)

hasExtra

public static Matcher<IntenthasExtra(Matcher<String> keyMatcher, Matcher<Object> valueMatcher)

hasExtra

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

hasExtra

public static Matcher<IntenthasExtra(String key, Matcher<Object> valueMatcher)

hasExtraWithKey

public static Matcher<IntenthasExtraWithKey(Matcher<String> keyMatcher)

hasExtraWithKey

public static Matcher<IntenthasExtraWithKey(String key)

hasExtras

public static Matcher<IntenthasExtras(Matcher<Bundle> bundleMatcher)

hasFlag

public static Matcher<IntenthasFlag(int flag)

hasFlags

public static Matcher<IntenthasFlags(int[] flags)

hasFlags

public static Matcher<IntenthasFlags(int flags)

hasPackage

public static Matcher<IntenthasPackage(Matcher<String> packageMatcher)

hasPackage

public static Matcher<IntenthasPackage(String packageName)

hasType

public static Matcher<IntenthasType(Matcher<String> typeMatcher)

hasType

public static Matcher<IntenthasType(String type)

isInternal

public static Matcher<IntentisInternal()

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

toPackage

public static Matcher<IntenttoPackage(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