Added in API level 1
Deprecated in API level 24

MoreAsserts


public final class MoreAsserts
extends Object

java.lang.Object
   ↳ android.test.MoreAsserts


This class was deprecated in API level 24.
Use Hamcrest matchers instead.

Contains additional assertion methods not found in JUnit.

Summary

Public methods

static void assertAssignableFrom(Class<?> expected, Object actual)

Asserts that the class expected is assignable from the object actual.

static void assertAssignableFrom(Class<?> expected, Class<?> actual)

Asserts that class expected is assignable from the class actual.

static MatchResult assertContainsRegex(String expectedRegex, String actual)

Variant of assertContainsRegex(java.lang.String, java.lang.String, java.lang.String) using a generic message.

static MatchResult assertContainsRegex(String message, String expectedRegex, String actual)

Asserts that expectedRegex matches any substring of actual and fails with message if it does not.

static void assertContentsInAnyOrder(String message, Iterable<?> actual, Object... expected)

Asserts that actual contains precisely the elements expected, but in any order.

static void assertContentsInAnyOrder(Iterable<?> actual, Object... expected)

Variant of assertContentsInAnyOrder(String, Iterable, Object...) using a generic message.

static void assertContentsInOrder(Iterable<?> actual, Object... expected)

Variant of assertContentsInOrder(String, Iterable, Object...) using a generic message.

static void assertContentsInOrder(String message, Iterable<?> actual, Object... expected)

Asserts that actual contains precisely the elements expected, and in the same order.

static void assertEmpty(String message, Map<?, ?> map)

Asserts that map is empty.

static void assertEmpty(Iterable<?> iterable)

Variant of assertEmpty(java.lang.String, java.lang.Iterable) using a generic message.

static void assertEmpty(Map<?, ?> map)

Variant of assertEmpty(java.lang.String, java.util.Map) using a generic message.

static void assertEmpty(String message, Iterable<?> iterable)

Asserts that iterable is empty.

static void assertEquals(String message, int[] expected, int[] actual)

Asserts that array actual is the same size and every element equals those in array expected.

static void assertEquals(String message, Set<?> expected, Set<?> actual)

Asserts that two sets contain the same elements.

static void assertEquals(String message, Object[] expected, Object[] actual)

Asserts that array actual is the same size and every element is the same as those in array expected.

static void assertEquals(Object[] expected, Object[] actual)

Asserts that array actual is the same size and every element is the same as those in array expected.

static void assertEquals(byte[] expected, byte[] actual)

Asserts that array actual is the same size and every element equals those in array expected.

static void assertEquals(Set<?> expected, Set<?> actual)

Asserts that two sets contain the same elements.

static void assertEquals(int[] expected, int[] actual)

Asserts that array actual is the same size and every element equals those in array expected.

static void assertEquals(String message, double[] expected, double[] actual)

Asserts that array actual is the same size and every element equals those in array expected.

static void assertEquals(String message, byte[] expected, byte[] actual)

Asserts that array actual is the same size and every element equals those in array expected.

static void assertEquals(double[] expected, double[] actual)

Asserts that array actual is the same size and every element equals those in array expected.

static MatchResult assertMatchesRegex(String expectedRegex, String actual)

Variant of assertMatchesRegex(java.lang.String, java.lang.String, java.lang.String) using a generic message.

static MatchResult assertMatchesRegex(String message, String expectedRegex, String actual)

Asserts that expectedRegex exactly matches actual and fails with message if it does not.

static void assertNotContainsRegex(String message, String expectedRegex, String actual)

Asserts that expectedRegex does not match any substring of actual, and fails with message if it does.

static void assertNotContainsRegex(String expectedRegex, String actual)

Variant of assertNotContainsRegex(java.lang.String, java.lang.String, java.lang.String) using a generic message.

static void assertNotEmpty(Map<?, ?> map)

Variant of assertNotEmpty(java.lang.String, java.util.Map) using a generic message.

static void assertNotEmpty(Iterable<?> iterable)

Variant of assertNotEmpty(String, Iterable) using a generic message.

static void assertNotEmpty(String message, Iterable<?> iterable)

Asserts that iterable is not empty.

static void assertNotEmpty(String message, Map<?, ?> map)

Asserts that map is not empty.

static void assertNotEqual(Object unexpected, Object actual)

Variant of assertNotEqual(java.lang.String, java.lang.Object, java.lang.Object) using a generic message.

static void assertNotEqual(String message, Object unexpected, Object actual)

Asserts that actual is not equal unexpected, according to both == and Object#equals.

static void assertNotMatchesRegex(String expectedRegex, String actual)

Variant of assertNotMatchesRegex(java.lang.String, java.lang.String, java.lang.String) using a generic message.

static void assertNotMatchesRegex(String message, String expectedRegex, String actual)

Asserts that expectedRegex does not exactly match actual, and fails with message if it does.

static void checkEqualsAndHashCodeMethods(String message, Object lhs, Object rhs, boolean expectedResult)

Utility for testing equals() and hashCode() results at once.

static void checkEqualsAndHashCodeMethods(Object lhs, Object rhs, boolean expectedResult)

Variant of checkEqualsAndHashCodeMethods(String,Object,Object,boolean...)} using a generic message.

Inherited methods

Public methods

assertAssignableFrom

Added in API level 1
public static void assertAssignableFrom (Class<?> expected, 
                Object actual)

Asserts that the class expected is assignable from the object actual. This verifies expected is a parent class or a interface that actual implements.

Parameters
expected Class

actual Object

assertAssignableFrom

Added in API level 1
public static void assertAssignableFrom (Class<?> expected, 
                Class<?> actual)

Asserts that class expected is assignable from the class actual. This verifies expected is a parent class or a interface that actual implements.

Parameters
expected Class

actual Class

assertContainsRegex

Added in API level 1
public static MatchResult assertContainsRegex (String expectedRegex, 
                String actual)

Variant of assertContainsRegex(java.lang.String, java.lang.String, java.lang.String) using a generic message.

Parameters
expectedRegex String

actual String

Returns
MatchResult

assertContainsRegex

Added in API level 1
public static MatchResult assertContainsRegex (String message, 
                String expectedRegex, 
                String actual)

Asserts that expectedRegex matches any substring of actual and fails with message if it does not. The Matcher is returned in case the test needs access to any captured groups. Note that you can also use this for a literal string, by wrapping your expected string in Pattern#quote.

Parameters
message String

expectedRegex String

actual String

Returns
MatchResult

assertContentsInAnyOrder

Added in API level 1
public static void assertContentsInAnyOrder (String message, 
                Iterable<?> actual, 
                Object... expected)

Asserts that actual contains precisely the elements expected, but in any order.

Parameters
message String

actual Iterable

expected Object

assertContentsInAnyOrder

Added in API level 1
public static void assertContentsInAnyOrder (Iterable<?> actual, 
                Object... expected)

Variant of assertContentsInAnyOrder(String, Iterable, Object...) using a generic message.

Parameters
actual Iterable

expected Object

assertContentsInOrder

Added in API level 1
public static void assertContentsInOrder (Iterable<?> actual, 
                Object... expected)

Variant of assertContentsInOrder(String, Iterable, Object...) using a generic message.

Parameters
actual Iterable

expected Object

assertContentsInOrder

Added in API level 1
public static void assertContentsInOrder (String message, 
                Iterable<?> actual, 
                Object... expected)

Asserts that actual contains precisely the elements expected, and in the same order.

Parameters
message String

actual Iterable

expected Object

assertEmpty

Added in API level 1
public static void assertEmpty (String message, 
                Map<?, ?> map)

Asserts that map is empty.

Parameters
message String

map Map

assertEmpty

Added in API level 1
public static void assertEmpty (Iterable<?> iterable)

Variant of assertEmpty(java.lang.String, java.lang.Iterable) using a generic message.

Parameters
iterable Iterable

assertEmpty

Added in API level 1
public static void assertEmpty (Map<?, ?> map)

Variant of assertEmpty(java.lang.String, java.util.Map) using a generic message.

Parameters
map Map

assertEmpty

Added in API level 1
public static void assertEmpty (String message, 
                Iterable<?> iterable)

Asserts that iterable is empty.

Parameters
message String

iterable Iterable

assertEquals

Added in API level 1
public static void assertEquals (String message, 
                int[] expected, 
                int[] actual)

Asserts that array actual is the same size and every element equals those in array expected. On failure, message indicates first specific element mismatch.

Parameters
message String

expected int

actual int

assertEquals

Added in API level 1
public static void assertEquals (String message, 
                Set<?> expected, 
                Set<?> actual)

Asserts that two sets contain the same elements.

Parameters
message String

expected Set

actual Set

assertEquals

Added in API level 1
public static void assertEquals (String message, 
                Object[] expected, 
                Object[] actual)

Asserts that array actual is the same size and every element is the same as those in array expected. Note that this uses equals() instead of == to compare the objects. null will be considered equal to null (unlike SQL). On failure, message indicates first specific element mismatch.

Parameters
message String

expected Object

actual Object

assertEquals

Added in API level 1
public static void assertEquals (Object[] expected, 
                Object[] actual)

Asserts that array actual is the same size and every element is the same as those in array expected. Note that this uses == instead of equals() to compare the objects. On failure, message indicates first specific element mismatch.

Parameters
expected Object

actual Object

assertEquals

Added in API level 1
public static void assertEquals (byte[] expected, 
                byte[] actual)

Asserts that array actual is the same size and every element equals those in array expected. On failure, message indicates specific element mismatch.

Parameters
expected byte

actual byte

assertEquals

Added in API level 1
public static void assertEquals (Set<?> expected, 
                Set<?> actual)

Asserts that two sets contain the same elements.

Parameters
expected Set

actual Set

assertEquals

Added in API level 1
public static void assertEquals (int[] expected, 
                int[] actual)

Asserts that array actual is the same size and every element equals those in array expected. On failure, message indicates first specific element mismatch.

Parameters
expected int

actual int

assertEquals

Added in API level 1
public static void assertEquals (String message, 
                double[] expected, 
                double[] actual)

Asserts that array actual is the same size and every element equals those in array expected. On failure, message indicates first specific element mismatch.

Parameters
message String

expected double

actual double

assertEquals

Added in API level 1
public static void assertEquals (String message, 
                byte[] expected, 
                byte[] actual)

Asserts that array actual is the same size and every element equals those in array expected. On failure, message indicates specific element mismatch.

Parameters
message String

expected byte

actual byte

assertEquals

Added in API level 1
public static void assertEquals (double[] expected, 
                double[] actual)

Asserts that array actual is the same size and every element equals those in array expected. On failure, message indicates first specific element mismatch.

Parameters
expected double

actual double

assertMatchesRegex

Added in API level 1
public static MatchResult assertMatchesRegex (String expectedRegex, 
                String actual)

Variant of assertMatchesRegex(java.lang.String, java.lang.String, java.lang.String) using a generic message.

Parameters
expectedRegex String

actual String

Returns
MatchResult

assertMatchesRegex

Added in API level 1
public static MatchResult assertMatchesRegex (String message, 
                String expectedRegex, 
                String actual)

Asserts that expectedRegex exactly matches actual and fails with message if it does not. The MatchResult is returned in case the test needs access to any captured groups. Note that you can also use this for a literal string, by wrapping your expected string in Pattern#quote.

Parameters
message String

expectedRegex String

actual String

Returns
MatchResult

assertNotContainsRegex

Added in API level 1
public static void assertNotContainsRegex (String message, 
                String expectedRegex, 
                String actual)

Asserts that expectedRegex does not match any substring of actual, and fails with message if it does. Note that you can also use this for a literal string, by wrapping your expected string in Pattern#quote.

Parameters
message String

expectedRegex String

actual String

assertNotContainsRegex

Added in API level 1
public static void assertNotContainsRegex (String expectedRegex, 
                String actual)

Variant of assertNotContainsRegex(java.lang.String, java.lang.String, java.lang.String) using a generic message.

Parameters
expectedRegex String

actual String

assertNotEmpty

Added in API level 1
public static void assertNotEmpty (Map<?, ?> map)

Variant of assertNotEmpty(java.lang.String, java.util.Map) using a generic message.

Parameters
map Map

assertNotEmpty

Added in API level 1
public static void assertNotEmpty (Iterable<?> iterable)

Variant of assertNotEmpty(String, Iterable) using a generic message.

Parameters
iterable Iterable

assertNotEmpty

Added in API level 1
public static void assertNotEmpty (String message, 
                Iterable<?> iterable)

Asserts that iterable is not empty.

Parameters
message String

iterable Iterable

assertNotEmpty

Added in API level 1
public static void assertNotEmpty (String message, 
                Map<?, ?> map)

Asserts that map is not empty.

Parameters
message String

map Map

assertNotEqual

Added in API level 1
public static void assertNotEqual (Object unexpected, 
                Object actual)

Variant of assertNotEqual(java.lang.String, java.lang.Object, java.lang.Object) using a generic message.

Parameters
unexpected Object

actual Object

assertNotEqual

Added in API level 1
public static void assertNotEqual (String message, 
                Object unexpected, 
                Object actual)

Asserts that actual is not equal unexpected, according to both == and Object#equals.

Parameters
message String

unexpected Object

actual Object

assertNotMatchesRegex

Added in API level 1
public static void assertNotMatchesRegex (String expectedRegex, 
                String actual)

Variant of assertNotMatchesRegex(java.lang.String, java.lang.String, java.lang.String) using a generic message.

Parameters
expectedRegex String

actual String

assertNotMatchesRegex

Added in API level 1
public static void assertNotMatchesRegex (String message, 
                String expectedRegex, 
                String actual)

Asserts that expectedRegex does not exactly match actual, and fails with message if it does. Note that you can also use this for a literal string, by wrapping your expected string in Pattern#quote.

Parameters
message String

expectedRegex String

actual String

checkEqualsAndHashCodeMethods

Added in API level 1
public static void checkEqualsAndHashCodeMethods (String message, 
                Object lhs, 
                Object rhs, 
                boolean expectedResult)

Utility for testing equals() and hashCode() results at once. Tests that lhs.equals(rhs) matches expectedResult, as well as rhs.equals(lhs). Also tests that hashCode() return values are equal if expectedResult is true. (hashCode() is not tested if expectedResult is false, as unequal objects can have equal hashCodes.)

Parameters
message String

lhs Object: An Object for which equals() and hashCode() are to be tested.

rhs Object: As lhs.

expectedResult boolean: True if the objects should compare equal, false if not.

checkEqualsAndHashCodeMethods

Added in API level 1
public static void checkEqualsAndHashCodeMethods (Object lhs, 
                Object rhs, 
                boolean expectedResult)

Variant of checkEqualsAndHashCodeMethods(String,Object,Object,boolean...)} using a generic message.

Parameters
lhs Object

rhs Object

expectedResult boolean