-
Interfaces Interface Description org.assertj.core.api.iterable.Extractor useFunction
instead
-
Classes Class Description org.assertj.core.api.Java6Assertions For Android compatible assertions use the latest assertj 2.x version which is based on Java 7 only.Assertions compatible with Android. Duplicated from
Assertions
.org.assertj.core.api.Java6BDDAssertions For Android compatible assertions use the latest assertj 2.x version which is based on Java 7 only.Android-compatible BDD-style assertions duplicated from
BDDAssertions
.org.assertj.core.api.Java6BDDSoftAssertions For Android compatible assertions use the latest assertj 2.x version which is based on Java 7 only.BDD-style Android-compatible soft assertions. Duplicated from
BDDSoftAssertions
.org.assertj.core.api.Java6JUnitBDDSoftAssertions For Android compatible assertions use the latest assertj 2.x version which is based on Java 7 only.Duplicate of
JUnitBDDSoftAssertions
compatible with Android.org.assertj.core.api.Java6JUnitSoftAssertions For Android compatible assertions use the latest assertj 2.x version which is based on Java 7 only.JUnitSoftAssertions rule compatible with Android. Duplicated from
JUnitSoftAssertions
.org.assertj.core.api.Java6SoftAssertions For Android compatible assertions use the latest assertj 2.x version which is based on Java 7 only.Soft assertions compatible with Android. Duplicated from
SoftAssertions
.org.assertj.core.api.JUnitJupiterBDDSoftAssertions useSoftAssertionsExtension
instead. Same asSoftAssertions
, but with the following differences:
First, it's a JUnit Jupiter extension, which can be used without having to callassertAll()
, example:
Second, the failures are recognized by IDE's (like IntelliJ IDEA) which open a comparison window.public class SoftlyTest { @RegisterExtension public final JUnitJupiterBDDSoftAssertions softly = new JUnitJupiterBDDSoftAssertions(); @Test public void soft_bdd_assertions() throws Exception { softly.then(1).isEqualTo(2); softly.then(Lists.newArrayList(1, 2)).containsOnly(1, 2); } }
org.assertj.core.api.JUnitJupiterSoftAssertions useSoftAssertionsExtension
instead. Same asSoftAssertions
, but with the following differences:
First, it's a JUnit Jupiter extension, which can be used without having to callassertAll()
, example:
Second, the failures are recognized by IDE's (like IntelliJ IDEA) which open a comparison window.public class SoftlyTest { @RegisterExtension public final JUnitJupiterSoftAssertions softly = new JUnitJupiterSoftAssertions(); @Test public void testSoftly() throws Exception { softly.assertThat(1).isEqualTo(2); softly.assertThat(Lists.newArrayList(1, 2)).containsOnly(1, 2); } }
-
Methods Method Description org.assertj.core.api.AbstractAssert.equals(Object) useAbstractAssert.isEqualTo(java.lang.Object)
insteadorg.assertj.core.api.AbstractBooleanArrayAssert.usingDefaultElementComparator() Custom element Comparator is not supported for Boolean array comparison.org.assertj.core.api.AbstractBooleanArrayAssert.usingElementComparator(Comparator<? super Boolean>) Custom element Comparator is not supported for Boolean array comparison.org.assertj.core.api.AbstractBooleanAssert.usingComparator(Comparator<? super Boolean>) Custom Comparator is not supported for Boolean comparison.org.assertj.core.api.AbstractCharSequenceAssert.isJavaBlank() UseAbstractCharSequenceAssert.isBlank()
instead.org.assertj.core.api.AbstractCharSequenceAssert.isNotJavaBlank() UseAbstractCharSequenceAssert.isNotBlank()
instead.org.assertj.core.api.AbstractCharSequenceAssert.usingDefaultElementComparator() Custom element Comparator is not supported for CharSequence comparison.org.assertj.core.api.AbstractCharSequenceAssert.usingElementComparator(Comparator<? super Character>) Custom element Comparator is not supported for CharSequence comparison.org.assertj.core.api.AbstractClassAssert.hasFields(String...) useAbstractClassAssert.hasPublicFields(String...)
instead.org.assertj.core.api.AbstractDateAssert.isAfterOrEqualsTo(Date) prefer callingAbstractDateAssert.isAfterOrEqualTo(Date)
org.assertj.core.api.AbstractDateAssert.isBeforeOrEqualsTo(Date) prefer callingAbstractDateAssert.isBeforeOrEqualTo(Date)
org.assertj.core.api.AbstractDateAssert.isWithinDayOfMonth(int) useAbstractDateAssert.hasDayOfMonth(int)
instead.org.assertj.core.api.AbstractDateAssert.isWithinDayOfWeek(int) useAbstractDateAssert.hasDayOfWeek(int)
instead.org.assertj.core.api.AbstractDateAssert.isWithinHourOfDay(int) useAbstractDateAssert.hasHourOfDay(int)
instead.org.assertj.core.api.AbstractDateAssert.isWithinMillisecond(int) useAbstractDateAssert.hasMillisecond(int)
instead.org.assertj.core.api.AbstractDateAssert.isWithinMinute(int) useAbstractDateAssert.hasMinute(int)
instead.org.assertj.core.api.AbstractDateAssert.isWithinMonth(int) useAbstractDateAssert.hasMonth(int)
instead.org.assertj.core.api.AbstractDateAssert.isWithinSecond(int) useAbstractDateAssert.hasSecond(int)
instead.org.assertj.core.api.AbstractDateAssert.isWithinYear(int) useAbstractDateAssert.hasYear(int)
instead.org.assertj.core.api.AbstractFileAssert.hasContentEqualTo(File) useAbstractFileAssert.hasSameContentAs(File)
insteadorg.assertj.core.api.AbstractInputStreamAssert.hasContentEqualTo(InputStream) org.assertj.core.api.AbstractMapAssert.usingDefaultElementComparator() Custom element Comparator is not supported for MapEntry comparison.org.assertj.core.api.AbstractMapAssert.usingElementComparator(Comparator<? super Map.Entry<? extends K, ? extends V>>) Custom element Comparator is not supported for MapEntry comparison.org.assertj.core.api.AbstractObjectAssert.isEqualToComparingFieldByFieldRecursively(Object) Prefer callingAbstractObjectAssert.usingRecursiveComparison()
for comparing objects field by field as it offers more flexibility, better reporting and an easier to use API. Asserts that the object under test (actual) is equal to the given object based on a recursive property/field by property/field comparison (including inherited ones). This can be useful if actual'sequals
implementation does not suit you. The recursive property/field comparison is not applied on fields having a customequals
implementation, i.e. the overriddenequals
method will be used instead of a field by field comparison.The recursive comparison handles cycles. By default
floats
are compared with a precision of 1.0E-6 anddoubles
with 1.0E-15.You can specify a custom comparator per (nested) fields or type with respectively
usingComparatorForFields(Comparator, String...)
andAbstractObjectAssert.usingComparatorForType(Comparator, Class)
.The objects to compare can be of different types but must have the same properties/fields. For example if actual object has a name String field, it is expected the other object to also have one. If an object has a field and a property with the same name, the property value will be used over the field.
Example:
public class Person { public String name; public double height; public Home home = new Home(); public Person bestFriend; // constructor with name and height omitted for brevity } public class Home { public Address address = new Address(); } public static class Address { public int number = 1; } Person jack = new Person("Jack", 1.80); jack.home.address.number = 123; Person jackClone = new Person("Jack", 1.80); jackClone.home.address.number = 123; // cycle are handled in comparison jack.bestFriend = jackClone; jackClone.bestFriend = jack; // will fail as equals compares object references assertThat(jack).isEqualTo(jackClone); // jack and jackClone are equals when doing a recursive field by field comparison assertThat(jack).isEqualToComparingFieldByFieldRecursively(jackClone); // any type/field can be compared with a a specific comparator. // let's change jack's height a little bit jack.height = 1.81; // assertion fails because of the height difference // (the default precision comparison for double is 1.0E-15) assertThat(jack).isEqualToComparingFieldByFieldRecursively(jackClone); // this succeeds because we allow a 0.5 tolerance on double assertThat(jack).usingComparatorForType(new DoubleComparator(0.5), Double.class) .isEqualToComparingFieldByFieldRecursively(jackClone); // you can set a comparator on specific fields (nested fields are supported) assertThat(jack).usingComparatorForFields(new DoubleComparator(0.5), "height") .isEqualToComparingFieldByFieldRecursively(jackClone);
org.assertj.core.api.Assert.equals(Object) Throws
if called. It is easy to accidentally callUnsupportedOperationException
equals(Object)
instead of
.Assert.isEqualTo(Object)
org.assertj.core.api.AtomicBooleanAssert.usingComparator(Comparator<? super AtomicBoolean>) Custom Comparator is not supported for Boolean comparison.org.assertj.core.util.Maps.format(Map<?, ?>) useStandardRepresentation.toStringOf(Map)
instead.