S
- the "self" type of this assertion class. Please read "Emulating 'self types' using Java Generics to simplify fluent API implementation"
for more details.A
- the type of the "actual" value.T
- the type of elements of the "actual" value.public abstract class AbstractListAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T> extends AbstractIterableAssert<S,A,T> implements IndexedObjectEnumerableAssert<S,T>
List
s.actual, info, myself
Modifier | Constructor and Description |
---|---|
protected |
AbstractListAssert(A actual,
Class<?> selfType) |
Modifier and Type | Method and Description |
---|---|
S |
as(Description description)
Sets the description of the assertion that is going to be called after.
|
S |
as(String description,
Object... args)
Sets the description of the assertion that is going to be called after.
|
S |
contains(T value,
Index index)
Verifies that the actual group contains the given object at the given index.
|
S |
describedAs(Description description)
Sets the description of the assertion that is going to be called after.
|
S |
describedAs(String description,
Object... args)
Sets the description of the assertion that is going to be called after.
|
S |
doesNotContain(T value,
Index index)
Verifies that the actual group does not contain the given object at the given index.
|
S |
doesNotHave(Condition<? super A> condition)
Verifies that the actual value does not satisfy the given condition.
|
S |
doesNotHaveSameClassAs(Object other)
Verifies that the actual value does not have the same class as the given object.
|
S |
has(Condition<? super A> condition)
Verifies that the actual value satisfies the given condition.
|
S |
has(Condition<? super T> condition,
Index index)
Verifies that the actual object at the given index in the actual group satisfies the given condition.
|
S |
hasSameClassAs(Object other)
Verifies that the actual value has the same class as the given object.
|
S |
hasToString(String expectedToString)
Verifies that actual
actual.toString() is equal to the given String . |
S |
is(Condition<? super A> condition)
Verifies that the actual value satisfies the given condition.
|
S |
is(Condition<? super T> condition,
Index index)
Verifies that the actual object at the given index in the actual group satisfies the given condition.
|
S |
isEqualTo(Object expected)
Verifies that the actual value is equal to the given one.
|
S |
isExactlyInstanceOf(Class<?> type)
Verifies that the actual value is exactly an instance of the given type.
|
S |
isIn(Iterable<?> values)
Verifies that the actual value is present in the given values.
|
S |
isIn(Object... values)
Verifies that the actual value is present in the given array of values.
|
S |
isInstanceOf(Class<?> type)
Verifies that the actual value is an instance of the given type.
|
S |
isInstanceOfAny(Class<?>... types)
Verifies that the actual value is an instance of any of the given types.
|
S |
isNot(Condition<? super A> condition)
Verifies that the actual value does not satisfy the given condition.
|
S |
isNotEqualTo(Object other)
Verifies that the actual value is not equal to the given one.
|
S |
isNotExactlyInstanceOf(Class<?> type)
Verifies that the actual value is not exactly an instance of given type.
|
S |
isNotIn(Iterable<?> values)
Verifies that the actual value is not present in the given values.
|
S |
isNotIn(Object... values)
Verifies that the actual value is not present in the given array of values.
|
S |
isNotInstanceOf(Class<?> type)
Verifies that the actual value is not an instance of the given type.
|
S |
isNotInstanceOfAny(Class<?>... types)
Verifies that the actual value is not an instance of any of the given types.
|
S |
isNotNull()
Verifies that the actual value is not
null . |
S |
isNotOfAnyClassIn(Class<?>... types)
Verifies that the actual value type is not in given types.
|
S |
isNotSameAs(Object other)
Verifies that the actual value is not the same as the given one, ie using == comparison.
|
S |
isOfAnyClassIn(Class<?>... types)
Verifies that the actual value type is in given types.
|
S |
isSameAs(Object expected)
Verifies that the actual value is the same as the given one, ie using == comparison.
|
S |
isSorted()
Verifies that the actual list is sorted into ascending order according to the natural ordering of its elements.
|
S |
isSortedAccordingTo(Comparator<? super T> 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.
|
S |
overridingErrorMessage(String newErrorMessage,
Object... args)
Overrides AssertJ default error message by the given one.
|
S |
usingComparator(Comparator<? super A> customComparator)
Use given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
|
protected S |
usingComparisonStrategy(ComparisonStrategy comparisonStrategy) |
S |
usingDefaultComparator()
Revert to standard comparison for incoming assertion checks.
|
S |
usingDefaultElementComparator()
Revert to standard comparison for incoming assertion group element checks.
|
S |
usingElementComparator(Comparator<? super T> customComparator)
Use given custom comparator instead of relying on actual type A
equals method to compare group
elements for incoming assertion checks. |
S |
withFailMessage(String newErrorMessage,
Object... args)
Alternative method for
AbstractAssert.overridingErrorMessage(java.lang.String, java.lang.Object...) |
S |
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, endsWith, extracting, extracting, extracting, extracting, extracting, extractingResultOf, extractingResultOf, filteredOn, filteredOn, filteredOn, filteredOn, filteredOnNull, flatExtracting, flatExtracting, hasAtLeastOneElementOfType, hasOnlyElementsOfType, hasSameElementsAs, hasSameSizeAs, hasSameSizeAs, hasSize, have, haveAtLeast, haveAtLeastOne, haveAtMost, haveExactly, inBinary, inHexadecimal, isEmpty, isNotEmpty, isNullOrEmpty, isSubsetOf, isSubsetOf, startsWith, usingElementComparatorIgnoringFields, usingElementComparatorOnFields, usingFieldByFieldElementComparator
asList, asString, descriptionText, equals, failWithMessage, getWritableAssertionInfo, hashCode, isNull, matches, matches, throwAssertionError
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
allMatch, 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, startsWith
hasSameSizeAs, hasSameSizeAs, hasSize, isEmpty, isNotEmpty, isNullOrEmpty
public S contains(T value, Index index)
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<S extends AbstractListAssert<S,A,T>,T>
value
- the object to look for.index
- the index where the object should be stored in the actual group.public S doesNotContain(T value, Index index)
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<S extends AbstractListAssert<S,A,T>,T>
value
- the object to look for.index
- the index where the object should not be stored in the actual group.public S has(Condition<? super T> 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 S is(Condition<? super T> 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 S 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 S isSortedAccordingTo(Comparator<? super T> 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 S usingElementComparator(Comparator<? super T> customComparator)
AbstractIterableAssert
equals
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<S extends AbstractListAssert<S,A,T>,T>
usingElementComparator
in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
customComparator
- the comparator to use for incoming assertion checks.this
assertion object.public S usingDefaultElementComparator()
AbstractIterableAssert
This method should be used to disable a custom comparison strategy set by calling
EnumerableAssert.usingElementComparator(Comparator)
.
usingDefaultElementComparator
in interface EnumerableAssert<S extends AbstractListAssert<S,A,T>,T>
usingDefaultElementComparator
in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
this
assertion object.protected S usingComparisonStrategy(ComparisonStrategy comparisonStrategy)
usingComparisonStrategy
in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
public S as(String description, Object... args)
AbstractAssert
You 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<S extends AbstractListAssert<S,A,T>>
as
in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
description
- the new description to set.args
- optional parameter if description is a format String.this
object.Descriptable.describedAs(String, Object...)
public S as(Description description)
AbstractAssert
You 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<S extends AbstractListAssert<S,A,T>>
as
in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
description
- the new description to set.this
object.Descriptable.describedAs(Description)
public S describedAs(Description description)
AbstractAssert
You 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<S extends AbstractListAssert<S,A,T>>
describedAs
in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
description
- the new description to set.this
object.public S describedAs(String description, Object... args)
AbstractAssert
You 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<S extends AbstractListAssert<S,A,T>>
describedAs
in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
description
- the new description to set.this
object.public S doesNotHave(Condition<? super A> condition)
AbstractAssert
ExtensionPoints.isNot(Condition)
.doesNotHave
in interface ExtensionPoints<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>>
doesNotHave
in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
condition
- the given condition.this ExtensionPoints
object.ExtensionPoints.isNot(Condition)
public S doesNotHaveSameClassAs(Object other)
AbstractAssert
Example:
// 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<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>>
doesNotHaveSameClassAs
in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
other
- the object to check type against.public S has(Condition<? super A> condition)
AbstractAssert
ExtensionPoints.is(Condition)
.has
in interface ExtensionPoints<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>>
has
in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
condition
- the given condition.this ExtensionPoints
object.ExtensionPoints.is(Condition)
public S hasSameClassAs(Object other)
AbstractAssert
Example:
// 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<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>>
hasSameClassAs
in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
other
- the object to check type against.public S hasToString(String expectedToString)
AbstractAssert
actual.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<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>>
hasToString
in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
expectedToString
- the expected String description of actual.public S is(Condition<? super A> condition)
AbstractAssert
ExtensionPoints.has(Condition)
.is
in interface ExtensionPoints<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>>
is
in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
condition
- the given condition.this ExtensionPoints
object.ExtensionPoints.is(Condition)
public S isEqualTo(Object expected)
AbstractAssert
Example:
// 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<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>>
isEqualTo
in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
expected
- the given value to compare the actual value to.this
assertion object.public S isExactlyInstanceOf(Class<?> type)
AbstractAssert
Example:
// 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<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>>
isExactlyInstanceOf
in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
type
- the type to check the actual value against.public S isIn(Iterable<?> values)
AbstractAssert
Example:
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<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>>
isIn
in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
values
- the given iterable to search the actual value in.this
assertion object.public S isIn(Object... values)
AbstractAssert
Example:
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<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>>
isIn
in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
values
- the given array to search the actual value in.this
assertion object.public S isInstanceOf(Class<?> type)
AbstractAssert
Example:
// 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<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>>
isInstanceOf
in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
type
- the type to check the actual value against.public S isInstanceOfAny(Class<?>... types)
AbstractAssert
Example:
// 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<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>>
isInstanceOfAny
in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
types
- the types to check the actual value against.public S isNot(Condition<? super A> condition)
AbstractAssert
ExtensionPoints.doesNotHave(Condition)
.isNot
in interface ExtensionPoints<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>>
isNot
in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
condition
- the given condition.this ExtensionPoints
object.ExtensionPoints.isNot(Condition)
public S isNotEqualTo(Object other)
AbstractAssert
Example:
// 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<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>>
isNotEqualTo
in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
other
- the given value to compare the actual value to.this
assertion object.public S isNotExactlyInstanceOf(Class<?> type)
AbstractAssert
Example:
// 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<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>>
isNotExactlyInstanceOf
in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
type
- the type to check the actual value against.public S isNotIn(Iterable<?> values)
AbstractAssert
Example:
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<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>>
isNotIn
in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
values
- the given iterable to search the actual value in.this
assertion object.public S isNotIn(Object... values)
AbstractAssert
Example:
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<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>>
isNotIn
in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
values
- the given array to search the actual value in.this
assertion object.public S isNotInstanceOf(Class<?> type)
AbstractAssert
Example:
// 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<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>>
isNotInstanceOf
in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
type
- the type to check the actual value against.public S isNotInstanceOfAny(Class<?>... types)
AbstractAssert
Example:
// 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<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>>
isNotInstanceOfAny
in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
types
- the types to check the actual value against.public S isNotOfAnyClassIn(Class<?>... types)
AbstractAssert
Example:
// 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<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>>
isNotOfAnyClassIn
in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
types
- the types to check the actual value against.public S isNotNull()
AbstractAssert
null
.
Example:
// assertion will pass
assertThat("abc").isNotNull();
assertThat(new HashMap<String, Integer>()).isNotNull();
// assertion will fail
String value = null;
assertThat(value).isNotNull();
public S isNotSameAs(Object other)
AbstractAssert
Example:
// 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<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>>
isNotSameAs
in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
other
- the given value to compare the actual value to.this
assertion object.public S isOfAnyClassIn(Class<?>... types)
AbstractAssert
Example:
// 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<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>>
isOfAnyClassIn
in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
types
- the types to check the actual value against.public S isSameAs(Object expected)
AbstractAssert
Example:
// 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<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>>
isSameAs
in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
expected
- the given value to compare the actual value to.this
assertion object.public S 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<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
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 S usingDefaultComparator()
AbstractAssert
This method should be used to disable a custom comparison strategy set by calling
Assert.usingComparator(Comparator)
.
usingDefaultComparator
in interface Assert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>>
usingDefaultComparator
in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
this
assertion object.public S usingComparator(Comparator<? super A> customComparator)
AbstractAssert
Custom 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<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>>
usingComparator
in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
customComparator
- the comparator to use for incoming assertion checks.this
assertion object.public S withFailMessage(String newErrorMessage, Object... args)
AbstractAssert
AbstractAssert.overridingErrorMessage(java.lang.String, java.lang.Object...)
withFailMessage
in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
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 S withThreadDumpOnError()
Assert
System.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<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>>
withThreadDumpOnError
in class AbstractIterableAssert<S extends AbstractListAssert<S,A,T>,A extends List<? extends T>,T>
Copyright © 2014–2016 AssertJ. All rights reserved.