SELF - the "self" type of this assertion class. Please read "Emulating 'self types' using Java Generics to simplify fluent API implementation"
for more details.ACTUAL - the type of the "actual" value.ELEMENT - the type of elements of the "actual" value.ELEMENT_ASSERT - used for navigational assertions to return the right assert type.public abstract class AbstractListAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>> extends AbstractIterableAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT> implements IndexedObjectEnumerableAssert<SELF,ELEMENT>
Lists.iterablesactual, info, myself| Constructor and Description |
|---|
AbstractListAssert(ACTUAL actual,
Class<?> selfType) |
| Modifier and Type | Method and Description |
|---|---|
SELF |
as(Description description)
Sets the description of the assertion that is going to be called after.
|
SELF |
as(String description,
Object... args)
Sets the description of the assertion that is going to be called after.
|
SELF |
contains(ELEMENT value,
Index index)
Verifies that the actual group contains the given object at the given index.
|
SELF |
describedAs(Description description)
Sets the description of the assertion that is going to be called after.
|
SELF |
describedAs(String description,
Object... args)
Sets the description of the assertion that is going to be called after.
|
SELF |
doesNotContain(ELEMENT value,
Index index)
Verifies that the actual group does not contain the given object at the given index.
|
SELF |
doesNotHave(Condition<? super ACTUAL> condition)
Verifies that the actual value does not satisfy the given condition.
|
SELF |
doesNotHaveSameClassAs(Object other)
Verifies that the actual value does not have the same class as the given object.
|
SELF |
has(Condition<? super ACTUAL> condition)
Verifies that the actual value satisfies the given condition.
|
SELF |
has(Condition<? super ELEMENT> condition,
Index index)
Verifies that the actual object at the given index in the actual group satisfies the given condition.
|
SELF |
hasSameClassAs(Object other)
Verifies that the actual value has the same class as the given object.
|
SELF |
hasToString(String expectedToString)
Verifies that actual
actual.toString() is equal to the given String. |
SELF |
is(Condition<? super ACTUAL> condition)
Verifies that the actual value satisfies the given condition.
|
SELF |
is(Condition<? super ELEMENT> condition,
Index index)
Verifies that the actual object at the given index in the actual group satisfies the given condition.
|
SELF |
isEqualTo(Object expected)
Verifies that the actual value is equal to the given one.
|
SELF |
isExactlyInstanceOf(Class<?> type)
Verifies that the actual value is exactly an instance of the given type.
|
SELF |
isIn(Iterable<?> values)
Verifies that the actual value is present in the given values.
|
SELF |
isIn(Object... values)
Verifies that the actual value is present in the given array of values.
|
SELF |
isInstanceOf(Class<?> type)
Verifies that the actual value is an instance of the given type.
|
SELF |
isInstanceOfAny(Class<?>... types)
Verifies that the actual value is an instance of any of the given types.
|
SELF |
isNot(Condition<? super ACTUAL> condition)
Verifies that the actual value does not satisfy the given condition.
|
SELF |
isNotEqualTo(Object other)
Verifies that the actual value is not equal to the given one.
|
SELF |
isNotExactlyInstanceOf(Class<?> type)
Verifies that the actual value is not exactly an instance of given type.
|
SELF |
isNotIn(Iterable<?> values)
Verifies that the actual value is not present in the given values.
|
SELF |
isNotIn(Object... values)
Verifies that the actual value is not present in the given array of values.
|
SELF |
isNotInstanceOf(Class<?> type)
Verifies that the actual value is not an instance of the given type.
|
SELF |
isNotInstanceOfAny(Class<?>... types)
Verifies that the actual value is not an instance of any of the given types.
|
SELF |
isNotNull()
Verifies that the actual value is not
null. |
SELF |
isNotOfAnyClassIn(Class<?>... types)
Verifies that the actual value type is not in given types.
|
SELF |
isNotSameAs(Object other)
Verifies that the actual value is not the same as the given one, ie using == comparison.
|
SELF |
isOfAnyClassIn(Class<?>... types)
Verifies that the actual value type is in given types.
|
SELF |
isSameAs(Object expected)
Verifies that the actual value is the same as the given one, ie using == comparison.
|
SELF |
isSorted()
Verifies that the actual list is sorted into ascending order according to the natural ordering of its elements.
|
SELF |
isSortedAccordingTo(Comparator<? super ELEMENT> comparator)
Verifies that the actual list is sorted according to the given comparator. Empty lists are considered sorted whatever
the comparator is. One element lists are considered sorted if element is compatible with comparator.
|
SELF |
overridingErrorMessage(String newErrorMessage,
Object... args)
Overrides AssertJ default error message by the given one.
|
SELF |
usingComparator(Comparator<? super ACTUAL> customComparator)
Use given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
|
protected SELF |
usingComparisonStrategy(ComparisonStrategy comparisonStrategy) |
SELF |
usingDefaultComparator()
Revert to standard comparison for incoming assertion checks.
|
SELF |
usingDefaultElementComparator()
Revert to standard comparison for incoming assertion group element checks.
|
SELF |
usingElementComparator(Comparator<? super ELEMENT> customComparator)
Use given custom comparator instead of relying on actual type A
equals method to compare group
elements for incoming assertion checks. |
SELF |
withFailMessage(String newErrorMessage,
Object... args)
Alternative method for
AbstractAssert.overridingErrorMessage(java.lang.String, java.lang.Object...) |
SELF |
withThreadDumpOnError()
In case of assertion error, the thread dump will be printed on
System.err. |
allMatch, are, areAtLeast, areAtLeastOne, areAtMost, areExactly, areNot, contains, containsAll, containsExactly, containsExactlyElementsOf, containsExactlyInAnyOrder, containsNull, containsOnly, containsOnlyElementsOf, containsOnlyOnce, containsSequence, containsSubsequence, doesNotContain, doesNotContainAnyElementsOf, doesNotContainNull, doesNotHaveDuplicates, doNotHave, element, endsWith, extracting, extracting, extracting, extracting, extracting, extractingResultOf, extractingResultOf, filteredOn, filteredOn, filteredOn, filteredOn, filteredOnNull, first, flatExtracting, flatExtracting, flatExtracting, flatExtracting, hasAtLeastOneElementOfType, hasOnlyElementsOfType, hasOnlyOneElementSatisfying, hasSameElementsAs, hasSameSizeAs, hasSameSizeAs, hasSize, have, haveAtLeast, haveAtLeastOne, haveAtMost, haveExactly, inBinary, inHexadecimal, isEmpty, isNotEmpty, isNullOrEmpty, isSubsetOf, isSubsetOf, last, navigationDescription, size, startsWith, toAssert, usingComparatorForElementFieldsWithNames, usingComparatorForElementFieldsWithType, usingElementComparatorIgnoringFields, usingElementComparatorOnFields, usingFieldByFieldElementComparator, usingRecursiveFieldByFieldElementComparatorasList, asString, descriptionText, equals, failWithMessage, getWritableAssertionInfo, hashCode, isNull, matches, matches, satisfies, setCustomRepresentation, throwAssertionError, withRepresentationclone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitallMatch, are, areAtLeast, areAtLeastOne, areAtMost, areExactly, areNot, contains, containsAll, containsExactly, containsExactlyElementsOf, containsExactlyInAnyOrder, containsNull, containsOnly, containsOnlyElementsOf, containsOnlyOnce, containsSequence, containsSubsequence, doesNotContain, doesNotContainAnyElementsOf, doesNotContainNull, doesNotHaveDuplicates, doNotHave, endsWith, hasAtLeastOneElementOfType, hasOnlyElementsOfType, hasSameElementsAs, have, haveAtLeast, haveAtLeastOne, haveAtMost, haveExactly, isSubsetOf, isSubsetOf, startsWithhasSameSizeAs, hasSameSizeAs, hasSize, isEmpty, isNotEmpty, isNullOrEmptypublic SELF contains(ELEMENT value, Index index)
Example:
List<Ring> elvesRings = newArrayList(vilya, nenya, narya);
// assertions will pass
assertThat(elvesRings).contains(vilya, atIndex(0));
assertThat(elvesRings).contains(nenya, atIndex(1));
assertThat(elvesRings).contains(narya, atIndex(2));
// assertions will fail
assertThat(elvesRings).contains(vilya, atIndex(1));
assertThat(elvesRings).contains(nenya, atIndex(2));
assertThat(elvesRings).contains(narya, atIndex(0));contains in interface IndexedObjectEnumerableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ELEMENT>value - the object to look for.index - the index where the object should be stored in the actual group.public SELF doesNotContain(ELEMENT value, Index index)
Example:
List<Ring> elvesRings = newArrayList(vilya, nenya, narya);
// assertions will pass
assertThat(elvesRings).contains(vilya, atIndex(1));
assertThat(elvesRings).contains(nenya, atIndex(2));
assertThat(elvesRings).contains(narya, atIndex(0));
// assertions will fail
assertThat(elvesRings).contains(vilya, atIndex(0));
assertThat(elvesRings).contains(nenya, atIndex(1));
assertThat(elvesRings).contains(narya, atIndex(2));doesNotContain in interface IndexedObjectEnumerableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ELEMENT>value - the object to look for.index - the index where the object should not be stored in the actual group.public SELF has(Condition<? super ELEMENT> condition, Index index)
condition - the given condition.index - the index where the object should be stored in the actual group.AssertionError - if the given List is null or empty.NullPointerException - if the given Index is null.IndexOutOfBoundsException - if the value of the given Index is equal to or greater than the size of
the given List.NullPointerException - if the given Condition is null.AssertionError - if the value in the given List at the given index does not satisfy the given
Condition .public SELF is(Condition<? super ELEMENT> condition, Index index)
condition - the given condition.index - the index where the object should be stored in the actual group.AssertionError - if the given List is null or empty.NullPointerException - if the given Index is null.IndexOutOfBoundsException - if the value of the given Index is equal to or greater than the size of
the given List.NullPointerException - if the given Condition is null.AssertionError - if the value in the given List at the given index does not satisfy the given
Condition .public SELF isSorted()
All list elements must implement the Comparable interface and must be mutually comparable (that is,
e1.compareTo(e2) must not throw a ClassCastException for any elements e1 and e2 in the list), examples :
this assertion object.AssertionError - if the actual list is not sorted into ascending order according to the natural ordering of its
elements.AssertionError - if the actual list is null.AssertionError - if the actual list element type does not implement Comparable.AssertionError - if the actual list elements are not mutually Comparable.public SELF isSortedAccordingTo(Comparator<? super ELEMENT> comparator)
comparator - the Comparator used to compare list elementsthis assertion object.AssertionError - if the actual list is not sorted according to the given comparator.AssertionError - if the actual list is null.NullPointerException - if the given comparator is null.AssertionError - if the actual list elements are not mutually comparable according to given Comparator.public SELF usingElementComparator(Comparator<? super ELEMENT> customComparator)
AbstractIterableAssertequals method to compare group
elements for incoming assertion checks.
Custom comparator is bound to assertion instance, meaning that if a new assertion is created, it will use default comparison strategy.
Examples :
// compares invoices by payee
assertThat(invoiceList).usingComparator(invoicePayeeComparator).isEqualTo(expectedInvoiceList);
// compares invoices by date, doesNotHaveDuplicates and contains both use the given invoice date comparator
assertThat(invoiceList).usingComparator(invoiceDateComparator).doesNotHaveDuplicates().contains(may2010Invoice);
// as assertThat(invoiceList) creates a new assertion, it falls back to standard comparison strategy
// based on Invoice's equal method to compare invoiceList elements to lowestInvoice.
assertThat(invoiceList).contains(lowestInvoice);
// standard comparison : the fellowshipOfTheRing includes Gandalf but not Sauron (believe me) ...
assertThat(fellowshipOfTheRing).contains(gandalf)
.doesNotContain(sauron);
// ... but if we compare only races, Sauron is in fellowshipOfTheRing because he's a Maia like Gandalf.
assertThat(fellowshipOfTheRing).usingElementComparator(raceComparator)
.contains(sauron);usingElementComparator in interface EnumerableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ELEMENT>usingElementComparator in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>customComparator - the comparator to use for incoming assertion checks.this assertion object.public SELF usingDefaultElementComparator()
AbstractIterableAssert
This method should be used to disable a custom comparison strategy set by calling
EnumerableAssert.usingElementComparator(Comparator).
usingDefaultElementComparator in interface EnumerableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ELEMENT>usingDefaultElementComparator in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>this assertion object.protected SELF usingComparisonStrategy(ComparisonStrategy comparisonStrategy)
usingComparisonStrategy in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>public SELF as(String description, Object... args)
AbstractAssertYou must set it before calling the assertion otherwise it is ignored as the failing assertion breaks the chained call by throwing an AssertionError.
The description follows String.format(String, Object...) syntax.
Example :
try {
// set a bad age to Mr Frodo which is really 33 years old.
frodo.setAge(50);
// specify a test description (call as() before the assertion !), it supports String format syntax.
assertThat(frodo.getAge()).as("check %s's age", frodo.getName()).isEqualTo(33);
} catch (AssertionError e) {
assertThat(e).hasMessage("[check Frodo's age] expected:<[33]> but was:<[50]>");
}as in interface Descriptable<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>>as in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>description - the new description to set.args - optional parameter if description is a format String.this object.Descriptable.describedAs(String, Object...)public SELF as(Description description)
AbstractAssertYou must set it before calling the assertion otherwise it is ignored as the failing assertion breaks the chained call by throwing an AssertionError.
This overloaded version of "describedAs" offers more flexibility than the one taking a String by allowing
users to pass their own implementation of a description. For example, a description that creates its value lazily,
only when an assertion failure occurs.
as in interface Descriptable<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>>as in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>description - the new description to set.this object.Descriptable.describedAs(Description)public SELF describedAs(Description description)
AbstractAssertYou must set it before calling the assertion otherwise it is ignored as the failing assertion breaks the chained call by throwing an AssertionError.
This overloaded version of "describedAs" offers more flexibility than the one taking a String by allowing
users to pass their own implementation of a description. For example, a description that creates its value lazily,
only when an assertion failure occurs.
describedAs in interface Descriptable<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>>describedAs in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>description - the new description to set.this object.public SELF describedAs(String description, Object... args)
AbstractAssertYou must set it before calling the assertion otherwise it is ignored as the failing assertion breaks the chained call by throwing an AssertionError.
Alias for since "as" is a keyword in Groovy.Descriptable.as(String, Object...)
describedAs in interface Descriptable<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>>describedAs in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>description - the new description to set.this object.public SELF doesNotHave(Condition<? super ACTUAL> condition)
AbstractAssertExtensionPoints.isNot(Condition).doesNotHave in interface ExtensionPoints<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>doesNotHave in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>condition - the given condition.this ExtensionPoints object.ExtensionPoints.isNot(Condition)public SELF doesNotHaveSameClassAs(Object other)
AbstractAssertExample:
// assertions will pass
assertThat(1).doesNotHaveSameClassAs("abc");
assertThat(new ArrayList<String>()).doesNotHaveSameClassAs(new LinkedList<String>());
// assertions will fail
assertThat(1).doesNotHaveSameClassAs(2);
assertThat("abc").doesNotHaveSameClassAs("123");
assertThat(new ArrayList<String>()).doesNotHaveSameClassAs(new ArrayList<Integer>());doesNotHaveSameClassAs in interface Assert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>doesNotHaveSameClassAs in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>other - the object to check type against.public SELF has(Condition<? super ACTUAL> condition)
AbstractAssertExtensionPoints.is(Condition)
.has in interface ExtensionPoints<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>has in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>condition - the given condition.this ExtensionPoints object.ExtensionPoints.is(Condition)public SELF hasSameClassAs(Object other)
AbstractAssertExample:
// assertions will pass
assertThat(1).hasSameClassAs(2);
assertThat("abc").hasSameClassAs("123");
assertThat(new ArrayList<String>()).hasSameClassAs(new ArrayList<Integer>());
// assertions will fail
assertThat(1).hasSameClassAs("abc");
assertThat(new ArrayList<String>()).hasSameClassAs(new LinkedList<String>());hasSameClassAs in interface Assert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>hasSameClassAs in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>other - the object to check type against.public SELF hasToString(String expectedToString)
AbstractAssertactual.toString() is equal to the given String.
Example :
CartoonCaracter homer = new CartoonCaracter("Homer");
// Instead of writing ...
assertThat(homer.toString()).isEqualTo("Homer");
// ... you can simply write:
assertThat(homer).hasToString("Homer");hasToString in interface Assert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>hasToString in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>expectedToString - the expected String description of actual.public SELF is(Condition<? super ACTUAL> condition)
AbstractAssertExtensionPoints.has(Condition).is in interface ExtensionPoints<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>is in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>condition - the given condition.this ExtensionPoints object.ExtensionPoints.is(Condition)public SELF isEqualTo(Object expected)
AbstractAssertExample:
// assertions will pass
assertThat("abc").isEqualTo("abc");
assertThat(new HashMap<String, Integer>()).isEqualTo(new HashMap<String, Integer>());
// assertions will fail
assertThat("abc").isEqualTo("123");
assertThat(new ArrayList<String>()).isEqualTo(1);isEqualTo in interface Assert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>isEqualTo in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>expected - the given value to compare the actual value to.this assertion object.public SELF isExactlyInstanceOf(Class<?> type)
AbstractAssertExample:
// assertions will pass
assertThat("abc").isExactlyInstanceOf(String.class);
assertThat(new ArrayList<String>()).isExactlyInstanceOf(ArrayList.class);
assertThat(new HashMap<String, Integer>()).isExactlyInstanceOf(HashMap.class);
// assertions will fail
assertThat(1).isExactlyInstanceOf(String.class);
assertThat(new ArrayList<String>()).isExactlyInstanceOf(List.class);
assertThat(new HashMap<String, Integer>()).isExactlyInstanceOf(Map.class);isExactlyInstanceOf in interface Assert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>isExactlyInstanceOf in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>type - the type to check the actual value against.public SELF isIn(Iterable<?> values)
AbstractAssertExample:
Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya);
// assertion will pass:
assertThat(nenya).isIn(elvesRings);
// assertion will fail:
assertThat(oneRing).isIn(elvesRings);isIn in interface Assert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>isIn in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>values - the given iterable to search the actual value in.this assertion object.public SELF isIn(Object... values)
AbstractAssertExample:
Ring[] elvesRings = new Ring[] { vilya, nenya, narya };
// assertion will pass:
assertThat(nenya).isIn(elvesRings);
// assertion will fail:
assertThat(oneRing).isIn(elvesRings);isIn in interface Assert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>isIn in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>values - the given array to search the actual value in.this assertion object.public SELF isInstanceOf(Class<?> type)
AbstractAssertExample:
// assertions will pass
assertThat("abc").isInstanceOf(String.class);
assertThat(new HashMap<String, Integer>()).isInstanceOf(HashMap.class);
assertThat(new HashMap<String, Integer>()).isInstanceOf(Map.class);
// assertions will fail
assertThat(1).isInstanceOf(String.class);
assertThat(new ArrayList<String>()).isInstanceOf(LinkedList.class);isInstanceOf in interface Assert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>isInstanceOf in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>type - the type to check the actual value against.public SELF isInstanceOfAny(Class<?>... types)
AbstractAssertExample:
// assertions will pass
assertThat("abc").isInstanceOfAny(String.class, Integer.class);
assertThat(new ArrayList<String>()).isInstanceOfAny(LinkedList.class, ArrayList.class);
assertThat(new HashMap<String, Integer>()).isInstanceOfAny(TreeMap.class, Map.class);
// assertions will fail
assertThat(1).isInstanceOfAny(Double.class, Float.class);
assertThat(new ArrayList<String>()).isInstanceOfAny(LinkedList.class, Vector.class);isInstanceOfAny in interface Assert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>isInstanceOfAny in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>types - the types to check the actual value against.public SELF isNot(Condition<? super ACTUAL> condition)
AbstractAssertExtensionPoints.doesNotHave(Condition).isNot in interface ExtensionPoints<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>isNot in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>condition - the given condition.this ExtensionPoints object.ExtensionPoints.isNot(Condition)public SELF isNotEqualTo(Object other)
AbstractAssertExample:
// assertions will pass
assertThat("abc").isNotEqualTo("123");
assertThat(new ArrayList<String>()).isNotEqualTo(1);
// assertions will fail
assertThat("abc").isNotEqualTo("abc");
assertThat(new HashMap<String, Integer>()).isNotEqualTo(new HashMap<String, Integer>());isNotEqualTo in interface Assert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>isNotEqualTo in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>other - the given value to compare the actual value to.this assertion object.public SELF isNotExactlyInstanceOf(Class<?> type)
AbstractAssertExample:
// assertions will pass
assertThat(1).isNotExactlyInstanceOf(String.class);
assertThat(new ArrayList<String>()).isNotExactlyInstanceOf(List.class);
assertThat(new HashMap<String, Integer>()).isNotExactlyInstanceOf(Map.class);
// assertions will fail
assertThat("abc").isNotExactlyInstanceOf(String.class);
assertThat(new ArrayList<String>()).isNotExactlyInstanceOf(ArrayList.class);
assertThat(new HashMap<String, Integer>()).isNotExactlyInstanceOf(HashMap.class);isNotExactlyInstanceOf in interface Assert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>isNotExactlyInstanceOf in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>type - the type to check the actual value against.public SELF isNotIn(Iterable<?> values)
AbstractAssertExample:
Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya);
// assertion will pass:
assertThat(oneRing).isNotIn(elvesRings);
// assertion will fail:
assertThat(nenya).isNotIn(elvesRings);isNotIn in interface Assert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>isNotIn in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>values - the given iterable to search the actual value in.this assertion object.public SELF isNotIn(Object... values)
AbstractAssertExample:
Ring[] elvesRings = new Ring[] { vilya, nenya, narya };
// assertion will pass:
assertThat(oneRing).isNotIn(elvesRings);
// assertion will fail:
assertThat(nenya).isNotIn(elvesRings);isNotIn in interface Assert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>isNotIn in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>values - the given array to search the actual value in.this assertion object.public SELF isNotInstanceOf(Class<?> type)
AbstractAssertExample:
// assertions will pass
assertThat(1).isNotInstanceOf(Double.class);
assertThat(new ArrayList<String>()).isNotInstanceOf(LinkedList.class);
// assertions will fail
assertThat("abc").isNotInstanceOf(String.class);
assertThat(new HashMap<String, Integer>()).isNotInstanceOf(HashMap.class);
assertThat(new HashMap<String, Integer>()).isNotInstanceOf(Map.class);isNotInstanceOf in interface Assert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>isNotInstanceOf in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>type - the type to check the actual value against.public SELF isNotInstanceOfAny(Class<?>... types)
AbstractAssertExample:
// assertions will pass
assertThat(1).isNotInstanceOfAny(Double.class, Float.class);
assertThat(new ArrayList<String>()).isNotInstanceOfAny(LinkedList.class, Vector.class);
// assertions will fail
assertThat(1).isNotInstanceOfAny(Double.class, Integer.class);
assertThat(new ArrayList<String>()).isNotInstanceOfAny(LinkedList.class, ArrayList.class);
assertThat(new HashMap<String, Integer>()).isNotInstanceOfAny(TreeMap.class, Map.class);isNotInstanceOfAny in interface Assert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>isNotInstanceOfAny in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>types - the types to check the actual value against.public SELF isNotOfAnyClassIn(Class<?>... types)
AbstractAssertExample:
// assertions will pass
assertThat(new HashMap<String, Integer>()).isNotOfAnyClassIn(Map.class, TreeMap.class);
assertThat(new ArrayList<String>()).isNotOfAnyClassIn(LinkedList.class, List.class);
// assertions will fail
assertThat(new HashMap<String, Integer>()).isNotOfAnyClassIn(HashMap.class, TreeMap.class);
assertThat(new ArrayList<String>()).isNotOfAnyClassIn(ArrayList.class, LinkedList.class);isNotOfAnyClassIn in interface Assert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>isNotOfAnyClassIn in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>types - the types to check the actual value against.public SELF isNotNull()
AbstractAssertnull.
Example:
// assertion will pass
assertThat("abc").isNotNull();
assertThat(new HashMap<String, Integer>()).isNotNull();
// assertion will fail
String value = null;
assertThat(value).isNotNull();isNotNull in interface Assert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>isNotNull in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>this assertion object.public SELF isNotSameAs(Object other)
AbstractAssertExample:
// Name is a class with first and last fields, two Names are equals if both first and last are equals.
Name tyrion = new Name("Tyrion", "Lannister");
Name alias = tyrion;
Name clone = new Name("Tyrion", "Lannister");
// assertions succeed:
assertThat(clone).isNotSameAs(tyrion)
.isEqualTo(tyrion);
// assertion fails:
assertThat(alias).isNotSameAs(tyrion);isNotSameAs in interface Assert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>isNotSameAs in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>other - the given value to compare the actual value to.this assertion object.public SELF isOfAnyClassIn(Class<?>... types)
AbstractAssertExample:
// assertions will pass
assertThat(new HashMap<String, Integer>()).isOfAnyClassIn(HashMap.class, TreeMap.class);
assertThat(new ArrayList<String>()).isOfAnyClassIn(ArrayList.class, LinkedList.class);
// assertions will fail
assertThat(new HashMap<String, Integer>()).isOfAnyClassIn(TreeMap.class, Map.class);
assertThat(new ArrayList<String>()).isOfAnyClassIn(LinkedList.class, List.class);isOfAnyClassIn in interface Assert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>isOfAnyClassIn in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>types - the types to check the actual value against.public SELF isSameAs(Object expected)
AbstractAssertExample:
// Name is a class with first and last fields, two Names are equals if both first and last are equals.
Name tyrion = new Name("Tyrion", "Lannister");
Name alias = tyrion;
Name clone = new Name("Tyrion", "Lannister");
// assertions succeed:
assertThat(tyrion).isSameAs(alias)
.isEqualTo(clone);
// assertion fails:
assertThat(tyrion).isSameAs(clone);isSameAs in interface Assert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>isSameAs in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>expected - the given value to compare the actual value to.this assertion object.public SELF overridingErrorMessage(String newErrorMessage, Object... args)
AbstractAssert
The new error message is built using String.format(String, Object...) if you provide args parameter (if you
don't, the error message is taken as it is).
Example :
assertThat(player.isRookie()).overridingErrorMessage("Expecting Player <%s> to be a rookie but was not.", player)
.isTrue();overridingErrorMessage in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>newErrorMessage - the error message that will replace the default one provided by Assertj.args - the args used to fill error message as in String.format(String, Object...).public SELF usingDefaultComparator()
AbstractAssert
This method should be used to disable a custom comparison strategy set by calling
Assert.usingComparator(Comparator).
usingDefaultComparator in interface Assert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>usingDefaultComparator in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>this assertion object.public SELF usingComparator(Comparator<? super ACTUAL> customComparator)
AbstractAssertCustom comparator is bound to assertion instance, meaning that if a new assertion is created, it will use default comparison strategy. Examples :
// frodo and sam are instances of Character with Hobbit race (obviously :).
// raceComparator implements Comparator<Character>
assertThat(frodo).usingComparator(raceComparator).isEqualTo(sam);usingComparator in interface Assert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>usingComparator in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>customComparator - the comparator to use for incoming assertion checks.this assertion object.public SELF withFailMessage(String newErrorMessage, Object... args)
AbstractAssertAbstractAssert.overridingErrorMessage(java.lang.String, java.lang.Object...)withFailMessage in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>newErrorMessage - the error message that will replace the default one provided by Assertj.args - the args used to fill error message as in String.format(String, Object...).public SELF withThreadDumpOnError()
AbstractAssertSystem.err.
Example :
assertThat("Messi").withThreadDumpOnError().isEqualTo("Ronaldo");
will print the thread dump, something looking like:
"JDWP Command Reader"
java.lang.Thread.State: RUNNABLE
"JDWP Event Helper Thread"
java.lang.Thread.State: RUNNABLE
"JDWP Transport Listener: dt_socket"
java.lang.Thread.State: RUNNABLE
"Signal Dispatcher"
java.lang.Thread.State: RUNNABLE
"Finalizer"
java.lang.Thread.State: WAITING
at java.lang.Object.wait(Native Method)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135)
at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:151)
at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:189)
"Reference Handler"
java.lang.Thread.State: WAITING
at java.lang.Object.wait(Native Method)
at java.lang.Object.wait(Object.java:503)
at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:133)
"main"
java.lang.Thread.State: RUNNABLE
at sun.management.ThreadImpl.dumpThreads0(Native Method)
at sun.management.ThreadImpl.dumpAllThreads(ThreadImpl.java:446)
at org.assertj.core.internal.Failures.threadDumpDescription(Failures.java:193)
at org.assertj.core.internal.Failures.printThreadDumpIfNeeded(Failures.java:141)
at org.assertj.core.internal.Failures.failure(Failures.java:91)
at org.assertj.core.internal.Objects.assertEqual(Objects.java:314)
at org.assertj.core.api.AbstractAssert.isEqualTo(AbstractAssert.java:198)
at org.assertj.examples.ThreadDumpOnErrorExample.main(ThreadDumpOnErrorExample.java:28)withThreadDumpOnError in interface Assert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>withThreadDumpOnError in class AbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>Copyright © 2014–2016 AssertJ. All rights reserved.