Class AbstractListAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- java.lang.Object
-
- org.assertj.core.api.AbstractAssert<SELF,ACTUAL>
-
- org.assertj.core.api.AbstractIterableAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>
-
- org.assertj.core.api.AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>
-
- Type Parameters:
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.
- All Implemented Interfaces:
Assert<SELF,ACTUAL>
,Descriptable<SELF>
,EnumerableAssert<SELF,ELEMENT>
,ExtensionPoints<SELF,ACTUAL>
,IndexedObjectEnumerableAssert<SELF,ELEMENT>
,ObjectEnumerableAssert<SELF,ELEMENT>
- Direct Known Subclasses:
ClassBasedNavigableListAssert
,FactoryBasedNavigableListAssert
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>
Base class for all implementations of assertions forList
s.- Author:
- Yvonne Wang, Alex Ruiz, Joel Costigliola, Mikhail Mazursky, Jacek Jackowiak
-
-
Field Summary
Fields Modifier and Type Field Description (package private) Lists
lists
-
Fields inherited from class org.assertj.core.api.AbstractIterableAssert
iterables
-
Fields inherited from class org.assertj.core.api.AbstractAssert
actual, assertionErrorCreator, conditions, info, myself, objects, throwUnsupportedExceptionOnEquals
-
-
Constructor Summary
Constructors Constructor Description AbstractListAssert(ACTUAL actual, Class<?> selfType)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SELF
as(String description, Object... args)
Sets the description of the assertion that is going to be called after.SELF
as(Description description)
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(String description, Object... args)
Sets the description of the assertion that is going to be called after.SELF
describedAs(Description description)
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 actualactual.toString()
is equal to the givenString
.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 iterable.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 iterable.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 notnull
.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 in 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 the element is compatible with comparator.SELF
overridingErrorMessage(String newErrorMessage, Object... args)
Overrides AssertJ default error message by the given one.SELF
satisfies(Consumer<? super ELEMENT> requirements, Index index)
Verifies that the actualList
contains a value at givenIndex
that satisfies the givenrequirements
.SELF
usingComparator(Comparator<? super ACTUAL> customComparator)
Use the given custom comparator instead of relying on actual type A equals method for incoming assertion checks.SELF
usingComparator(Comparator<? super ACTUAL> customComparator, String customComparatorDescription)
Use the 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 the 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 Aequals
method to compare group elements for incoming assertion checks.SELF
withFailMessage(String newErrorMessage, Object... args)
Alternative method forAbstractAssert.overridingErrorMessage(java.lang.String, java.lang.Object...)
SELF
withThreadDumpOnError()
In case of an assertion error, a thread dump will be printed toSystem.err
.-
Methods inherited from class org.assertj.core.api.AbstractIterableAssert
allMatch, allMatch, allSatisfy, anyMatch, anySatisfy, are, areAtLeast, areAtLeastOne, areAtMost, areExactly, areNot, contains, containsAll, containsAnyElementsOf, containsAnyOf, containsExactly, containsExactlyElementsOf, containsExactlyInAnyOrder, containsExactlyInAnyOrderElementsOf, containsNull, containsOnly, containsOnlyElementsOf, containsOnlyNulls, containsOnlyOnce, containsOnlyOnceElementsOf, containsSequence, containsSequence, containsSubsequence, containsSubsequence, doesNotContain, doesNotContainAnyElementsOf, doesNotContainNull, doesNotContainSequence, doesNotContainSequence, doesNotContainSubsequence, doesNotContainSubsequence, doesNotHaveAnyElementsOfTypes, doesNotHaveDuplicates, doNotHave, element, element, endsWith, endsWith, extracting, extracting, extracting, extracting, extracting, extracting, extractingResultOf, extractingResultOf, filteredOn, filteredOn, filteredOn, filteredOn, filteredOn, filteredOnAssertions, filteredOnNull, first, first, flatExtracting, flatExtracting, flatExtracting, flatExtracting, flatExtracting, flatExtracting, getComparatorsByType, getComparatorsForElementPropertyOrFieldTypes, hasAtLeastOneElementOfType, hasOnlyElementsOfType, hasOnlyElementsOfTypes, hasOnlyOneElementSatisfying, hasSameElementsAs, hasSameSizeAs, hasSameSizeAs, hasSize, hasSizeBetween, hasSizeGreaterThan, hasSizeGreaterThanOrEqualTo, hasSizeLessThan, hasSizeLessThanOrEqualTo, have, haveAtLeast, haveAtLeastOne, haveAtMost, haveExactly, inBinary, inHexadecimal, isEmpty, isNotEmpty, isNullOrEmpty, isSubsetOf, isSubsetOf, last, last, navigationDescription, newAbstractIterableAssert, noneMatch, noneSatisfy, singleElement, singleElement, size, startsWith, toAssert, usingComparatorForElementFieldsWithNames, usingComparatorForElementFieldsWithType, usingComparatorForType, usingElementComparatorIgnoringFields, usingElementComparatorOnFields, usingFieldByFieldElementComparator, usingRecursiveComparison, usingRecursiveComparison, usingRecursiveFieldByFieldElementComparator, usingRecursiveFieldByFieldElementComparator, withAssertionState, withComparatorsForElementPropertyOrFieldNames, withComparatorsForElementPropertyOrFieldTypes, withIterables, withTypeComparators, zipSatisfy
-
Methods inherited from class org.assertj.core.api.AbstractAssert
asInstanceOf, asList, assertionError, asString, descriptionText, equals, extracting, extracting, failure, failureWithActualExpected, failWithActualExpectedAndMessage, failWithMessage, getWritableAssertionInfo, hashCode, hasSameHashCodeAs, isInstanceOfSatisfying, isNull, matches, matches, newListAssertInstance, overridingErrorMessage, satisfies, satisfies, satisfiesAnyOf, satisfiesAnyOf, satisfiesAnyOf, setCustomRepresentation, setDescriptionConsumer, setPrintAssertionsDescription, throwAssertionError, withFailMessage, withRepresentation
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.assertj.core.api.EnumerableAssert
hasSameSizeAs, hasSameSizeAs, hasSize, hasSizeBetween, hasSizeGreaterThan, hasSizeGreaterThanOrEqualTo, hasSizeLessThan, hasSizeLessThanOrEqualTo, isEmpty, isNotEmpty, isNullOrEmpty
-
Methods inherited from interface org.assertj.core.api.ObjectEnumerableAssert
allMatch, allMatch, allSatisfy, anyMatch, anySatisfy, are, areAtLeast, areAtLeastOne, areAtMost, areExactly, areNot, contains, containsAll, containsAnyElementsOf, containsAnyOf, containsExactly, containsExactlyElementsOf, containsExactlyInAnyOrder, containsExactlyInAnyOrderElementsOf, containsNull, containsOnly, containsOnlyElementsOf, containsOnlyNulls, containsOnlyOnce, containsOnlyOnceElementsOf, containsSequence, containsSequence, containsSubsequence, containsSubsequence, doesNotContain, doesNotContainAnyElementsOf, doesNotContainNull, doesNotContainSequence, doesNotContainSequence, doesNotContainSubsequence, doesNotContainSubsequence, doesNotHaveAnyElementsOfTypes, doesNotHaveDuplicates, doNotHave, endsWith, endsWith, hasAtLeastOneElementOfType, hasOnlyElementsOfType, hasOnlyElementsOfTypes, hasOnlyOneElementSatisfying, hasSameElementsAs, have, haveAtLeast, haveAtLeastOne, haveAtMost, haveExactly, isSubsetOf, isSubsetOf, noneMatch, noneSatisfy, startsWith
-
-
-
-
Field Detail
-
lists
Lists lists
-
-
Method Detail
-
contains
public SELF contains(ELEMENT value, Index index)
Verifies that the actual group contains the given object at the given 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));
- Specified by:
contains
in interfaceIndexedObjectEnumerableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>
- Parameters:
value
- the object to look for.index
- the index where the object should be stored in the actual group.- Returns:
- this assertion object.
-
doesNotContain
public SELF doesNotContain(ELEMENT value, Index index)
Verifies that the actual group does not contain the given object at the given 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));
- Specified by:
doesNotContain
in interfaceIndexedObjectEnumerableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>
- Parameters:
value
- the object to look for.index
- the index where the object should not be stored in the actual group.- Returns:
- this assertion object.
-
has
public 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.- Parameters:
condition
- the given condition.index
- the index where the object should be stored in the actual group.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the givenList
isnull
or empty.NullPointerException
- if the givenIndex
isnull
.IndexOutOfBoundsException
- if the value of the givenIndex
is equal to or greater than the size of the givenList
.NullPointerException
- if the givenCondition
isnull
.AssertionError
- if the value in the givenList
at the given index does not satisfy the givenCondition
.
-
is
public 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.- Parameters:
condition
- the given condition.index
- the index where the object should be stored in the actual group.- Returns:
- this assertion object.
- Throws:
AssertionError
- if the givenList
isnull
or empty.NullPointerException
- if the givenIndex
isnull
.IndexOutOfBoundsException
- if the value of the givenIndex
is equal to or greater than the size of the givenList
.NullPointerException
- if the givenCondition
isnull
.AssertionError
- if the value in the givenList
at the given index does not satisfy the givenCondition
.
-
isSorted
public SELF isSorted()
Verifies that the actual list is sorted in ascending order according to the natural ordering of its elements.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 :- a list composed of {"a1", "a2", "a3"} is ok because the element type (String) is Comparable
- a list composed of Rectangle {r1, r2, r3} is NOT ok because Rectangle is not Comparable
- a list composed of {True, "abc", False} is NOT ok because elements are not mutually comparable
Unique element lists are considered sorted unless the element type is not Comparable.- Returns:
this
assertion object.- Throws:
AssertionError
- if the actual list is not sorted in ascending order according to the natural ordering of its elements.AssertionError
- if the actual list isnull
.AssertionError
- if the actual list element type does not implementComparable
.AssertionError
- if the actual list elements are not mutuallyComparable
.
-
isSortedAccordingTo
public 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 the element is compatible with comparator.- Parameters:
comparator
- theComparator
used to compare list elements- Returns:
this
assertion object.- Throws:
AssertionError
- if the actual list is not sorted according to the given comparator.AssertionError
- if the actual list isnull
.NullPointerException
- if the given comparator isnull
.AssertionError
- if the actual list elements are not mutually comparable according to given Comparator.
-
satisfies
public SELF satisfies(Consumer<? super ELEMENT> requirements, Index index)
Verifies that the actualList
contains a value at givenIndex
that satisfies the givenrequirements
.Example:
List<TolkienCharacter> ringBearers = newArrayList(frodo, elrond, gandalf); // this assertion will pass assertThat(ringBearers).satisfies( ringBearer -> { assertThat(ringBearer.getAge()).isGreaterThan(200); assertThat(ringBearer.getRace()).isEqualTo(ELF); }, atIndex(1)); // this assertion will fail assertThat(ringBearers).satisfies( ringBearer -> { assertThat(ringBearer.getRace()).isEqualTo(ELF); }, atIndex(0);
- Parameters:
requirements
- the given requirements for the element atIndex
to meet.index
- the index where the object should be stored in the actualList
.- Returns:
this
assertion object.- Throws:
AssertionError
- if the value at givenIndex
does not satisfy therequirements
.AssertionError
- if the actual list isnull
.NullPointerException
- if the givenrequirements
arenull
.NullPointerException
- if the givenIndex
isnull
.IndexOutOfBoundsException
- if the value of the givenIndex
is equal to or greater than the size of the actualList
.- Since:
- 3.10.0
-
usingElementComparator
public SELF usingElementComparator(Comparator<? super ELEMENT> customComparator)
Description copied from class:AbstractIterableAssert
Use given custom comparator instead of relying on actual type Aequals
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);
- Specified by:
usingElementComparator
in interfaceEnumerableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>
- Overrides:
usingElementComparator
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Parameters:
customComparator
- the comparator to use for incoming assertion checks.- Returns:
this
assertion object.
-
usingDefaultElementComparator
public SELF usingDefaultElementComparator()
Description copied from class:AbstractIterableAssert
Revert to standard comparison for incoming assertion group element checks.This method should be used to disable a custom comparison strategy set by calling
EnumerableAssert.usingElementComparator(Comparator)
.- Specified by:
usingDefaultElementComparator
in interfaceEnumerableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>
- Overrides:
usingDefaultElementComparator
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Returns:
this
assertion object.
-
usingComparisonStrategy
protected SELF usingComparisonStrategy(ComparisonStrategy comparisonStrategy)
- Overrides:
usingComparisonStrategy
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
-
as
public SELF as(String description, Object... args)
Description copied from interface:Descriptable
Sets the description of the assertion that is going to be called after.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]>"); }
- Specified by:
as
in interfaceDescriptable<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>>
- Overrides:
as
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Parameters:
description
- the new description to set.args
- optional parameter if description is a format String.- Returns:
this
object.- See Also:
Descriptable.describedAs(String, Object...)
-
as
public SELF as(Description description)
Description copied from interface:Descriptable
Sets the description of the assertion that is going to be called after.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.- Specified by:
as
in interfaceDescriptable<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>>
- Overrides:
as
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Parameters:
description
- the new description to set.- Returns:
this
object.- See Also:
Descriptable.describedAs(Description)
-
describedAs
public SELF describedAs(Description description)
Description copied from class:AbstractAssert
Sets the description of the assertion that is going to be called after.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.- Specified by:
describedAs
in interfaceDescriptable<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>>
- Overrides:
describedAs
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Parameters:
description
- the new description to set.- Returns:
this
object.
-
describedAs
public SELF describedAs(String description, Object... args)
Description copied from interface:Descriptable
Sets the description of the assertion that is going to be called after.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...)
- Specified by:
describedAs
in interfaceDescriptable<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>>
- Overrides:
describedAs
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Parameters:
description
- the new description to set.args
- optional parameter if description is a format String.- Returns:
this
object.
-
doesNotHave
public SELF doesNotHave(Condition<? super ACTUAL> condition)
Description copied from class:AbstractAssert
Verifies that the actual value does not satisfy the given condition. This method is an alias for
.ExtensionPoints.isNot(Condition)
- Specified by:
doesNotHave
in interfaceExtensionPoints<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>
- Overrides:
doesNotHave
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Parameters:
condition
- the given condition.- Returns:
this ExtensionPoints
object.- See Also:
ExtensionPoints.isNot(Condition)
-
doesNotHaveSameClassAs
public SELF doesNotHaveSameClassAs(Object other)
Description copied from class:AbstractAssert
Verifies that the actual value does not have the same class as the given object.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>());
- Specified by:
doesNotHaveSameClassAs
in interfaceAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>
- Overrides:
doesNotHaveSameClassAs
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Parameters:
other
- the object to check type against.- Returns:
- this assertion object.
-
has
public SELF has(Condition<? super ACTUAL> condition)
Description copied from class:AbstractAssert
Verifies that the actual value satisfies the given condition. This method is an alias for
.ExtensionPoints.is(Condition)
- Specified by:
has
in interfaceExtensionPoints<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>
- Overrides:
has
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Parameters:
condition
- the given condition.- Returns:
this ExtensionPoints
object.- See Also:
ExtensionPoints.is(Condition)
-
hasSameClassAs
public SELF hasSameClassAs(Object other)
Description copied from class:AbstractAssert
Verifies that the actual value has the same class as the given object.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>());
- Specified by:
hasSameClassAs
in interfaceAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>
- Overrides:
hasSameClassAs
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Parameters:
other
- the object to check type against.- Returns:
- this assertion object.
-
hasToString
public SELF hasToString(String expectedToString)
Description copied from class:AbstractAssert
Verifies that actualactual.toString()
is equal to the givenString
.Example :
CartoonCharacter homer = new CartoonCharacter("Homer"); // Instead of writing ... assertThat(homer.toString()).isEqualTo("Homer"); // ... you can simply write: assertThat(homer).hasToString("Homer");
- Specified by:
hasToString
in interfaceAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>
- Overrides:
hasToString
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Parameters:
expectedToString
- the expected String description of actual.- Returns:
- this assertion object.
-
is
public SELF is(Condition<? super ACTUAL> condition)
Description copied from class:AbstractAssert
Verifies that the actual value satisfies the given condition. This method is an alias for
.ExtensionPoints.has(Condition)
- Specified by:
is
in interfaceExtensionPoints<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>
- Overrides:
is
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Parameters:
condition
- the given condition.- Returns:
this ExtensionPoints
object.- See Also:
ExtensionPoints.has(Condition)
-
isEqualTo
public SELF isEqualTo(Object expected)
Description copied from class:AbstractAssert
Verifies that the actual value is equal to the given one.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);
- Specified by:
isEqualTo
in interfaceAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>
- Overrides:
isEqualTo
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Parameters:
expected
- the given value to compare the actual value to.- Returns:
this
assertion object.
-
isExactlyInstanceOf
public SELF isExactlyInstanceOf(Class<?> type)
Description copied from class:AbstractAssert
Verifies that the actual value is exactly an instance of the given type.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);
- Specified by:
isExactlyInstanceOf
in interfaceAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>
- Overrides:
isExactlyInstanceOf
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Parameters:
type
- the type to check the actual value against.- Returns:
- this assertion object.
-
isIn
public SELF isIn(Iterable<?> values)
Description copied from class:AbstractAssert
Verifies that the actual value is present in the given iterable.This assertion always fails if the given iterable is empty.
Example:
Iterable<Ring> elvesRings = list(vilya, nenya, narya); // assertion will pass: assertThat(nenya).isIn(elvesRings); // assertions will fail: assertThat(oneRing).isIn(elvesRings); assertThat(oneRing).isIn(emptyList());
- Specified by:
isIn
in interfaceAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>
- Overrides:
isIn
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Parameters:
values
- the given iterable to search the actual value in.- Returns:
this
assertion object.
-
isIn
public SELF isIn(Object... values)
Description copied from class:AbstractAssert
Verifies that the actual value is present in the given array of values.This assertion always fails if the given array of values is empty.
Example:
Ring[] elvesRings = new Ring[] { vilya, nenya, narya }; // assertion will pass: assertThat(nenya).isIn(elvesRings); // assertions will fail: assertThat(oneRing).isIn(elvesRings); assertThat(oneRing).isIn(new Ring[0]);
- Specified by:
isIn
in interfaceAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>
- Overrides:
isIn
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Parameters:
values
- the given array to search the actual value in.- Returns:
this
assertion object.
-
isInstanceOf
public SELF isInstanceOf(Class<?> type)
Description copied from class:AbstractAssert
Verifies that the actual value is an instance of the given type.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);
- Specified by:
isInstanceOf
in interfaceAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>
- Overrides:
isInstanceOf
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Parameters:
type
- the type to check the actual value against.- Returns:
- this assertion object.
-
isInstanceOfAny
public SELF isInstanceOfAny(Class<?>... types)
Description copied from class:AbstractAssert
Verifies that the actual value is an instance of any of the given types.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);
- Specified by:
isInstanceOfAny
in interfaceAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>
- Overrides:
isInstanceOfAny
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Parameters:
types
- the types to check the actual value against.- Returns:
- this assertion object.
-
isNot
public SELF isNot(Condition<? super ACTUAL> condition)
Description copied from class:AbstractAssert
Verifies that the actual value does not satisfy the given condition. This method is an alias for
.ExtensionPoints.doesNotHave(Condition)
- Specified by:
isNot
in interfaceExtensionPoints<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>
- Overrides:
isNot
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Parameters:
condition
- the given condition.- Returns:
this ExtensionPoints
object.- See Also:
ExtensionPoints.isNot(Condition)
-
isNotEqualTo
public SELF isNotEqualTo(Object other)
Description copied from class:AbstractAssert
Verifies that the actual value is not equal to the given one.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>());
- Specified by:
isNotEqualTo
in interfaceAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>
- Overrides:
isNotEqualTo
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Parameters:
other
- the given value to compare the actual value to.- Returns:
this
assertion object.
-
isNotExactlyInstanceOf
public SELF isNotExactlyInstanceOf(Class<?> type)
Description copied from class:AbstractAssert
Verifies that the actual value is not exactly an instance of given type.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);
- Specified by:
isNotExactlyInstanceOf
in interfaceAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>
- Overrides:
isNotExactlyInstanceOf
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Parameters:
type
- the type to check the actual value against.- Returns:
- this assertion object.
-
isNotIn
public SELF isNotIn(Iterable<?> values)
Description copied from class:AbstractAssert
Verifies that the actual value is not present in the given iterable.This assertion always succeeds if the given iterable is empty.
Example:
Iterable<Ring> elvesRings = list(vilya, nenya, narya); // assertions will pass: assertThat(oneRing).isNotIn(elvesRings); assertThat(oneRing).isNotIn(emptyList()); // assertion will fail: assertThat(nenya).isNotIn(elvesRings);
- Specified by:
isNotIn
in interfaceAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>
- Overrides:
isNotIn
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Parameters:
values
- the given iterable to search the actual value in.- Returns:
this
assertion object.
-
isNotIn
public SELF isNotIn(Object... values)
Description copied from class:AbstractAssert
Verifies that the actual value is not present in the given array of values.This assertion always succeeds if the given array of values is empty.
Example:
Ring[] elvesRings = new Ring[] { vilya, nenya, narya }; // assertions will pass: assertThat(oneRing).isNotIn(elvesRings); assertThat(oneRing).isNotIn(new Ring[0]); // assertion will fail: assertThat(nenya).isNotIn(elvesRings);
- Specified by:
isNotIn
in interfaceAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>
- Overrides:
isNotIn
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Parameters:
values
- the given array to search the actual value in.- Returns:
this
assertion object.
-
isNotInstanceOf
public SELF isNotInstanceOf(Class<?> type)
Description copied from class:AbstractAssert
Verifies that the actual value is not an instance of the given type.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);
- Specified by:
isNotInstanceOf
in interfaceAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>
- Overrides:
isNotInstanceOf
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Parameters:
type
- the type to check the actual value against.- Returns:
- this assertion object.
-
isNotInstanceOfAny
public SELF isNotInstanceOfAny(Class<?>... types)
Description copied from class:AbstractAssert
Verifies that the actual value is not an instance of any of the given types.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);
- Specified by:
isNotInstanceOfAny
in interfaceAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>
- Overrides:
isNotInstanceOfAny
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Parameters:
types
- the types to check the actual value against.- Returns:
- this assertion object.
-
isNotOfAnyClassIn
public SELF isNotOfAnyClassIn(Class<?>... types)
Description copied from class:AbstractAssert
Verifies that the actual value type is not in given types.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);
- Specified by:
isNotOfAnyClassIn
in interfaceAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>
- Overrides:
isNotOfAnyClassIn
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Parameters:
types
- the types to check the actual value against.- Returns:
- this assertion object.
-
isNotNull
public SELF isNotNull()
Description copied from class:AbstractAssert
Verifies that the actual value is notnull
.Example:
// assertion will pass assertThat("abc").isNotNull(); assertThat(new HashMap<String, Integer>()).isNotNull(); // assertion will fail String value = null; assertThat(value).isNotNull();
- Specified by:
isNotNull
in interfaceAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>
- Overrides:
isNotNull
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Returns:
this
assertion object.
-
isNotSameAs
public SELF isNotSameAs(Object other)
Description copied from class:AbstractAssert
Verifies that the actual value is not the same as the given one, ie using == comparison.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);
- Specified by:
isNotSameAs
in interfaceAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>
- Overrides:
isNotSameAs
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Parameters:
other
- the given value to compare the actual value to.- Returns:
this
assertion object.
-
isOfAnyClassIn
public SELF isOfAnyClassIn(Class<?>... types)
Description copied from class:AbstractAssert
Verifies that the actual value type is in given types.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);
- Specified by:
isOfAnyClassIn
in interfaceAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>
- Overrides:
isOfAnyClassIn
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Parameters:
types
- the types to check the actual value against.- Returns:
- this assertion object.
-
isSameAs
public SELF isSameAs(Object expected)
Description copied from class:AbstractAssert
Verifies that the actual value is the same as the given one, ie using == comparison.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);
- Specified by:
isSameAs
in interfaceAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>
- Overrides:
isSameAs
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Parameters:
expected
- the given value to compare the actual value to.- Returns:
this
assertion object.
-
overridingErrorMessage
public SELF overridingErrorMessage(String newErrorMessage, Object... args)
Description copied from class:AbstractAssert
Overrides AssertJ default error message by the given one.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 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();
- Overrides:
overridingErrorMessage
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Parameters:
newErrorMessage
- the error message that will replace the default one provided by Assertj.args
- the args used to fill error message as inString.format(String, Object...)
.- Returns:
- this assertion object.
-
usingDefaultComparator
public SELF usingDefaultComparator()
Description copied from class:AbstractAssert
Revert to standard comparison for the incoming assertion checks.This method should be used to disable a custom comparison strategy set by calling
usingComparator
.- Specified by:
usingDefaultComparator
in interfaceAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>
- Overrides:
usingDefaultComparator
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Returns:
this
assertion object.
-
usingComparator
public SELF usingComparator(Comparator<? super ACTUAL> customComparator)
Description copied from class:AbstractAssert
Use the given custom comparator instead of relying on actual type A equals method for incoming assertion checks.The custom comparator is bound to assertion instance, meaning that if a new assertion instance is created, the default comparison strategy will be used.
Examples :
// frodo and sam are instances of Character with Hobbit race (obviously :). // raceComparator implements Comparator<Character> assertThat(frodo).usingComparator(raceComparator).isEqualTo(sam);
- Specified by:
usingComparator
in interfaceAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>
- Overrides:
usingComparator
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Parameters:
customComparator
- the comparator to use for the incoming assertion checks.- Returns:
this
assertion object.
-
usingComparator
public SELF usingComparator(Comparator<? super ACTUAL> customComparator, String customComparatorDescription)
Description copied from class:AbstractAssert
Use the given custom comparator instead of relying on actual type A equals method for incoming assertion checks.The custom comparator is bound to assertion instance, meaning that if a new assertion instance is created, the default comparison strategy will be used.
Examples :
// frodo and sam are instances of Character with Hobbit race (obviously :). // raceComparator implements Comparator<Character> assertThat(frodo).usingComparator(raceComparator, "Hobbit Race Comparator").isEqualTo(sam);
- Specified by:
usingComparator
in interfaceAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>
- Overrides:
usingComparator
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Parameters:
customComparator
- the comparator to use for the incoming assertion checks.customComparatorDescription
- comparator description to be used in assertion error messages- Returns:
this
assertion object.
-
withFailMessage
public SELF withFailMessage(String newErrorMessage, Object... args)
Description copied from class:AbstractAssert
Alternative method forAbstractAssert.overridingErrorMessage(java.lang.String, java.lang.Object...)
You must set it before calling the assertion otherwise it is ignored as the failing assertion breaks the chained call by throwing an AssertionError.
Example:
assertThat(player.isRookie()).withFailMessage("Expecting Player <%s> to be a rookie but was not.", player) .isTrue();
- Overrides:
withFailMessage
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Parameters:
newErrorMessage
- the error message that will replace the default one provided by Assertj.args
- the args used to fill error message as inString.format(String, Object...)
.- Returns:
- this assertion object.
-
withThreadDumpOnError
public SELF withThreadDumpOnError()
Description copied from class:AbstractAssert
In case of an assertion error, a thread dump will be printed toSystem.err
.Example :
will print a thread dump, something similar to this:assertThat("Messi").withThreadDumpOnError().isEqualTo("Ronaldo");
"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)
- Specified by:
withThreadDumpOnError
in interfaceAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>>
- Overrides:
withThreadDumpOnError
in classAbstractIterableAssert<SELF extends AbstractListAssert<SELF,ACTUAL,ELEMENT,ELEMENT_ASSERT>,ACTUAL extends List<? extends ELEMENT>,ELEMENT,ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,ELEMENT>>
- Returns:
- this assertion object.
-
-