Class Verify
public final class Verify extends Assert
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 Type Method Description static <T> voidassertAllSatisfy(Iterable<T> iterable, Predicate<? super T> predicate)static <T> voidassertAllSatisfy(String message, Iterable<T> iterable, Predicate<? super T> predicate)static <K, V> voidassertAllSatisfy(Map<K,V> map, Predicate<? super V> predicate)static <T> voidassertAnySatisfy(Iterable<T> iterable, Predicate<? super T> predicate)static <T> voidassertAnySatisfy(String message, Iterable<T> iterable, Predicate<? super T> predicate)static <K, V> voidassertAnySatisfy(Map<K,V> map, Predicate<? super V> predicate)static <K, V> voidassertBagMultimapsEqual(String multimapName, BagMultimap<K,V> expectedBagMultimap, BagMultimap<K,V> actualBagMultimap)static <K, V> voidassertBagMultimapsEqual(BagMultimap<K,V> expectedBagMultimap, BagMultimap<K,V> actualBagMultimap)static voidassertBagsEqual(String bagName, Bag<?> expectedBag, Bag<?> actualBag)static voidassertBagsEqual(Bag<?> expectedBag, Bag<?> actualBag)static voidassertBefore(Object formerItem, Object latterItem, List<?> actualList)Assert that the formerItem appears before the latterItem in the givenCollection.static voidassertBefore(String listName, Object formerItem, Object latterItem, List<?> actualList)Assert that the formerItem appears before the latterItem in the givenCollection.static <T> voidassertClassNonInstantiable(Class<T> aClass)static voidassertContains(Object expectedItem, Collection<?> actualCollection)Assert that the givenCollectioncontains the given item.static voidassertContains(Object expectedItem, ImmutableCollection<?> actualImmutableCollection)Assert that the givenImmutableCollectioncontains the given item.static voidassertContains(String collectionName, Object expectedItem, Collection<?> actualCollection)Assert that the givenCollectioncontains the given item.static voidassertContains(String immutableCollectionName, Object expectedItem, ImmutableCollection<?> actualImmutableCollection)Assert that the givenImmutableCollectioncontains the given item.static voidassertContains(String stringToFind, String stringToSearch)Assert that the givenstringToFindis contained within thestringToSearch.static voidassertContains(String stringName, String stringToFind, String stringToSearch)Assert that the givenstringToFindis contained within thestringToSearch.static voidassertContainsAll(Iterable<?> iterable, Object... items)static voidassertContainsAll(String collectionName, Iterable<?> iterable, Object... items)static voidassertContainsAllEntries(String multimapName, Multimap<?,?> actualMultimap, Object... expectedKeyValues)Assert the givenMultimapcontains all of the given keys and values.static voidassertContainsAllEntries(Multimap<?,?> actualMultimap, Object... keyValues)Assert the givenMultimapcontains all of the given keys and values.static voidassertContainsAllKeyValues(String mapName, Map<?,?> actualMap, Object... expectedKeyValues)Assert that the givenMapcontains all of the given keys and values.static voidassertContainsAllKeyValues(String immutableMapIterableName, ImmutableMapIterable<?,?> immutableMapIterable, Object... expectedKeyValues)Assert that the givenImmutableMapIterablecontains all of the given keys and values.static voidassertContainsAllKeyValues(String mapIterableName, MapIterable<?,?> mapIterable, Object... expectedKeyValues)Assert that the givenMapIterablecontains all of the given keys and values.static voidassertContainsAllKeyValues(String mutableMapIterableName, MutableMapIterable<?,?> mutableMapIterable, Object... expectedKeyValues)Assert that the givenMutableMapIterablecontains all of the given keys and values.static voidassertContainsAllKeyValues(Map<?,?> actualMap, Object... keyValues)Assert that the givenMapcontains all of the given keys and values.static voidassertContainsAllKeyValues(ImmutableMapIterable<?,?> immutableMapIterable, Object... keyValues)Assert that the givenImmutableMapIterablecontains all of the given keys and values.static voidassertContainsAllKeyValues(MapIterable<?,?> mapIterable, Object... keyValues)Assert that the givenMapIterablecontains all of the given keys and values.static voidassertContainsAllKeyValues(MutableMapIterable<?,?> mutableMapIterable, Object... keyValues)Assert that the givenMutableMapIterablecontains all of the given keys and values.static <K, V> voidassertContainsEntry(String multimapName, K expectedKey, V expectedValue, Multimap<K,V> actualMultimap)Assert that the givenMultimapcontains an entry with the given key and value.static <K, V> voidassertContainsEntry(K expectedKey, V expectedValue, Multimap<K,V> actualMultimap)Assert that the givenMultimapcontains an entry with the given key and value.static voidassertContainsKey(Object expectedKey, Map<?,?> actualMap)Assert that the givenMapcontains an entry with the given key.static voidassertContainsKey(Object expectedKey, ImmutableMapIterable<?,?> immutableMapIterable)Assert that the givenImmutableMapIterablecontains an entry with the given key.static voidassertContainsKey(Object expectedKey, MapIterable<?,?> mapIterable)Assert that the givenMapIterablecontains an entry with the given key.static voidassertContainsKey(Object expectedKey, MutableMapIterable<?,?> mutableMapIterable)Assert that the givenMutableMapIterablecontains an entry with the given key.static voidassertContainsKey(String mapName, Object expectedKey, Map<?,?> actualMap)Assert that the givenMapcontains an entry with the given key.static voidassertContainsKey(String immutableMapIterableName, Object expectedKey, ImmutableMapIterable<?,?> immutableMapIterable)Assert that the givenImmutableMapIterablecontains an entry with the given key.static voidassertContainsKey(String mapIterableName, Object expectedKey, MapIterable<?,?> mapIterable)Assert that the givenMapIterablecontains an entry with the given key.static voidassertContainsKey(String mutableMapIterableName, Object expectedKey, MutableMapIterable<?,?> mutableMapIterable)Assert that the givenMutableMapIterablecontains an entry with the given key.static voidassertContainsKeyValue(Object expectedKey, Object expectedValue, Map<?,?> actualMap)Assert that the givenMapcontains an entry with the given key and value.static voidassertContainsKeyValue(Object expectedKey, Object expectedValue, ImmutableMapIterable<?,?> mapIterable)Assert that the givenImmutableMapIterablecontains an entry with the given key and value.static voidassertContainsKeyValue(Object expectedKey, Object expectedValue, MapIterable<?,?> mapIterable)Assert that the givenMapIterablecontains an entry with the given key and value.static voidassertContainsKeyValue(Object expectedKey, Object expectedValue, MutableMapIterable<?,?> mapIterable)Assert that the givenMutableMapIterablecontains an entry with the given key and value.static voidassertContainsKeyValue(String mapName, Object expectedKey, Object expectedValue, Map<?,?> actualMap)Assert that the givenMapcontains an entry with the given key and value.static voidassertContainsKeyValue(String mapIterableName, Object expectedKey, Object expectedValue, ImmutableMapIterable<?,?> immutableMapIterable)Assert that the givenImmutableMapIterablecontains an entry with the given key and value.static voidassertContainsKeyValue(String mapIterableName, Object expectedKey, Object expectedValue, MapIterable<?,?> mapIterable)Assert that the givenMapIterablecontains an entry with the given key and value.static voidassertContainsKeyValue(String mapIterableName, Object expectedKey, Object expectedValue, MutableMapIterable<?,?> mutableMapIterable)Assert that the givenMutableMapIterablecontains an entry with the given key and value.static voidassertContainsNone(Collection<?> actualCollection, Object... items)static <T> voidassertCount(int expectedCount, Iterable<T> iterable, Predicate<? super T> predicate)static voidassertDeserializedForm(String expectedBase64Form, Object actualObject)static voidassertEmpty(Iterable<?> actualIterable)Assert that the givenIterableis empty.static voidassertEmpty(String iterableName, Iterable<?> actualIterable)Assert that the givenCollectionis empty.static voidassertEmpty(String mapName, Map<?,?> actualMap)Assert that the givenMapis empty.static voidassertEmpty(String mutableMapIterableName, MutableMapIterable<?,?> actualMutableMapIterable)Assert that the givenCollectionis empty.static voidassertEmpty(String multimapName, Multimap<?,?> actualMultimap)Assert that the givenMultimapis empty.static voidassertEmpty(String iterableName, PrimitiveIterable primitiveIterable)Assert that the givenPrimitiveIterableis empty.static voidassertEmpty(Map<?,?> actualMap)Assert that the givenMapis empty.static voidassertEmpty(MutableMapIterable<?,?> actualMutableMapIterable)Assert that the givenMutableMapIterableis empty.static voidassertEmpty(Multimap<?,?> actualMultimap)Assert that the givenMultimapis empty.static voidassertEmpty(PrimitiveIterable primitiveIterable)Assert that the givenPrimitiveIterableis empty.static <T> voidassertEndsWith(List<T> list, T... items)static <T> voidassertEndsWith(T[] array, T... items)static voidassertEqualsAndHashCode(Object objectA, Object objectB)Assert thatobjectAandobjectBare equal (via theObject.equals(Object)method, and that they both return the sameObject.hashCode().static voidassertEqualsAndHashCode(String itemNames, Object objectA, Object objectB)Assert thatobjectAandobjectBare equal (via theObject.equals(Object)method, and that they both return the sameObject.hashCode().static voidassertError(Class<? extends Error> expectedErrorClass, Runnable code)static voidassertInstanceOf(Class<?> expectedClassType, Object actualObject)Assert that the given object is an instanceof expectedClassType.static voidassertInstanceOf(String objectName, Class<?> expectedClassType, Object actualObject)Assert that the given object is an instanceof expectedClassType.static voidassertItemAtIndex(Object expectedItem, int index, Object[] array)Assert that the givenitemis at theindexin the givenarray.static voidassertItemAtIndex(Object expectedItem, int index, List<?> list)static voidassertItemAtIndex(String arrayName, Object expectedItem, int index, Object[] array)static voidassertItemAtIndex(String listName, Object expectedItem, int index, List<?> list)static voidassertIterableEmpty(Iterable<?> iterable)Assert that the givenIterableis empty.static voidassertIterableEmpty(String iterableName, Iterable<?> iterable)Assert that the givenIterableis empty.static voidassertIterableNotEmpty(Iterable<?> iterable)Assert that the givenIterableis not empty.static voidassertIterableNotEmpty(String iterableName, Iterable<?> iterable)Assert that the givenIterableis not empty.static voidassertIterablesEqual(Iterable<?> expectedIterable, Iterable<?> actualIterable)static voidassertIterablesEqual(String iterableName, Iterable<?> expectedIterable, Iterable<?> actualIterable)static voidassertIterableSize(int expectedSize, Iterable<?> actualIterable)Assert the size of the givenIterable.static voidassertIterableSize(String iterableName, int expectedSize, Iterable<?> actualIterable)Assert the size of the givenIterable.static <K, V> voidassertListMultimapsEqual(String multimapName, ListMultimap<K,V> expectedListMultimap, ListMultimap<K,V> actualListMultimap)static <K, V> voidassertListMultimapsEqual(ListMultimap<K,V> expectedListMultimap, ListMultimap<K,V> actualListMultimap)static voidassertListsEqual(String listName, List<?> expectedList, List<?> actualList)static voidassertListsEqual(List<?> expectedList, List<?> actualList)static voidassertMapsEqual(String mapName, Map<?,?> expectedMap, Map<?,?> actualMap)static voidassertMapsEqual(Map<?,?> expectedMap, Map<?,?> actualMap)static voidassertNegative(int value)Asserts that a value is negative.static <T> voidassertNoneSatisfy(Iterable<T> iterable, Predicate<? super T> predicate)static <T> voidassertNoneSatisfy(String message, Iterable<T> iterable, Predicate<? super T> predicate)static <K, V> voidassertNoneSatisfy(Map<K,V> map, Predicate<? super V> predicate)static voidassertNotContains(Object unexpectedItem, Iterable<?> iterable)Assert that the givenIterabledoes not contain the given item.static voidassertNotContains(Object unexpectedItem, Collection<?> actualCollection)Assert that the givenCollectiondoes not contain the given item.static voidassertNotContains(String collectionName, Object unexpectedItem, Iterable<?> iterable)Assert that the givenIterabledoes not contain the given item.static voidassertNotContains(String collectionName, Object unexpectedItem, Collection<?> actualCollection)Assert that the givenCollectiondoes not contain the given item.static voidassertNotContains(String unexpectedString, String stringToSearch)Assert that the givenunexpectedStringis not contained within thestringToSearch.static voidassertNotContains(String stringName, String unexpectedString, String stringToSearch)Assert that the givenunexpectedStringis not contained within thestringToSearch.static voidassertNotContainsKey(Object unexpectedKey, Map<?,?> actualMap)Assert that the givenCollectiondoes not contain the given item.static voidassertNotContainsKey(String mapName, Object unexpectedKey, Map<?,?> actualMap)Assert that the givenCollectiondoes not contain the given item.static voidassertNotEmpty(Iterable<?> actualIterable)Assert that the givenIterableis not empty.static voidassertNotEmpty(String iterableName, Iterable<?> actualIterable)Assert that the givenIterableis not empty.static voidassertNotEmpty(String mapName, Map<?,?> actualMap)Assert that the givenMapis not empty.static voidassertNotEmpty(String mutableMapIterableName, MutableMapIterable<?,?> actualMutableMapIterable)Assert that the givenMutableMapIterableis not empty.static voidassertNotEmpty(String multimapName, Multimap<?,?> actualMultimap)Assert that the givenMultimapis not empty.static voidassertNotEmpty(String iterableName, PrimitiveIterable primitiveIterable)Assert that the givenPrimitiveIterableis not empty.static <T> voidassertNotEmpty(String itemsName, T[] items)static voidassertNotEmpty(Map<?,?> actualMap)Assert that the givenMapis not empty.static voidassertNotEmpty(MutableMapIterable<?,?> actualMutableMapIterable)Assert that the givenMutableMapIterableis not empty.static voidassertNotEmpty(Multimap<?,?> actualMultimap)Assert that the givenMultimapis not empty.static voidassertNotEmpty(PrimitiveIterable primitiveIterable)Assert that the givenPrimitiveIterableis not empty.static <T> voidassertNotEmpty(T[] items)static voidassertNotEquals(boolean notExpected, boolean actual)Asserts that two booleans are not equal.static voidassertNotEquals(byte notExpected, byte actual)Asserts that two bytes are not equal.static voidassertNotEquals(char notExpected, char actual)Asserts that two chars are not equal.static voidassertNotEquals(double notExpected, double actual, double delta)Deprecated.in 3.0.static voidassertNotEquals(float expected, float actual, float delta)Asserts that two floats are not equal concerning a delta.static voidassertNotEquals(int notExpected, int actual)Deprecated.in 3.0.static voidassertNotEquals(long notExpected, long actual)Deprecated.in 3.0.static voidassertNotEquals(short notExpected, short actual)Asserts that two shorts are not equal.static voidassertNotEquals(Object item1, Object item2)Deprecated.in 3.0.static voidassertNotEquals(String itemName, boolean notExpected, boolean actual)Asserts that two booleans are not equal.static voidassertNotEquals(String itemName, byte notExpected, byte actual)Asserts that two bytes are not equal.static voidassertNotEquals(String itemName, char notExpected, char actual)Asserts that two chars are not equal.static voidassertNotEquals(String itemName, double notExpected, double actual, double delta)Deprecated.in 3.0.static voidassertNotEquals(String itemName, float notExpected, float actual, float delta)Asserts that two floats are not equal concerning a delta.static voidassertNotEquals(String itemName, int notExpected, int actual)Deprecated.in 3.0.static voidassertNotEquals(String itemName, long notExpected, long actual)Deprecated.in 3.0.static voidassertNotEquals(String itemName, short notExpected, short actual)Asserts that two shorts are not equal.static voidassertNotEquals(String itemsName, Object item1, Object item2)Deprecated.in 3.0.static voidassertNotEquals(String notExpected, String actual)Deprecated.in 3.0.static voidassertNotEquals(String itemName, String notExpected, String actual)Deprecated.in 3.0.static voidassertNotInstanceOf(Class<?> expectedClassType, Object actualObject)Assert that the given object is not an instanceof expectedClassType.static voidassertNotInstanceOf(String objectName, Class<?> expectedClassType, Object actualObject)Assert that the given object is not an instanceof expectedClassType.static voidassertNotSerializable(Object actualObject)static voidassertObjectNotNull(String objectName, Object actualObject)static voidassertPositive(int value)Asserts that a value is positive.static voidassertPostSerializedEqualsAndHashCode(Object object)static voidassertPostSerializedEqualsHashCodeAndToString(Object object)static voidassertPostSerializedIdentity(Object object)static voidassertSerializedForm(long expectedSerialVersionUID, String expectedBase64Form, Object actualObject)static voidassertSerializedForm(String expectedBase64Form, Object actualObject)static <K, V> voidassertSetMultimapsEqual(String multimapName, SetMultimap<K,V> expectedSetMultimap, SetMultimap<K,V> actualSetMultimap)static <K, V> voidassertSetMultimapsEqual(SetMultimap<K,V> expectedSetMultimap, SetMultimap<K,V> actualSetMultimap)static voidassertSetsEqual(String setName, Set<?> expectedSet, Set<?> actualSet)static voidassertSetsEqual(Set<?> expectedSet, Set<?> actualSet)static voidassertShallowClone(Cloneable object)Deprecated.since 8.2.0 as will not work with Java 9static voidassertShallowClone(String itemName, Cloneable object)Deprecated.since 8.2.0 as will not work with Java 9static voidassertSize(int expectedSize, Iterable<?> actualIterable)Assert the size of the givenIterable.static voidassertSize(int expectedSize, Object[] actualArray)Assert the size of the given array.static voidassertSize(int expectedSize, Map<?,?> actualMap)Assert the size of the givenMap.static voidassertSize(int expectedSize, MutableMapIterable<?,?> mutableMapIterable)Assert the size of the givenMutableMapIterable.static voidassertSize(int expectedSize, Multimap<?,?> actualMultimap)Assert the size of the givenMultimap.static voidassertSize(int expectedSize, PrimitiveIterable primitiveIterable)Assert the size of the givenPrimitiveIterable.static voidassertSize(int expectedSize, ImmutableSet<?> actualImmutableSet)Assert the size of the givenImmutableSet.static voidassertSize(String iterableName, int expectedSize, Iterable<?> actualIterable)Assert the size of the givenIterable.static voidassertSize(String arrayName, int expectedSize, Object[] actualArray)Assert the size of the given array.static voidassertSize(String mapName, int expectedSize, Map<?,?> actualMap)Assert the size of the givenMap.static voidassertSize(String mapName, int expectedSize, MutableMapIterable<?,?> mutableMapIterable)Assert the size of the givenMutableMapIterable.static voidassertSize(String multimapName, int expectedSize, Multimap<?,?> actualMultimap)Assert the size of the givenMultimap.static voidassertSize(String primitiveIterableName, int expectedSize, PrimitiveIterable actualPrimitiveIterable)Assert the size of the givenPrimitiveIterable.static voidassertSize(String immutableSetName, int expectedSize, ImmutableSet<?> actualImmutableSet)Assert the size of the givenImmutableSet.static <K, V> voidassertSortedBagMultimapsEqual(String multimapName, SortedBagMultimap<K,V> expectedSortedBagMultimap, SortedBagMultimap<K,V> actualSortedBagMultimap)static <K, V> voidassertSortedBagMultimapsEqual(SortedBagMultimap<K,V> expectedSortedBagMultimap, SortedBagMultimap<K,V> actualSortedBagMultimap)static voidassertSortedBagsEqual(String bagName, SortedBag<?> expectedBag, SortedBag<?> actualBag)static voidassertSortedBagsEqual(SortedBag<?> expectedBag, SortedBag<?> actualBag)static voidassertSortedMapsEqual(String mapName, SortedMapIterable<?,?> expectedMap, SortedMapIterable<?,?> actualMap)static voidassertSortedMapsEqual(SortedMapIterable<?,?> expectedMap, SortedMapIterable<?,?> actualMap)static <K, V> voidassertSortedSetMultimapsEqual(String multimapName, SortedSetMultimap<K,V> expectedSortedSetMultimap, SortedSetMultimap<K,V> actualSortedSetMultimap)static <K, V> voidassertSortedSetMultimapsEqual(SortedSetMultimap<K,V> expectedSortedSetMultimap, SortedSetMultimap<K,V> actualSortedSetMultimap)static voidassertSortedSetsEqual(String setName, SortedSet<?> expectedSet, SortedSet<?> actualSet)static voidassertSortedSetsEqual(SortedSet<?> expectedSet, SortedSet<?> actualSet)static <T> voidassertStartsWith(String listName, List<T> list, T... items)static <T> voidassertStartsWith(List<T> list, T... items)static <T> voidassertStartsWith(T[] array, T... items)static voidassertThrows(Class<? extends Exception> expectedExceptionClass, Runnable code)static voidassertThrows(Class<? extends Exception> expectedExceptionClass, Callable<?> code)static voidassertThrowsWithCause(Class<? extends Exception> expectedExceptionClass, Class<? extends Throwable> expectedCauseClass, Runnable code)Runs theRunnablecodeand asserts that it throws anExceptionof the typeexpectedExceptionClass, which contains a cause of type expectedCauseClass.static voidassertThrowsWithCause(Class<? extends Exception> expectedExceptionClass, Class<? extends Throwable> expectedCauseClass, Callable<?> code)Runs theCallablecodeand asserts that it throws anExceptionof the typeexpectedExceptionClass, which contains a cause of type expectedCauseClass.static voidassertZero(int value)Asserts that a value is positive.static voiddenyContainsAny(String collectionName, Collection<?> actualCollection, Object... items)static voiddenyContainsAny(Collection<?> actualCollection, Object... items)static voiddenyContainsKey(Object unexpectedKey, Map<?,?> actualMap)Deny that the givenMapcontains an entry with the given key.static voiddenyContainsKey(String mapName, Object unexpectedKey, Map<?,?> actualMap)Deny that the givenMapcontains an entry with the given key.static voidfail(String message, Throwable cause)static voidthrowMangledException(AssertionError e)Mangles the stack trace ofAssertionErrorso that it looks like its been thrown from the line that called to a custom assertion.static voidthrowMangledException(AssertionError e, int framesToPop)Mangles the stack trace ofAssertionErrorso that it looks like its 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, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertThat, assertThat, assertTrue, assertTrue, fail, fail
-
Method Details
-
throwMangledException
Mangles the stack trace ofAssertionErrorso that it looks like its 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(AssertionError, int)
-
throwMangledException
Mangles the stack trace ofAssertionErrorso that it looks like its 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 ... catchblock 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 ... catchblock 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
-
assertNotEquals
Deprecated.in 3.0. UseAssert.assertNotEquals(String, Object, Object)in JUnit 4.11 instead.Assert that two items are not the same. If one item is null, the the other must be non-null. -
assertNotEquals
Deprecated.in 3.0. UseAssert.assertNotEquals(Object, Object)in JUnit 4.11 instead.Assert that two items are not the same. If one item is null, the the other must be non-null. -
assertNotEquals
Deprecated.in 3.0. UseAssert.assertNotEquals(String, Object, Object)in JUnit 4.11 instead.Asserts that two Strings are not equal. -
assertNotEquals
Deprecated.in 3.0. UseAssert.assertNotEquals(Object, Object)in JUnit 4.11 instead.Asserts that two Strings are not equal. -
assertNotEquals
@Deprecated public static void assertNotEquals(String itemName, double notExpected, double actual, double delta)Deprecated.in 3.0. UseAssert.assertNotEquals(String, double, double, double)in JUnit 4.11 instead.Asserts that two doubles are not equal concerning a delta. If the expected value is infinity then the delta value is ignored. -
assertNotEquals
Deprecated.in 3.0. UseAssert.assertNotEquals(double, double, double)in JUnit 4.11 instead.Asserts that two doubles are not equal concerning a delta. If the expected value is infinity then the delta value is ignored. -
assertNotEquals
Asserts that two floats are not equal concerning a delta. If the expected value is infinity then the delta value is ignored. -
assertNotEquals
public static void assertNotEquals(float expected, float actual, float delta)Asserts that two floats are not equal concerning a delta. If the expected value is infinity then the delta value is ignored. -
assertNotEquals
Deprecated.in 3.0. UseAssert.assertNotEquals(String, long, long)in JUnit 4.11 instead.Asserts that two longs are not equal. -
assertNotEquals
Deprecated.in 3.0. UseAssert.assertNotEquals(long, long)in JUnit 4.11 instead.Asserts that two longs are not equal. -
assertNotEquals
Asserts that two booleans are not equal. -
assertNotEquals
public static void assertNotEquals(boolean notExpected, boolean actual)Asserts that two booleans are not equal. -
assertNotEquals
Asserts that two bytes are not equal. -
assertNotEquals
public static void assertNotEquals(byte notExpected, byte actual)Asserts that two bytes are not equal. -
assertNotEquals
Asserts that two chars are not equal. -
assertNotEquals
public static void assertNotEquals(char notExpected, char actual)Asserts that two chars are not equal. -
assertNotEquals
Asserts that two shorts are not equal. -
assertNotEquals
public static void assertNotEquals(short notExpected, short actual)Asserts that two shorts are not equal. -
assertNotEquals
Deprecated.in 3.0. UseAssert.assertNotEquals(String, long, long)in JUnit 4.11 instead.Asserts that two ints are not equal. -
assertNotEquals
Deprecated.in 3.0. UseAssert.assertNotEquals(long, long)in JUnit 4.11 instead.Asserts that two ints are not equal. -
assertEmpty
Assert that the givenIterableis empty. -
assertEmpty
Assert that the givenCollectionis empty. -
assertEmpty
Assert that the givenMutableMapIterableis empty. -
assertEmpty
public static void assertEmpty(String mutableMapIterableName, MutableMapIterable<?,?> actualMutableMapIterable)Assert that the givenCollectionis empty. -
assertEmpty
Assert that the givenPrimitiveIterableis empty. -
assertEmpty
Assert that the givenPrimitiveIterableis empty. -
assertIterableEmpty
Assert that the givenIterableis empty. -
assertIterableEmpty
Assert that the givenIterableis 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 givenMapis empty. -
assertEmpty
Assert that the givenMultimapis empty. -
assertEmpty
Assert that the givenMultimapis empty. -
assertEmpty
Assert that the givenMapis empty. -
assertNotEmpty
Assert that the givenIterableis not empty. -
assertNotEmpty
Assert that the givenIterableis not empty. -
assertNotEmpty
Assert that the givenMutableMapIterableis not empty. -
assertNotEmpty
public static void assertNotEmpty(String mutableMapIterableName, MutableMapIterable<?,?> actualMutableMapIterable)Assert that the givenMutableMapIterableis not empty. -
assertNotEmpty
Assert that the givenPrimitiveIterableis not empty. -
assertNotEmpty
Assert that the givenPrimitiveIterableis not empty. -
assertIterableNotEmpty
Assert that the givenIterableis not empty. -
assertIterableNotEmpty
Assert that the givenIterableis not empty. -
assertNotEmpty
Assert that the givenMapis not empty. -
assertNotEmpty
Assert that the givenMapis not empty. -
assertNotEmpty
Assert that the givenMultimapis not empty. -
assertNotEmpty
Assert that the givenMultimapis 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
public static void assertSize(String multimapName, int expectedSize, Multimap<?,?> actualMultimap)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 givenstringToFindis contained within thestringToSearch. -
assertNotContains
Assert that the givenunexpectedStringis not contained within thestringToSearch. -
assertContains
Assert that the givenstringToFindis contained within thestringToSearch. -
assertNotContains
public static void assertNotContains(String stringName, String unexpectedString, String stringToSearch)Assert that the givenunexpectedStringis not contained within thestringToSearch. -
assertCount
-
assertAllSatisfy
-
assertAllSatisfy
-
assertAllSatisfy
-
assertAnySatisfy
-
assertAnySatisfy
-
assertAnySatisfy
-
assertNoneSatisfy
-
assertNoneSatisfy
-
assertNoneSatisfy
-
assertContainsAllKeyValues
Assert that the givenMapcontains all of the given keys and values. -
assertContainsAllKeyValues
public static void assertContainsAllKeyValues(String mapName, Map<?,?> actualMap, Object... expectedKeyValues)Assert that the givenMapcontains all of the given keys and values. -
assertContainsAllKeyValues
Assert that the givenMapIterablecontains all of the given keys and values. -
assertContainsAllKeyValues
public static void assertContainsAllKeyValues(String mapIterableName, MapIterable<?,?> mapIterable, Object... expectedKeyValues)Assert that the givenMapIterablecontains all of the given keys and values. -
assertContainsAllKeyValues
public static void assertContainsAllKeyValues(MutableMapIterable<?,?> mutableMapIterable, Object... keyValues)Assert that the givenMutableMapIterablecontains all of the given keys and values. -
assertContainsAllKeyValues
public static void assertContainsAllKeyValues(String mutableMapIterableName, MutableMapIterable<?,?> mutableMapIterable, Object... expectedKeyValues)Assert that the givenMutableMapIterablecontains all of the given keys and values. -
assertContainsAllKeyValues
public static void assertContainsAllKeyValues(ImmutableMapIterable<?,?> immutableMapIterable, Object... keyValues)Assert that the givenImmutableMapIterablecontains all of the given keys and values. -
assertContainsAllKeyValues
public static void assertContainsAllKeyValues(String immutableMapIterableName, ImmutableMapIterable<?,?> immutableMapIterable, Object... expectedKeyValues)Assert that the givenImmutableMapIterablecontains all of the given keys and values. -
denyContainsAny
-
assertContainsNone
-
assertContains
Assert that the givenCollectioncontains the given item. -
assertContains
public static void assertContains(String collectionName, Object expectedItem, Collection<?> actualCollection)Assert that the givenCollectioncontains the given item. -
assertContains
public static void assertContains(Object expectedItem, ImmutableCollection<?> actualImmutableCollection)Assert that the givenImmutableCollectioncontains the given item. -
assertContains
public static void assertContains(String immutableCollectionName, Object expectedItem, ImmutableCollection<?> actualImmutableCollection)Assert that the givenImmutableCollectioncontains 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 givenMultimapcontains 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 givenMultimapcontains an entry with the given key and value. -
assertContainsAllEntries
Assert the givenMultimapcontains all of the given keys and values. -
assertContainsAllEntries
public static void assertContainsAllEntries(String multimapName, Multimap<?,?> actualMultimap, Object... expectedKeyValues)Assert the givenMultimapcontains all of the given keys and values. -
denyContainsAny
public static void denyContainsAny(String collectionName, Collection<?> actualCollection, Object... items) -
assertContainsKey
Assert that the givenMapcontains an entry with the given key. -
assertContainsKey
Assert that the givenMapcontains an entry with the given key. -
assertContainsKey
Assert that the givenMapIterablecontains an entry with the given key. -
assertContainsKey
public static void assertContainsKey(String mapIterableName, Object expectedKey, MapIterable<?,?> mapIterable)Assert that the givenMapIterablecontains an entry with the given key. -
assertContainsKey
public static void assertContainsKey(Object expectedKey, MutableMapIterable<?,?> mutableMapIterable)Assert that the givenMutableMapIterablecontains an entry with the given key. -
assertContainsKey
public static void assertContainsKey(String mutableMapIterableName, Object expectedKey, MutableMapIterable<?,?> mutableMapIterable)Assert that the givenMutableMapIterablecontains an entry with the given key. -
assertContainsKey
public static void assertContainsKey(Object expectedKey, ImmutableMapIterable<?,?> immutableMapIterable)Assert that the givenImmutableMapIterablecontains an entry with the given key. -
assertContainsKey
public static void assertContainsKey(String immutableMapIterableName, Object expectedKey, ImmutableMapIterable<?,?> immutableMapIterable)Assert that the givenImmutableMapIterablecontains an entry with the given key. -
denyContainsKey
Deny that the givenMapcontains an entry with the given key. -
denyContainsKey
Deny that the givenMapcontains an entry with the given key. -
assertContainsKeyValue
public static void assertContainsKeyValue(Object expectedKey, Object expectedValue, Map<?,?> actualMap)Assert that the givenMapcontains an entry with the given key and value. -
assertContainsKeyValue
public static void assertContainsKeyValue(String mapName, Object expectedKey, Object expectedValue, Map<?,?> actualMap)Assert that the givenMapcontains an entry with the given key and value. -
assertContainsKeyValue
public static void assertContainsKeyValue(Object expectedKey, Object expectedValue, MapIterable<?,?> mapIterable)Assert that the givenMapIterablecontains an entry with the given key and value. -
assertContainsKeyValue
public static void assertContainsKeyValue(String mapIterableName, Object expectedKey, Object expectedValue, MapIterable<?,?> mapIterable)Assert that the givenMapIterablecontains an entry with the given key and value. -
assertContainsKeyValue
public static void assertContainsKeyValue(Object expectedKey, Object expectedValue, MutableMapIterable<?,?> mapIterable)Assert that the givenMutableMapIterablecontains an entry with the given key and value. -
assertContainsKeyValue
public static void assertContainsKeyValue(String mapIterableName, Object expectedKey, Object expectedValue, MutableMapIterable<?,?> mutableMapIterable)Assert that the givenMutableMapIterablecontains an entry with the given key and value. -
assertContainsKeyValue
public static void assertContainsKeyValue(Object expectedKey, Object expectedValue, ImmutableMapIterable<?,?> mapIterable)Assert that the givenImmutableMapIterablecontains an entry with the given key and value. -
assertContainsKeyValue
public static void assertContainsKeyValue(String mapIterableName, Object expectedKey, Object expectedValue, ImmutableMapIterable<?,?> immutableMapIterable)Assert that the givenImmutableMapIterablecontains an entry with the given key and value. -
assertNotContains
Assert that the givenCollectiondoes not contain the given item. -
assertNotContains
public static void assertNotContains(String collectionName, Object unexpectedItem, Collection<?> actualCollection)Assert that the givenCollectiondoes not contain the given item. -
assertNotContains
Assert that the givenIterabledoes not contain the given item. -
assertNotContains
public static void assertNotContains(String collectionName, Object unexpectedItem, Iterable<?> iterable)Assert that the givenIterabledoes not contain the given item. -
assertNotContainsKey
Assert that the givenCollectiondoes not contain the given item. -
assertNotContainsKey
Assert that the givenCollectiondoes 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 givenitemis at theindexin 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 thatobjectAandobjectBare 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 thatobjectAandobjectBare 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 theCallablecodeand asserts that it throws anExceptionof the typeexpectedExceptionClass.Callableis most appropriate when a checked exception will be thrown. If a subclass ofRuntimeExceptionwill be thrown, the formassertThrows(Class, Runnable)may be more convenient.e.g.
Verify.assertThrows(StringIndexOutOfBoundsException.class, new Callable<String>() { public String call() throws Exception { return "Craig".substring(42, 3); } });- See Also:
assertThrows(Class, Runnable)
-
assertThrows
Runs theRunnablecodeand asserts that it throws anExceptionof the typeexpectedExceptionClass.Runnableis most appropriate when a subclass ofRuntimeExceptionwill be thrown. If a checked exception will be thrown, the formassertThrows(Class, Callable)may be more convenient.e.g.
Verify.assertThrows(NullPointerException.class, new Runnable() { public void run() { final Integer integer = null; LOGGER.info(integer.toString()); } });- See Also:
assertThrows(Class, Callable)
-
assertThrowsWithCause
public static void assertThrowsWithCause(Class<? extends Exception> expectedExceptionClass, Class<? extends Throwable> expectedCauseClass, Callable<?> code)Runs theCallablecodeand asserts that it throws anExceptionof the typeexpectedExceptionClass, which contains a cause of type expectedCauseClass.Callableis most appropriate when a checked exception will be thrown. If a subclass ofRuntimeExceptionwill 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 theRunnablecodeand asserts that it throws anExceptionof the typeexpectedExceptionClass, which contains a cause of type expectedCauseClass.Runnableis most appropriate when a subclass ofRuntimeExceptionwill 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); } } });
-