Class Verify
Assert
class, which adds useful additional "assert" methods.
You can import this class instead of Assert, and use it thus, e.g.:
Verify.assertEquals("fred", name); // from original Assert class Verify.assertContains("fred", nameList); // from new extensions Verify.assertBefore("fred", "jim", orderedNamesList); // from new extensions
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> void
assertAllSatisfy
(Iterable<T> iterable, Predicate<? super T> predicate) static <T> void
assertAllSatisfy
(String message, Iterable<T> iterable, Predicate<? super T> predicate) static <K,
V> void assertAllSatisfy
(Map<K, V> map, Predicate<? super V> predicate) static <T> void
assertAnySatisfy
(Iterable<T> iterable, Predicate<? super T> predicate) static <T> void
assertAnySatisfy
(String message, Iterable<T> iterable, Predicate<? super T> predicate) static <K,
V> void assertAnySatisfy
(Map<K, V> map, Predicate<? super V> predicate) static <K,
V> void assertBagMultimapsEqual
(String multimapName, BagMultimap<K, V> expectedBagMultimap, BagMultimap<K, V> actualBagMultimap) static <K,
V> void assertBagMultimapsEqual
(BagMultimap<K, V> expectedBagMultimap, BagMultimap<K, V> actualBagMultimap) static void
assertBagsEqual
(String bagName, Bag<?> expectedBag, Bag<?> actualBag) static void
assertBagsEqual
(Bag<?> expectedBag, Bag<?> actualBag) static void
assertBefore
(Object formerItem, Object latterItem, List<?> actualList) Assert that the formerItem appears before the latterItem in the givenCollection
.static void
assertBefore
(String listName, Object formerItem, Object latterItem, List<?> actualList) Assert that the formerItem appears before the latterItem in the givenCollection
.static <T> void
assertClassNonInstantiable
(Class<T> aClass) static void
assertContains
(Object expectedItem, Collection<?> actualCollection) Assert that the givenCollection
contains the given item.static void
assertContains
(Object expectedItem, ImmutableCollection<?> actualImmutableCollection) Assert that the givenImmutableCollection
contains the given item.static void
assertContains
(String collectionName, Object expectedItem, Collection<?> actualCollection) Assert that the givenCollection
contains the given item.static void
assertContains
(String immutableCollectionName, Object expectedItem, ImmutableCollection<?> actualImmutableCollection) Assert that the givenImmutableCollection
contains the given item.static void
assertContains
(String stringToFind, String stringToSearch) Assert that the givenstringToFind
is contained within thestringToSearch
.static void
assertContains
(String stringName, String stringToFind, String stringToSearch) Assert that the givenstringToFind
is contained within thestringToSearch
.static void
assertContainsAll
(Iterable<?> iterable, Object... items) static void
assertContainsAll
(String collectionName, Iterable<?> iterable, Object... items) static void
assertContainsAllEntries
(String multimapName, Multimap<?, ?> actualMultimap, Object... expectedKeyValues) Assert the givenMultimap
contains all the given keys and values.static void
assertContainsAllEntries
(Multimap<?, ?> actualMultimap, Object... keyValues) Assert the givenMultimap
contains all the given keys and values.static void
assertContainsAllKeyValues
(String mapName, Map<?, ?> actualMap, Object... expectedKeyValues) Assert that the givenMap
contains all the given keys and values.static void
assertContainsAllKeyValues
(String immutableMapIterableName, ImmutableMapIterable<?, ?> immutableMapIterable, Object... expectedKeyValues) Assert that the givenImmutableMapIterable
contains all the given keys and values.static void
assertContainsAllKeyValues
(String mapIterableName, MapIterable<?, ?> mapIterable, Object... expectedKeyValues) Assert that the givenMapIterable
contains all the given keys and values.static void
assertContainsAllKeyValues
(String mutableMapIterableName, MutableMapIterable<?, ?> mutableMapIterable, Object... expectedKeyValues) Assert that the givenMutableMapIterable
contains all the given keys and values.static void
assertContainsAllKeyValues
(Map<?, ?> actualMap, Object... keyValues) Assert that the givenMap
contains all the given keys and values.static void
assertContainsAllKeyValues
(ImmutableMapIterable<?, ?> immutableMapIterable, Object... keyValues) Assert that the givenImmutableMapIterable
contains all the given keys and values.static void
assertContainsAllKeyValues
(MapIterable<?, ?> mapIterable, Object... keyValues) Assert that the givenMapIterable
contains all the given keys and values.static void
assertContainsAllKeyValues
(MutableMapIterable<?, ?> mutableMapIterable, Object... keyValues) Assert that the givenMutableMapIterable
contains all the given keys and values.static <K,
V> void assertContainsEntry
(String multimapName, K expectedKey, V expectedValue, Multimap<K, V> actualMultimap) Assert that the givenMultimap
contains an entry with the given key and value.static <K,
V> void assertContainsEntry
(K expectedKey, V expectedValue, Multimap<K, V> actualMultimap) Assert that the givenMultimap
contains an entry with the given key and value.static void
assertContainsKey
(Object expectedKey, Map<?, ?> actualMap) Assert that the givenMap
contains an entry with the given key.static void
assertContainsKey
(Object expectedKey, ImmutableMapIterable<?, ?> immutableMapIterable) Assert that the givenImmutableMapIterable
contains an entry with the given key.static void
assertContainsKey
(Object expectedKey, MapIterable<?, ?> mapIterable) Assert that the givenMapIterable
contains an entry with the given key.static void
assertContainsKey
(Object expectedKey, MutableMapIterable<?, ?> mutableMapIterable) Assert that the givenMutableMapIterable
contains an entry with the given key.static void
assertContainsKey
(String mapName, Object expectedKey, Map<?, ?> actualMap) Assert that the givenMap
contains an entry with the given key.static void
assertContainsKey
(String immutableMapIterableName, Object expectedKey, ImmutableMapIterable<?, ?> immutableMapIterable) Assert that the givenImmutableMapIterable
contains an entry with the given key.static void
assertContainsKey
(String mapIterableName, Object expectedKey, MapIterable<?, ?> mapIterable) Assert that the givenMapIterable
contains an entry with the given key.static void
assertContainsKey
(String mutableMapIterableName, Object expectedKey, MutableMapIterable<?, ?> mutableMapIterable) Assert that the givenMutableMapIterable
contains an entry with the given key.static void
assertContainsKeyValue
(Object expectedKey, Object expectedValue, Map<?, ?> actualMap) Assert that the givenMap
contains an entry with the given key and value.static void
assertContainsKeyValue
(Object expectedKey, Object expectedValue, ImmutableMapIterable<?, ?> mapIterable) Assert that the givenImmutableMapIterable
contains an entry with the given key and value.static void
assertContainsKeyValue
(Object expectedKey, Object expectedValue, MapIterable<?, ?> mapIterable) Assert that the givenMapIterable
contains an entry with the given key and value.static void
assertContainsKeyValue
(Object expectedKey, Object expectedValue, MutableMapIterable<?, ?> mapIterable) Assert that the givenMutableMapIterable
contains an entry with the given key and value.static void
assertContainsKeyValue
(String mapName, Object expectedKey, Object expectedValue, Map<?, ?> actualMap) Assert that the givenMap
contains an entry with the given key and value.static void
assertContainsKeyValue
(String mapIterableName, Object expectedKey, Object expectedValue, ImmutableMapIterable<?, ?> immutableMapIterable) Assert that the givenImmutableMapIterable
contains an entry with the given key and value.static void
assertContainsKeyValue
(String mapIterableName, Object expectedKey, Object expectedValue, MapIterable<?, ?> mapIterable) Assert that the givenMapIterable
contains an entry with the given key and value.static void
assertContainsKeyValue
(String mapIterableName, Object expectedKey, Object expectedValue, MutableMapIterable<?, ?> mutableMapIterable) Assert that the givenMutableMapIterable
contains an entry with the given key and value.static void
assertContainsNone
(Collection<?> actualCollection, Object... items) static <T> void
assertCount
(int expectedCount, Iterable<T> iterable, Predicate<? super T> predicate) static void
assertDeserializedForm
(String expectedBase64Form, Object actualObject) static void
assertEmpty
(Iterable<?> actualIterable) Assert that the givenIterable
is empty.static void
assertEmpty
(String iterableName, Iterable<?> actualIterable) Assert that the givenCollection
is empty.static void
assertEmpty
(String mapName, Map<?, ?> actualMap) Assert that the givenMap
is empty.static void
assertEmpty
(String mutableMapIterableName, MutableMapIterable<?, ?> actualMutableMapIterable) Assert that the givenCollection
is empty.static void
assertEmpty
(String multimapName, Multimap<?, ?> actualMultimap) Assert that the givenMultimap
is empty.static void
assertEmpty
(String iterableName, PrimitiveIterable primitiveIterable) Assert that the givenPrimitiveIterable
is empty.static void
assertEmpty
(Map<?, ?> actualMap) Assert that the givenMap
is empty.static void
assertEmpty
(MutableMapIterable<?, ?> actualMutableMapIterable) Assert that the givenMutableMapIterable
is empty.static void
assertEmpty
(Multimap<?, ?> actualMultimap) Assert that the givenMultimap
is empty.static void
assertEmpty
(PrimitiveIterable primitiveIterable) Assert that the givenPrimitiveIterable
is empty.static <T> void
assertEndsWith
(List<T> list, T... items) static <T> void
assertEndsWith
(T[] array, T... items) static void
assertEqualsAndHashCode
(Object objectA, Object objectB) Assert thatobjectA
andobjectB
are equal via theObject.equals(Object)
method, and that they both return the sameObject.hashCode()
.static void
assertEqualsAndHashCode
(String itemNames, Object objectA, Object objectB) Assert thatobjectA
andobjectB
are equal (via theObject.equals(Object)
method, and that they both return the sameObject.hashCode()
.static void
assertError
(Class<? extends Error> expectedErrorClass, Runnable code) static void
assertInstanceOf
(Class<?> expectedClassType, Object actualObject) Assert that the given object is an instanceof expectedClassType.static void
assertInstanceOf
(String objectName, Class<?> expectedClassType, Object actualObject) Assert that the given object is an instanceof expectedClassType.static void
assertItemAtIndex
(Object expectedItem, int index, Object[] array) Assert that the givenitem
is at theindex
in the givenarray
.static void
assertItemAtIndex
(Object expectedItem, int index, List<?> list) static void
assertItemAtIndex
(String arrayName, Object expectedItem, int index, Object[] array) static void
assertItemAtIndex
(String listName, Object expectedItem, int index, List<?> list) static void
assertIterableEmpty
(Iterable<?> iterable) Assert that the givenIterable
is empty.static void
assertIterableEmpty
(String iterableName, Iterable<?> iterable) Assert that the givenIterable
is empty.static void
assertIterableNotEmpty
(Iterable<?> iterable) Assert that the givenIterable
is not empty.static void
assertIterableNotEmpty
(String iterableName, Iterable<?> iterable) Assert that the givenIterable
is not empty.static void
assertIterablesEqual
(Iterable<?> expectedIterable, Iterable<?> actualIterable) static void
assertIterablesEqual
(String iterableName, Iterable<?> expectedIterable, Iterable<?> actualIterable) static void
assertIterableSize
(int expectedSize, Iterable<?> actualIterable) Assert the size of the givenIterable
.static void
assertIterableSize
(String iterableName, int expectedSize, Iterable<?> actualIterable) Assert the size of the givenIterable
.static <K,
V> void assertListMultimapsEqual
(String multimapName, ListMultimap<K, V> expectedListMultimap, ListMultimap<K, V> actualListMultimap) static <K,
V> void assertListMultimapsEqual
(ListMultimap<K, V> expectedListMultimap, ListMultimap<K, V> actualListMultimap) static void
assertListsEqual
(String listName, List<?> expectedList, List<?> actualList) static void
assertListsEqual
(List<?> expectedList, List<?> actualList) static void
assertMapsEqual
(String mapName, Map<?, ?> expectedMap, Map<?, ?> actualMap) static void
assertMapsEqual
(Map<?, ?> expectedMap, Map<?, ?> actualMap) static void
assertNegative
(int value) Asserts that a value is negative.static <T> void
assertNoneSatisfy
(Iterable<T> iterable, Predicate<? super T> predicate) static <T> void
assertNoneSatisfy
(String message, Iterable<T> iterable, Predicate<? super T> predicate) static <K,
V> void assertNoneSatisfy
(Map<K, V> map, Predicate<? super V> predicate) static void
assertNotContains
(Object unexpectedItem, Iterable<?> iterable) Assert that the givenIterable
does not contain the given item.static void
assertNotContains
(Object unexpectedItem, Collection<?> actualCollection) Assert that the givenCollection
does not contain the given item.static void
assertNotContains
(String collectionName, Object unexpectedItem, Iterable<?> iterable) Assert that the givenIterable
does not contain the given item.static void
assertNotContains
(String collectionName, Object unexpectedItem, Collection<?> actualCollection) Assert that the givenCollection
does not contain the given item.static void
assertNotContains
(String unexpectedString, String stringToSearch) Assert that the givenunexpectedString
is not contained within thestringToSearch
.static void
assertNotContains
(String stringName, String unexpectedString, String stringToSearch) Assert that the givenunexpectedString
is not contained within thestringToSearch
.static void
assertNotContainsKey
(Object unexpectedKey, Map<?, ?> actualMap) Assert that the givenCollection
does not contain the given item.static void
assertNotContainsKey
(String mapName, Object unexpectedKey, Map<?, ?> actualMap) Assert that the givenCollection
does not contain the given item.static void
assertNotEmpty
(Iterable<?> actualIterable) Assert that the givenIterable
is not empty.static void
assertNotEmpty
(String iterableName, Iterable<?> actualIterable) Assert that the givenIterable
is not empty.static void
assertNotEmpty
(String mapName, Map<?, ?> actualMap) Assert that the givenMap
is not empty.static void
assertNotEmpty
(String mutableMapIterableName, MutableMapIterable<?, ?> actualMutableMapIterable) Assert that the givenMutableMapIterable
is not empty.static void
assertNotEmpty
(String multimapName, Multimap<?, ?> actualMultimap) Assert that the givenMultimap
is not empty.static void
assertNotEmpty
(String iterableName, PrimitiveIterable primitiveIterable) Assert that the givenPrimitiveIterable
is not empty.static <T> void
assertNotEmpty
(String itemsName, T[] items) static void
assertNotEmpty
(Map<?, ?> actualMap) Assert that the givenMap
is not empty.static void
assertNotEmpty
(MutableMapIterable<?, ?> actualMutableMapIterable) Assert that the givenMutableMapIterable
is not empty.static void
assertNotEmpty
(Multimap<?, ?> actualMultimap) Assert that the givenMultimap
is not empty.static void
assertNotEmpty
(PrimitiveIterable primitiveIterable) Assert that the givenPrimitiveIterable
is not empty.static <T> void
assertNotEmpty
(T[] items) static void
assertNotInstanceOf
(Class<?> expectedClassType, Object actualObject) Assert that the given object is not an instanceof expectedClassType.static void
assertNotInstanceOf
(String objectName, Class<?> expectedClassType, Object actualObject) Assert that the given object is not an instanceof expectedClassType.static void
assertNotSerializable
(Object actualObject) static void
assertObjectNotNull
(String objectName, Object actualObject) static void
assertPositive
(int value) Asserts that a value is positive.static void
static void
static void
assertPostSerializedIdentity
(Object object) static void
assertSerializedForm
(long expectedSerialVersionUID, String expectedBase64Form, Object actualObject) static void
assertSerializedForm
(String expectedBase64Form, Object actualObject) static <K,
V> void assertSetMultimapsEqual
(String multimapName, SetMultimap<K, V> expectedSetMultimap, SetMultimap<K, V> actualSetMultimap) static <K,
V> void assertSetMultimapsEqual
(SetMultimap<K, V> expectedSetMultimap, SetMultimap<K, V> actualSetMultimap) static void
assertSetsEqual
(String setName, Set<?> expectedSet, Set<?> actualSet) static void
assertSetsEqual
(Set<?> expectedSet, Set<?> actualSet) static void
assertShallowClone
(Cloneable object) Deprecated.since 8.2.0 as will not work with Java 9static void
assertShallowClone
(String itemName, Cloneable object) Deprecated.since 8.2.0 as will not work with Java 9static void
assertSize
(int expectedSize, Iterable<?> actualIterable) Assert the size of the givenIterable
.static void
assertSize
(int expectedSize, Object[] actualArray) Assert the size of the given array.static void
assertSize
(int expectedSize, Map<?, ?> actualMap) Assert the size of the givenMap
.static void
assertSize
(int expectedSize, MutableMapIterable<?, ?> mutableMapIterable) Assert the size of the givenMutableMapIterable
.static void
assertSize
(int expectedSize, Multimap<?, ?> actualMultimap) Assert the size of the givenMultimap
.static void
assertSize
(int expectedSize, PrimitiveIterable primitiveIterable) Assert the size of the givenPrimitiveIterable
.static void
assertSize
(int expectedSize, ImmutableSet<?> actualImmutableSet) Assert the size of the givenImmutableSet
.static void
assertSize
(String iterableName, int expectedSize, Iterable<?> actualIterable) Assert the size of the givenIterable
.static void
assertSize
(String arrayName, int expectedSize, Object[] actualArray) Assert the size of the given array.static void
assertSize
(String mapName, int expectedSize, Map<?, ?> actualMap) Assert the size of the givenMap
.static void
assertSize
(String mapName, int expectedSize, MutableMapIterable<?, ?> mutableMapIterable) Assert the size of the givenMutableMapIterable
.static void
assertSize
(String multimapName, int expectedSize, Multimap<?, ?> actualMultimap) Assert the size of the givenMultimap
.static void
assertSize
(String primitiveIterableName, int expectedSize, PrimitiveIterable actualPrimitiveIterable) Assert the size of the givenPrimitiveIterable
.static void
assertSize
(String immutableSetName, int expectedSize, ImmutableSet<?> actualImmutableSet) Assert the size of the givenImmutableSet
.static <K,
V> void assertSortedBagMultimapsEqual
(String multimapName, SortedBagMultimap<K, V> expectedSortedBagMultimap, SortedBagMultimap<K, V> actualSortedBagMultimap) static <K,
V> void assertSortedBagMultimapsEqual
(SortedBagMultimap<K, V> expectedSortedBagMultimap, SortedBagMultimap<K, V> actualSortedBagMultimap) static void
assertSortedBagsEqual
(String bagName, SortedBag<?> expectedBag, SortedBag<?> actualBag) static void
assertSortedBagsEqual
(SortedBag<?> expectedBag, SortedBag<?> actualBag) static void
assertSortedMapsEqual
(String mapName, SortedMapIterable<?, ?> expectedMap, SortedMapIterable<?, ?> actualMap) static void
assertSortedMapsEqual
(SortedMapIterable<?, ?> expectedMap, SortedMapIterable<?, ?> actualMap) static <K,
V> void assertSortedSetMultimapsEqual
(String multimapName, SortedSetMultimap<K, V> expectedSortedSetMultimap, SortedSetMultimap<K, V> actualSortedSetMultimap) static <K,
V> void assertSortedSetMultimapsEqual
(SortedSetMultimap<K, V> expectedSortedSetMultimap, SortedSetMultimap<K, V> actualSortedSetMultimap) static void
assertSortedSetsEqual
(String setName, SortedSet<?> expectedSet, SortedSet<?> actualSet) static void
assertSortedSetsEqual
(SortedSet<?> expectedSet, SortedSet<?> actualSet) static <T> void
assertStartsWith
(String listName, List<T> list, T... items) static <T> void
assertStartsWith
(List<T> list, T... items) static <T> void
assertStartsWith
(T[] array, T... items) static void
assertThrows
(Class<? extends Exception> expectedExceptionClass, Callable<?> code) static void
assertThrowsWithCause
(Class<? extends Exception> expectedExceptionClass, Class<? extends Throwable> expectedCauseClass, Runnable code) Runs theRunnable
code
and asserts that it throws anException
of the typeexpectedExceptionClass
, which contains a cause of type expectedCauseClass.static void
assertThrowsWithCause
(Class<? extends Exception> expectedExceptionClass, Class<? extends Throwable> expectedCauseClass, Callable<?> code) Runs theCallable
code
and asserts that it throws anException
of the typeexpectedExceptionClass
, which contains a cause of type expectedCauseClass.static void
assertZero
(int value) Asserts that a value is positive.static void
denyContainsAny
(String collectionName, Collection<?> actualCollection, Object... items) static void
denyContainsAny
(Collection<?> actualCollection, Object... items) static void
denyContainsKey
(Object unexpectedKey, Map<?, ?> actualMap) Deny that the givenMap
contains an entry with the given key.static void
denyContainsKey
(String mapName, Object unexpectedKey, Map<?, ?> actualMap) Deny that the givenMap
contains an entry with the given key.static void
static void
Mangles the stack trace ofAssertionError
so that it looks like it's been thrown from the line that called to a custom assertion.static void
throwMangledException
(AssertionError e, int framesToPop) Mangles the stack trace ofAssertionError
so that it looks like it's been thrown from the line that called to a custom assertion.Methods inherited from class org.junit.Assert
assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertArrayEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotEquals, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertThat, assertThat, assertThrows, assertThrows, assertTrue, assertTrue, fail, fail
-
Method Details
-
throwMangledException
Mangles the stack trace ofAssertionError
so that it looks like it's been thrown from the line that called to a custom assertion.This method behaves identically to
throwMangledException(AssertionError, int)
and is provided for convenience for assert methods that only want to pop two stack frames. The only time that you would want to call the otherthrowMangledException(AssertionError, int)
method is if you have a custom assert that calls another custom assert i.e. the source line calling the custom asserts is more than two stack frames away- Parameters:
e
- The exception to mangle.- See Also:
-
throwMangledException
Mangles the stack trace ofAssertionError
so that it looks like it's been thrown from the line that called to a custom assertion.This is useful for when you are in a debugging session, and you want to go to the source of the problem in the test case quickly. The regular use case for this would be something along the lines of:
public class TestFoo extends junit.framework.TestCase { public void testFoo() throws Exception { Foo foo = new Foo(); ... assertFoo(foo); } // Custom assert private static void assertFoo(Foo foo) { try { assertEquals(...); ... assertSame(...); } catch (AssertionFailedException e) { AssertUtils.throwMangledException(e, 2); } } }
Without the
try ... catch
block around lines 11-13 the stack trace following a test failure would look a little like:java.lang.AssertionError: ... at TestFoo.assertFoo(TestFoo.java:11) at TestFoo.testFoo(TestFoo.java:5) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) ...
Note that the source of the error isn't readily apparent as the first line in the stack trace is the code within the custom assert. If we were debugging the failure we would be more interested in the second line of the stack trace which shows us where in our tests the assert failed.
With the
try ... catch
block around lines 11-13 the stack trace would look like the following:java.lang.AssertionError: ... at TestFoo.testFoo(TestFoo.java:5) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) ...
Here the source of the error is more visible as we can instantly see that the testFoo test is failing at line 5.
- Parameters:
e
- The exception to mangle.framesToPop
- The number of frames to remove from the stack trace.- Throws:
AssertionError
- that was given as an argument with its stack trace mangled.
-
fail
-
assertEmpty
Assert that the givenIterable
is empty. -
assertEmpty
Assert that the givenCollection
is empty. -
assertEmpty
Assert that the givenMutableMapIterable
is empty. -
assertEmpty
public static void assertEmpty(String mutableMapIterableName, MutableMapIterable<?, ?> actualMutableMapIterable) Assert that the givenCollection
is empty. -
assertEmpty
Assert that the givenPrimitiveIterable
is empty. -
assertEmpty
Assert that the givenPrimitiveIterable
is empty. -
assertIterableEmpty
Assert that the givenIterable
is empty. -
assertIterableEmpty
Assert that the givenIterable
is empty. -
assertInstanceOf
Assert that the given object is an instanceof expectedClassType. -
assertInstanceOf
public static void assertInstanceOf(String objectName, Class<?> expectedClassType, Object actualObject) Assert that the given object is an instanceof expectedClassType. -
assertNotInstanceOf
Assert that the given object is not an instanceof expectedClassType. -
assertNotInstanceOf
public static void assertNotInstanceOf(String objectName, Class<?> expectedClassType, Object actualObject) Assert that the given object is not an instanceof expectedClassType. -
assertEmpty
Assert that the givenMap
is empty. -
assertEmpty
Assert that the givenMultimap
is empty. -
assertEmpty
Assert that the givenMultimap
is empty. -
assertEmpty
Assert that the givenMap
is empty. -
assertNotEmpty
Assert that the givenIterable
is not empty. -
assertNotEmpty
Assert that the givenIterable
is not empty. -
assertNotEmpty
Assert that the givenMutableMapIterable
is not empty. -
assertNotEmpty
public static void assertNotEmpty(String mutableMapIterableName, MutableMapIterable<?, ?> actualMutableMapIterable) Assert that the givenMutableMapIterable
is not empty. -
assertNotEmpty
Assert that the givenPrimitiveIterable
is not empty. -
assertNotEmpty
Assert that the givenPrimitiveIterable
is not empty. -
assertIterableNotEmpty
Assert that the givenIterable
is not empty. -
assertIterableNotEmpty
Assert that the givenIterable
is not empty. -
assertNotEmpty
Assert that the givenMap
is not empty. -
assertNotEmpty
Assert that the givenMap
is not empty. -
assertNotEmpty
Assert that the givenMultimap
is not empty. -
assertNotEmpty
Assert that the givenMultimap
is not empty. -
assertNotEmpty
-
assertNotEmpty
public static <T> void assertNotEmpty(T[] items) -
assertSize
Assert the size of the given array. -
assertSize
Assert the size of the given array. -
assertSize
Assert the size of the givenIterable
. -
assertSize
Assert the size of the givenIterable
. -
assertSize
Assert the size of the givenPrimitiveIterable
. -
assertSize
public static void assertSize(String primitiveIterableName, int expectedSize, PrimitiveIterable actualPrimitiveIterable) Assert the size of the givenPrimitiveIterable
. -
assertIterableSize
Assert the size of the givenIterable
. -
assertIterableSize
public static void assertIterableSize(String iterableName, int expectedSize, Iterable<?> actualIterable) Assert the size of the givenIterable
. -
assertSize
Assert the size of the givenMap
. -
assertSize
Assert the size of the givenMap
. -
assertSize
Assert the size of the givenMultimap
. -
assertSize
Assert the size of the givenMultimap
. -
assertSize
Assert the size of the givenMutableMapIterable
. -
assertSize
public static void assertSize(String mapName, int expectedSize, MutableMapIterable<?, ?> mutableMapIterable) Assert the size of the givenMutableMapIterable
. -
assertSize
Assert the size of the givenImmutableSet
. -
assertSize
public static void assertSize(String immutableSetName, int expectedSize, ImmutableSet<?> actualImmutableSet) Assert the size of the givenImmutableSet
. -
assertContains
Assert that the givenstringToFind
is contained within thestringToSearch
. -
assertNotContains
Assert that the givenunexpectedString
is not contained within thestringToSearch
. -
assertContains
Assert that the givenstringToFind
is contained within thestringToSearch
. -
assertNotContains
public static void assertNotContains(String stringName, String unexpectedString, String stringToSearch) Assert that the givenunexpectedString
is not contained within thestringToSearch
. -
assertCount
-
assertAllSatisfy
-
assertAllSatisfy
-
assertAllSatisfy
-
assertAnySatisfy
-
assertAnySatisfy
-
assertAnySatisfy
-
assertNoneSatisfy
-
assertNoneSatisfy
-
assertNoneSatisfy
-
assertContainsAllKeyValues
Assert that the givenMap
contains all the given keys and values. -
assertContainsAllKeyValues
public static void assertContainsAllKeyValues(String mapName, Map<?, ?> actualMap, Object... expectedKeyValues) Assert that the givenMap
contains all the given keys and values. -
assertContainsAllKeyValues
Assert that the givenMapIterable
contains all the given keys and values. -
assertContainsAllKeyValues
public static void assertContainsAllKeyValues(String mapIterableName, MapIterable<?, ?> mapIterable, Object... expectedKeyValues) Assert that the givenMapIterable
contains all the given keys and values. -
assertContainsAllKeyValues
public static void assertContainsAllKeyValues(MutableMapIterable<?, ?> mutableMapIterable, Object... keyValues) Assert that the givenMutableMapIterable
contains all the given keys and values. -
assertContainsAllKeyValues
public static void assertContainsAllKeyValues(String mutableMapIterableName, MutableMapIterable<?, ?> mutableMapIterable, Object... expectedKeyValues) Assert that the givenMutableMapIterable
contains all the given keys and values. -
assertContainsAllKeyValues
public static void assertContainsAllKeyValues(ImmutableMapIterable<?, ?> immutableMapIterable, Object... keyValues) Assert that the givenImmutableMapIterable
contains all the given keys and values. -
assertContainsAllKeyValues
public static void assertContainsAllKeyValues(String immutableMapIterableName, ImmutableMapIterable<?, ?> immutableMapIterable, Object... expectedKeyValues) Assert that the givenImmutableMapIterable
contains all the given keys and values. -
denyContainsAny
-
assertContainsNone
-
assertContains
Assert that the givenCollection
contains the given item. -
assertContains
public static void assertContains(String collectionName, Object expectedItem, Collection<?> actualCollection) Assert that the givenCollection
contains the given item. -
assertContains
public static void assertContains(Object expectedItem, ImmutableCollection<?> actualImmutableCollection) Assert that the givenImmutableCollection
contains the given item. -
assertContains
public static void assertContains(String immutableCollectionName, Object expectedItem, ImmutableCollection<?> actualImmutableCollection) Assert that the givenImmutableCollection
contains the given item. -
assertContainsAll
-
assertContainsAll
-
assertListsEqual
-
assertListsEqual
-
assertSetsEqual
-
assertSetsEqual
-
assertSortedSetsEqual
-
assertSortedSetsEqual
-
assertSortedBagsEqual
-
assertSortedBagsEqual
-
assertSortedMapsEqual
public static void assertSortedMapsEqual(SortedMapIterable<?, ?> expectedMap, SortedMapIterable<?, ?> actualMap) -
assertSortedMapsEqual
public static void assertSortedMapsEqual(String mapName, SortedMapIterable<?, ?> expectedMap, SortedMapIterable<?, ?> actualMap) -
assertIterablesEqual
-
assertIterablesEqual
-
assertMapsEqual
-
assertMapsEqual
-
assertBagsEqual
-
assertBagsEqual
-
assertListMultimapsEqual
public static <K,V> void assertListMultimapsEqual(ListMultimap<K, V> expectedListMultimap, ListMultimap<K, V> actualListMultimap) -
assertListMultimapsEqual
public static <K,V> void assertListMultimapsEqual(String multimapName, ListMultimap<K, V> expectedListMultimap, ListMultimap<K, V> actualListMultimap) -
assertSetMultimapsEqual
public static <K,V> void assertSetMultimapsEqual(SetMultimap<K, V> expectedSetMultimap, SetMultimap<K, V> actualSetMultimap) -
assertSetMultimapsEqual
public static <K,V> void assertSetMultimapsEqual(String multimapName, SetMultimap<K, V> expectedSetMultimap, SetMultimap<K, V> actualSetMultimap) -
assertBagMultimapsEqual
public static <K,V> void assertBagMultimapsEqual(BagMultimap<K, V> expectedBagMultimap, BagMultimap<K, V> actualBagMultimap) -
assertBagMultimapsEqual
public static <K,V> void assertBagMultimapsEqual(String multimapName, BagMultimap<K, V> expectedBagMultimap, BagMultimap<K, V> actualBagMultimap) -
assertSortedSetMultimapsEqual
public static <K,V> void assertSortedSetMultimapsEqual(SortedSetMultimap<K, V> expectedSortedSetMultimap, SortedSetMultimap<K, V> actualSortedSetMultimap) -
assertSortedSetMultimapsEqual
public static <K,V> void assertSortedSetMultimapsEqual(String multimapName, SortedSetMultimap<K, V> expectedSortedSetMultimap, SortedSetMultimap<K, V> actualSortedSetMultimap) -
assertSortedBagMultimapsEqual
public static <K,V> void assertSortedBagMultimapsEqual(SortedBagMultimap<K, V> expectedSortedBagMultimap, SortedBagMultimap<K, V> actualSortedBagMultimap) -
assertSortedBagMultimapsEqual
public static <K,V> void assertSortedBagMultimapsEqual(String multimapName, SortedBagMultimap<K, V> expectedSortedBagMultimap, SortedBagMultimap<K, V> actualSortedBagMultimap) -
assertContainsEntry
public static <K,V> void assertContainsEntry(K expectedKey, V expectedValue, Multimap<K, V> actualMultimap) Assert that the givenMultimap
contains an entry with the given key and value. -
assertContainsEntry
public static <K,V> void assertContainsEntry(String multimapName, K expectedKey, V expectedValue, Multimap<K, V> actualMultimap) Assert that the givenMultimap
contains an entry with the given key and value. -
assertContainsAllEntries
Assert the givenMultimap
contains all the given keys and values. -
assertContainsAllEntries
public static void assertContainsAllEntries(String multimapName, Multimap<?, ?> actualMultimap, Object... expectedKeyValues) Assert the givenMultimap
contains all the given keys and values. -
denyContainsAny
public static void denyContainsAny(String collectionName, Collection<?> actualCollection, Object... items) -
assertContainsKey
Assert that the givenMap
contains an entry with the given key. -
assertContainsKey
Assert that the givenMap
contains an entry with the given key. -
assertContainsKey
Assert that the givenMapIterable
contains an entry with the given key. -
assertContainsKey
public static void assertContainsKey(String mapIterableName, Object expectedKey, MapIterable<?, ?> mapIterable) Assert that the givenMapIterable
contains an entry with the given key. -
assertContainsKey
public static void assertContainsKey(Object expectedKey, MutableMapIterable<?, ?> mutableMapIterable) Assert that the givenMutableMapIterable
contains an entry with the given key. -
assertContainsKey
public static void assertContainsKey(String mutableMapIterableName, Object expectedKey, MutableMapIterable<?, ?> mutableMapIterable) Assert that the givenMutableMapIterable
contains an entry with the given key. -
assertContainsKey
public static void assertContainsKey(Object expectedKey, ImmutableMapIterable<?, ?> immutableMapIterable) Assert that the givenImmutableMapIterable
contains an entry with the given key. -
assertContainsKey
public static void assertContainsKey(String immutableMapIterableName, Object expectedKey, ImmutableMapIterable<?, ?> immutableMapIterable) Assert that the givenImmutableMapIterable
contains an entry with the given key. -
denyContainsKey
Deny that the givenMap
contains an entry with the given key. -
denyContainsKey
Deny that the givenMap
contains an entry with the given key. -
assertContainsKeyValue
public static void assertContainsKeyValue(Object expectedKey, Object expectedValue, Map<?, ?> actualMap) Assert that the givenMap
contains an entry with the given key and value. -
assertContainsKeyValue
public static void assertContainsKeyValue(String mapName, Object expectedKey, Object expectedValue, Map<?, ?> actualMap) Assert that the givenMap
contains an entry with the given key and value. -
assertContainsKeyValue
public static void assertContainsKeyValue(Object expectedKey, Object expectedValue, MapIterable<?, ?> mapIterable) Assert that the givenMapIterable
contains an entry with the given key and value. -
assertContainsKeyValue
public static void assertContainsKeyValue(String mapIterableName, Object expectedKey, Object expectedValue, MapIterable<?, ?> mapIterable) Assert that the givenMapIterable
contains an entry with the given key and value. -
assertContainsKeyValue
public static void assertContainsKeyValue(Object expectedKey, Object expectedValue, MutableMapIterable<?, ?> mapIterable) Assert that the givenMutableMapIterable
contains an entry with the given key and value. -
assertContainsKeyValue
public static void assertContainsKeyValue(String mapIterableName, Object expectedKey, Object expectedValue, MutableMapIterable<?, ?> mutableMapIterable) Assert that the givenMutableMapIterable
contains an entry with the given key and value. -
assertContainsKeyValue
public static void assertContainsKeyValue(Object expectedKey, Object expectedValue, ImmutableMapIterable<?, ?> mapIterable) Assert that the givenImmutableMapIterable
contains an entry with the given key and value. -
assertContainsKeyValue
public static void assertContainsKeyValue(String mapIterableName, Object expectedKey, Object expectedValue, ImmutableMapIterable<?, ?> immutableMapIterable) Assert that the givenImmutableMapIterable
contains an entry with the given key and value. -
assertNotContains
Assert that the givenCollection
does not contain the given item. -
assertNotContains
public static void assertNotContains(String collectionName, Object unexpectedItem, Collection<?> actualCollection) Assert that the givenCollection
does not contain the given item. -
assertNotContains
Assert that the givenIterable
does not contain the given item. -
assertNotContains
public static void assertNotContains(String collectionName, Object unexpectedItem, Iterable<?> iterable) Assert that the givenIterable
does not contain the given item. -
assertNotContainsKey
Assert that the givenCollection
does not contain the given item. -
assertNotContainsKey
Assert that the givenCollection
does not contain the given item. -
assertBefore
Assert that the formerItem appears before the latterItem in the givenCollection
. Both the formerItem and the latterItem must appear in the collection, or this assert will fail. -
assertBefore
public static void assertBefore(String listName, Object formerItem, Object latterItem, List<?> actualList) Assert that the formerItem appears before the latterItem in the givenCollection
.assertContains(String, Object, Collection)
will be called for both the formerItem and the latterItem, prior to the "before" assertion. -
assertObjectNotNull
-
assertItemAtIndex
-
assertItemAtIndex
Assert that the givenitem
is at theindex
in the givenarray
. -
assertStartsWith
public static <T> void assertStartsWith(T[] array, T... items) -
assertStartsWith
-
assertStartsWith
-
assertEndsWith
-
assertEndsWith
public static <T> void assertEndsWith(T[] array, T... items) -
assertItemAtIndex
-
assertItemAtIndex
-
assertPostSerializedEqualsAndHashCode
-
assertPostSerializedEqualsHashCodeAndToString
-
assertPostSerializedIdentity
-
assertSerializedForm
-
assertSerializedForm
-
assertDeserializedForm
-
assertNotSerializable
-
assertEqualsAndHashCode
Assert thatobjectA
andobjectB
are equal via theObject.equals(Object)
method, and that they both return the sameObject.hashCode()
. -
assertNegative
public static void assertNegative(int value) Asserts that a value is negative. -
assertPositive
public static void assertPositive(int value) Asserts that a value is positive. -
assertZero
public static void assertZero(int value) Asserts that a value is positive. -
assertEqualsAndHashCode
Assert thatobjectA
andobjectB
are equal (via theObject.equals(Object)
method, and that they both return the sameObject.hashCode()
. -
assertShallowClone
Deprecated.since 8.2.0 as will not work with Java 9 -
assertShallowClone
Deprecated.since 8.2.0 as will not work with Java 9 -
assertClassNonInstantiable
-
assertError
-
assertThrows
public static void assertThrows(Class<? extends Exception> expectedExceptionClass, Callable<?> code) Runs theCallable
code
and asserts that it throws anException
of the typeexpectedExceptionClass
.Callable
is most appropriate when a checked exception will be thrown. If a subclass ofRuntimeException
will be thrown, the formAssert.assertThrows(Class, org.junit.function.ThrowingRunnable)
may be more convenient.e.g.
Verify.assertThrows(StringIndexOutOfBoundsException.class, new Callable<String>() { public String call() throws Exception { return "Craig".substring(42, 3); } });
-
assertThrowsWithCause
public static void assertThrowsWithCause(Class<? extends Exception> expectedExceptionClass, Class<? extends Throwable> expectedCauseClass, Callable<?> code) Runs theCallable
code
and asserts that it throws anException
of the typeexpectedExceptionClass
, which contains a cause of type expectedCauseClass.Callable
is most appropriate when a checked exception will be thrown. If a subclass ofRuntimeException
will be thrown, the formassertThrowsWithCause(Class, Class, Runnable)
may be more convenient.e.g.
Verify.assertThrowsWithCause(RuntimeException.class, IOException.class, new Callable<Void>() { public Void call() throws Exception { try { new File("").createNewFile(); } catch (final IOException e) { throw new RuntimeException("Uh oh!", e); } return null; } });
-
assertThrowsWithCause
public static void assertThrowsWithCause(Class<? extends Exception> expectedExceptionClass, Class<? extends Throwable> expectedCauseClass, Runnable code) Runs theRunnable
code
and asserts that it throws anException
of the typeexpectedExceptionClass
, which contains a cause of type expectedCauseClass.Runnable
is most appropriate when a subclass ofRuntimeException
will be thrown. If a checked exception will be thrown, the formassertThrowsWithCause(Class, Class, Callable)
may be more convenient.e.g.
Verify.assertThrowsWithCause(RuntimeException.class, StringIndexOutOfBoundsException.class, new Runnable() { public void run() { try { LOGGER.info("Craig".substring(42, 3)); } catch (final StringIndexOutOfBoundsException e) { throw new RuntimeException("Uh oh!", e); } } });
-