Class BDDAssumptions
The difference with the Assumptions class is that entry point methods are named given instead of
assumeThat.
BDDAssumptions and BDDAssertions complement each other to allow a fluent Behavior-driven development.
Examples:
String hobbit = "HOBBIT";
List<String> fellowshipOfTheRing = list("Aragorn", "Gandalf", "Frodo", "Legolas"); // and more
@Test
public void given_the_assumption_is_not_met_the_test_is_skipped() {
given(hobbit).isEqualTo("ORC");
// ... following code is not executed
then(fellowshipOfTheRing).contains("Sauron");
}
@Test
public void given_the_assumption_is_met_the_test_is_executed() {
given(hobbit).isEqualTo("HOBBIT");
// ... following code is executed
then(fellowshipOfTheRing).doesNotContain("Sauron");
}- Since:
- 3.14.0
- Author:
- Gonzalo Müller
-
Method Summary
Modifier and TypeMethodDescriptionstatic AbstractBooleanAssert<?> given(boolean actual) Creates a new assumption's instance for abooleanvalue.static AbstractBooleanArrayAssert<?> given(boolean[] actual) Creates a new assumption's instance for abooleans' array.static Boolean2DArrayAssertgiven(boolean[][] actual) Creates a new assumption's instance for abooleans' two-dimensional array.static AbstractByteAssert<?> given(byte actual) Creates a new assumption's instance for abytevalue.static AbstractByteArrayAssert<?> given(byte[] actual) Creates a new assumption's instance for abytes' array.static Byte2DArrayAssertgiven(byte[][] actual) Creates a new assumption's instance for abytes' two-dimensional array.static AbstractCharacterAssert<?> given(char actual) Creates a new assumption's instance for acharvalue.static AbstractCharArrayAssert<?> given(char[] actual) Creates a new assumption's instance for anchars' array.static Char2DArrayAssertgiven(char[][] actual) Creates a new assumption's instance for anchars' two-dimensional array.static AbstractDoubleAssert<?> given(double actual) Creates a new assumption's instance for adoublevalue.static AbstractDoubleArrayAssert<?> given(double[] actual) Creates a new assumption's instance for andoubles' array.static Double2DArrayAssertgiven(double[][] actual) Creates a new assumption's instance for andoubles' two-dimensional array.static AbstractFloatAssert<?> given(float actual) Creates a new assumption's instance for afloatvalue.static AbstractFloatArrayAssert<?> given(float[] actual) Creates a new assumption's instance for afloats' array.static Float2DArrayAssertgiven(float[][] actual) Creates a new assumption's instance for afloats' two-dimensional array.static AbstractIntegerAssert<?> given(int actual) Creates a new assumption's instance for anintvalue.static AbstractIntArrayAssert<?> given(int[] actual) Creates a new assumption's instance for anints' array.static Int2DArrayAssertgiven(int[][] actual) Creates a new assumption's instance for anints' two-dimensional array.static AbstractLongAssert<?> given(long actual) Creates a new assumption's instance for alongvalue.static AbstractLongArrayAssert<?> given(long[] actual) Creates a new assumption's instance for alongs' array.static Long2DArrayAssertgiven(long[][] actual) Creates a new assumption's instance for alongs' two-dimensional array.static AbstractShortAssert<?> given(short actual) Creates a new assumption's instance for ashortvalue.static AbstractShortArrayAssert<?> given(short[] actual) Creates a new assumption's instance for ashorts' array.static Short2DArrayAssertgiven(short[][] actual) Creates a new assumption's instance for ashorts' two-dimensional array.static AbstractFileAssert<?> Creates a new assumption's instance for aFilevalue.static AbstractInputStreamAssert<?, ? extends InputStream> given(InputStream actual) Creates a new assumption's instance for anInputStreamvalue.static AbstractBooleanAssert<?> Creates a new assumption's instance for aBooleanvalue.static AbstractByteAssert<?> Creates a new assumption's instance for aBytevalue.static AbstractCharacterAssert<?> Creates a new assumption's instance for aCharactervalue.static AbstractCharSequenceAssert<?, ? extends CharSequence> given(CharSequence actual) Creates a new assumption's instance for aCharSequencevalue.static ClassAssertCreates a new assumption's instance for aClassvalue.static AbstractDoubleAssert<?> Creates a new assumption's instance for aDoublevalue.static AbstractFloatAssert<?> Creates a new assumption's instance for aFloatvalue.static AbstractIntegerAssert<?> Creates a new assumption's instance for anIntegervalue.static <ELEMENT> IterableAssert<ELEMENT> Creates a new assumption's instance for anIterablevalue.static AbstractLongAssert<?> Creates a new assumption's instance for aLongvalue.static AbstractShortAssert<?> Creates a new assumption's instance for aShortvalue.static AbstractStringAssert<?> Creates a new assumption's instance for aStringvalue.static AbstractCharSequenceAssert<?, ? extends CharSequence> given(StringBuffer actual) Creates a new assumption's instance for aStringBuffervalue.static AbstractCharSequenceAssert<?, ? extends CharSequence> given(StringBuilder actual) Creates a new assumption's instance for aStringBuildervalue.static AbstractBigDecimalAssert<?> given(BigDecimal actual) Creates a new assumption's instance for aBigDecimalvalue.static AbstractBigIntegerAssert<?> given(BigInteger actual) Creates a new assumption's instance for aBigIntegervalue.static AbstractUriAssert<?> Creates a new assumption's instance for anURIvalue.static AbstractUrlAssert<?> Creates a new assumption's instance for anURLvalue.static AbstractPathAssert<?> Creates a new assumption's instance for aPathvalue.static AbstractDurationAssert<?> Creates a new assumption's instance for aInstantvalue.static AbstractInstantAssert<?> Creates a new assumption's instance for anInstantvalue.static AbstractLocalDateAssert<?> Creates a new assumption's instance for aLocalDatevalue.static AbstractLocalDateTimeAssert<?> given(LocalDateTime actual) Creates a new assumption's instance for aLocalDateTimevalue.static AbstractLocalTimeAssert<?> Creates a new assumption's instance for aLocalTimevalue.static AbstractOffsetDateTimeAssert<?> given(OffsetDateTime actual) Creates a new assumption's instance for anOffsetDateTimevalue.static AbstractOffsetTimeAssert<?> given(OffsetTime actual) Creates a new assumption's instance for anOffsetTimevalue.static AbstractPeriodAssert<?> Creates a new assumption's instance for aPeriodvalue.static AbstractZonedDateTimeAssert<?> given(ZonedDateTime actual) Creates a new assumption's instance for aZonedDateTimevalue.static <E> AbstractCollectionAssert<?, Collection<? extends E>, E, ObjectAssert<E>> given(Collection<? extends E> actual) Creates a new assumption's instance for aCollectionvalue.static AtomicBooleanAssertgiven(AtomicBoolean actual) Creates a new assumption's instance for anAtomicBooleanvalue.static AtomicIntegerAssertgiven(AtomicInteger actual) Creates a new assumption's instance for anAtomicIntegervalue.static AtomicIntegerArrayAssertgiven(AtomicIntegerArray actual) Creates a new assumption's instance for anAtomicIntegerArrayvalue.static <OBJECT> AtomicIntegerFieldUpdaterAssert<OBJECT> given(AtomicIntegerFieldUpdater<OBJECT> actual) Creates a new assumption's instance for anAtomicIntegerFieldUpdatervalue.static AtomicLongAssertgiven(AtomicLong actual) Creates a new assumption's instance for anAtomicLongvalue.static AtomicLongArrayAssertgiven(AtomicLongArray actual) Creates a new assumption's instance for anAtomicLongArrayvalue.static <OBJECT> AtomicLongFieldUpdaterAssert<OBJECT> given(AtomicLongFieldUpdater<OBJECT> actual) Creates a new assumption's instance for anAtomicLongFieldUpdatervalue.static <VALUE> AtomicMarkableReferenceAssert<VALUE> given(AtomicMarkableReference<VALUE> actual) Creates a new assumption's instance for anAtomicMarkableReferencevalue.static <VALUE> AtomicReferenceAssert<VALUE> given(AtomicReference<VALUE> actual) Creates a new assumption's instance for anAtomicReferencevalue.static <ELEMENT> AtomicReferenceArrayAssert<ELEMENT> given(AtomicReferenceArray<ELEMENT> actual) Creates a new assumption's instance for anAtomicReferenceArrayvalue.static <FIELD,OBJECT>
AtomicReferenceFieldUpdaterAssert<FIELD, OBJECT> given(AtomicReferenceFieldUpdater<OBJECT, FIELD> actual) Creates a new assumption's instance for anAtomicReferenceFieldUpdatervalue.static <VALUE> AtomicStampedReferenceAssert<VALUE> given(AtomicStampedReference<VALUE> actual) Creates a new assumption's instance for anAtomicStampedReferencevalue.static LongAdderAssertCreates a new assumption's instance for aLongAddervalue.static <RESULT> CompletableFutureAssert<RESULT> given(CompletableFuture<RESULT> future) Creates a new assumption's instance for aCompletableFuturevalue.static <RESULT> CompletableFutureAssert<RESULT> given(CompletionStage<RESULT> stage) Creates a new assumption's instance for aCompletionStagevalue.static <RESULT> AbstractFutureAssert<?, ? extends Future<? extends RESULT>, RESULT> Creates a new assumption's instance for aFuturevalue.static AbstractDateAssert<?> Creates a new assumption's instance for aDatevalue.static DoublePredicateAssertgiven(DoublePredicate actual) Creates a new assumption's instance for aDoublePredicatevalue.static IntPredicateAssertgiven(IntPredicate actual) Creates a new assumption's instance for anIntPredicatevalue.static LongPredicateAssertgiven(LongPredicate actual) Creates a new assumption's instance for aLongPredicatevalue.static <T> PredicateAssert<T> Creates a new assumption's instance for aPredicatevalue.static <ELEMENT> IteratorAssert<ELEMENT> Creates a new assumption's instance for anIteratorvalue.static <ELEMENT> FactoryBasedNavigableListAssert<ListAssert<ELEMENT>, List<? extends ELEMENT>, ELEMENT, ObjectAssert<ELEMENT>> Creates a new assumption's instance for aListvalue.static <K,V> MapAssert <K, V> Creates a new assumption's instance for aMapvalue.static <VALUE> OptionalAssert<VALUE> Creates a new assumption's instance for anOptionalvalue.static OptionalDoubleAssertgiven(OptionalDouble actual) Creates a new assumption's instance for anOptionalDoublevalue.static OptionalIntAssertgiven(OptionalInt actual) Creates a new assumption's instance for anOptionalIntvalue.static OptionalLongAssertgiven(OptionalLong actual) Creates a new assumption's instance for anOptionalLongvalue.static MatcherAssertCreates a new assumption's instance for anMatcher.static <ELEMENT> AbstractSpliteratorAssert<?, ELEMENT> given(Spliterator<ELEMENT> actual) Creates a new assumption's instance for aSpliteratorvalue.static AbstractListAssert<?, List<? extends Double>, Double, ObjectAssert<Double>> given(DoubleStream actual) Creates a new assumption's instance for aDoubleStreamvalue.static AbstractListAssert<?, List<? extends Integer>, Integer, ObjectAssert<Integer>> Creates a new assumption's instance for anIntStreamvalue.static AbstractListAssert<?, List<? extends Long>, Long, ObjectAssert<Long>> given(LongStream actual) Creates a new assumption's instance for aLongStreamvalue.static <ELEMENT> AbstractListAssert<?, List<? extends ELEMENT>, ELEMENT, ObjectAssert<ELEMENT>> Creates a new assumption's instance for aStreamvalue.static <T> ObjectAssert<T> given(T actual) Creates a new assumption's instance for an object value.static <T> ObjectArrayAssert<T> given(T[] actual) Creates a new assumption's instance for an objects' array.static <T> Object2DArrayAssert<T> given(T[][] actual) Creates a new assumption's instance for an objects' two-dimensional array.static AbstractCharSequenceAssert<?, ? extends CharSequence> givenCharSequence(CharSequence actual) Creates a new assumption's instance for aCharSequencevalue.static AbstractThrowableAssert<?, ? extends Throwable> Creates a new assumption's instance from a no parameters lambda expression,() -> { /* some code */ }.static <E> AbstractCollectionAssert<?, Collection<? extends E>, E, ObjectAssert<E>> givenCollection(Collection<? extends E> actual) Creates a new assumption's instance of avalue.Collectionstatic <T extends Comparable<? super T>>
AbstractComparableAssert<?, T> givenComparable(T actual) Creates a new assumption's instance of avalue.Comparablestatic ThrowableTypeAssert<Exception> Alias forgivenExceptionOfType(Class)forException.static <T extends Throwable>
ThrowableTypeAssert<T> givenExceptionOfType(Class<? extends T> exceptionType) Creates a new assumption's instance for aThrowablevalue.Alias forgivenExceptionOfType(Class)forIllegalArgumentException.Alias forgivenExceptionOfType(Class)forIndexOutOfBoundsException.static ThrowableTypeAssert<IOException> Alias forgivenExceptionOfType(Class)forIOException.static <ELEMENT> IterableAssert<ELEMENT> givenIterable(Iterable<? extends ELEMENT> actual) Creates a new assumption's instance of anvalue.Iterablestatic <ELEMENT> IteratorAssert<ELEMENT> givenIterator(Iterator<? extends ELEMENT> actual) Creates a new assumption's instance of anvalue.Iteratorstatic <ELEMENT> FactoryBasedNavigableListAssert<ListAssert<ELEMENT>, List<? extends ELEMENT>, ELEMENT, ObjectAssert<ELEMENT>> Creates a new assumption's instance of avalue.ListAlias forgivenExceptionOfType(Class)forNullPointerException.static <T> ObjectAssert<T> givenObject(T actual) Creates a new assumption's instance for an object value.static AbstractPathAssert<?> Creates a new assumption's instance of avalue.Pathstatic <T> PredicateAssert<T> givenPredicate(Predicate<T> actual) Creates a new assumption's instance of avalue.PredicateAlias forgivenExceptionOfType(Class)forReflectiveOperationException.static ThrowableTypeAssert<RuntimeException> Alias forgivenExceptionOfType(Class)forRuntimeException.static <ELEMENT> AbstractListAssert<?, List<? extends ELEMENT>, ELEMENT, ObjectAssert<ELEMENT>> givenStream(Stream<? extends ELEMENT> actual) Creates a new assumption's instance of avalue.Streamstatic voidsetPreferredAssumptionException(PreferredAssumptionException preferredAssumptionException) Sets which exception is thrown if an assumption is not met.Methods inherited from class org.assertj.core.api.Assumptions
assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThat, assumeThatCharSequence, assumeThatCode, assumeThatCollection, assumeThatComparable, assumeThatException, assumeThatExceptionOfType, assumeThatIllegalArgumentException, assumeThatIndexOutOfBoundsException, assumeThatIOException, assumeThatIterable, assumeThatIterator, assumeThatList, assumeThatNullPointerException, assumeThatObject, assumeThatPath, assumeThatPredicate, assumeThatReflectiveOperationException, assumeThatRuntimeException, assumeThatStream, assumeThatTemporal, assumeThatThrownBy, generateAssumptionClass
-
Method Details
-
given
Creates a new assumption's instance for abooleanvalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(true).isTrue(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(true).isFalse(); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualbooleanvalue to be validated.- Returns:
- the
AbstractBooleanAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for aBooleanvalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(Boolean.valueOf(true)).isTrue(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(Boolean.valueOf(true)).isFalse(); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualBooleanvalue to be validated.- Returns:
- the
AbstractBooleanAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for abooleans' array.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new boolean[] { true, true }).contains(true); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new boolean[] { true, true }).contains(false); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualbooleans' array to be validated.- Returns:
- the
AbstractBooleanArrayAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for abooleans' two-dimensional array.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new boolean[][] {{true, true}, {false, false}}).contains(new boolean[] {true, true}, atIndex(0)); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new boolean[][] {{true, true}, {false, false}}).contains(new boolean[] {true, true}, atIndex(1)); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualbooleans' two-dimensional array to be validated.- Returns:
- the
Boolean2DArrayAssertassertion object to be used for assumptions. - Since:
- 3.17.0
-
given
Creates a new assumption's instance for abytevalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given((byte) 1).isOne(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given((byte) 1).isZero(); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualbytevalue to be validated.- Returns:
- the
AbstractByteAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for aBytevalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(Byte.valueOf("1")).isOne(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(Byte.valueOf("1")).isZero(); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualBytevalue to be validated.- Returns:
- the
AbstractByteAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for abytes' array.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new byte[] { 1, 2 }).contains((byte) 1); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new byte[] { 1, 2 }).contains((byte) 0); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actual bytes' array to be validated.- Returns:
- the
AbstractByteArrayAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for abytes' two-dimensional array.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new byte[][] {{1, 2}, {3, 4}}).contains(new byte[] {1, 2)}, atIndex(0)); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new byte[][] {{1, 2}, {3, 4}}).contains(new byte[] {1, 2)}, atIndex(1)); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actual bytes' two-dimensional array to be validated.- Returns:
- the
Byte2DArrayAssertassertion object to be used for assumptions. - Since:
- 3.17.0
-
given
Creates a new assumption's instance for ashortvalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given((short) 1).isOne(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given((short) 1).isZero(); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualshortvalue to be validated.- Returns:
- the
AbstractShortAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for aShortvalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(Short.valueOf("1")).isOne(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(Short.valueOf("1")).isZero(); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualShortvalue to be validated.- Returns:
- the
AbstractShortAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for ashorts' array.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new short[] { 1, 2 }).contains((short) 1); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new short[] { 1, 2 }).contains((short) 0); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualshorts' array to be validated.- Returns:
- the
AbstractShortArrayAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for ashorts' two-dimensional array.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new short[][] {{1, 2}, {3, 4}}).contains(new short[] {1, 2}, atIndex(0)); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new short[][] {{1, 2}, {3, 4}}).contains(new short[] {1, 2}, atIndex(1)); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualshorts' two-dimensional array to be validated.- Returns:
- the
Short2DArrayAssertassertion object to be used for assumptions. - Since:
- 3.17.0
-
given
Creates a new assumption's instance for anintvalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(1).isOne(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(1).isZero(); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualintvalue to be validated.- Returns:
- the
AbstractIntegerAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for anIntegervalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(Integer.valueOf("1")).isOne(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(Integer.valueOf("1")).isZero(); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualIntegervalue to be validated.- Returns:
- the
AbstractIntegerAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for anints' array.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new int[] { 1, 2 }).contains((short) 1); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new int[] { 1, 2 }).contains((short) 0); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualints' array to be validated.- Returns:
- the
AbstractIntArrayAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for anints' two-dimensional array.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new int[][] {{1, 2}, {3, 4}}).contains(new int[] {1, 2}, atIndex(0)); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new int[][] {{1, 2}, {3, 4}}).contains(new int[] {1, 2}, atIndex(1)); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualints' two-dimensional array to be validated.- Returns:
- the
Int2DArrayAssertassertion object to be used for assumptions. - Since:
- 3.17.0
-
given
Creates a new assumption's instance for aBigIntegervalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(BigInteger.valueOf(1L)).isOne(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(BigInteger.valueOf(1L)).isZero(); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualBigIntegervalue to be validated.- Returns:
- the
AbstractBigIntegerAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for alongvalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(1L).isOne(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(1L).isZero(); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actuallongvalue to be validated.- Returns:
- the
AbstractLongAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for aLongvalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(Long.valueOf(1L)).isOne(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(Long.valueOf(1L)).isZero(); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualLongvalue to be validated.- Returns:
- the
AbstractLongAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for alongs' array.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new long[] { 1, 2 }).contains(1L); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new long[] { 1, 2 }).contains(0L); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actuallongs' array to be validated.- Returns:
- the
AbstractLongArrayAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for alongs' two-dimensional array.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new long[][] {{1, 2}, {3, 4}}).contains(new long[] {1, 2}, atIndex(0)); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new long[][] {{1, 2}, {3, 4}}).contains(new long[] {1, 2}, atIndex(1)); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actuallongs' two-dimensional array to be validated.- Returns:
- the
Long2DArrayAssertassertion object to be used for assumptions. - Since:
- 3.17.0
-
given
Creates a new assumption's instance for afloatvalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(1.0f).isOne(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(1.0f).isZero(); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualfloatvalue to be validated.- Returns:
- the
AbstractFloatAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for aFloatvalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(Float.valueOf(1.0f)).isOne(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(Float.valueOf(1.0f)).isZero(); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualFloatvalue to be validated.- Returns:
- the
AbstractFloatAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for afloats' array.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new float[] { 1.0f, 2.0f }).contains(1.0f); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new float[] { 1.0f, 2.0f }).contains(0.0f); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualfloats' array to be validated.- Returns:
- the
AbstractFloatArrayAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for afloats' two-dimensional array.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new float[][] {{1.0f, 2.0f}, {3.0f, 4.0f}}).contains(new float[] {1.0f, 2.0f}, atIndex(0)); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new float[][] {{1.0f, 2.0f}, {3.0f, 4.0f}}).contains(new float[] {1.0f, 2.0f}, atIndex(1)); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualfloats' two-dimensional array to be validated.- Returns:
- the
Float2DArrayAssertassertion object to be used for assumptions. - Since:
- 3.17.0
-
given
Creates a new assumption's instance for adoublevalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(1.0).isOne(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(1.0).isZero(); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualdoublevalue to be validated.- Returns:
- the
AbstractDoubleAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for aDoublevalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(Double.valueOf(1.0f)).isOne(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(Double.valueOf(1.0f)).isZero(); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualDoublevalue to be validated.- Returns:
- the
AbstractDoubleAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for andoubles' array.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new double[] { 1.0, 2.0 }).contains(1.0); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new double[] { 1.0, 2.0 }).contains(0.0); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualdoubles' array to be validated.- Returns:
- the
AbstractDoubleArrayAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for andoubles' two-dimensional array.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new double[][] {{1.0, 2.0}, {3.0, 4.0}}).contains(new double[] {1.0, 2.0}, atIndex(0)); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new double[][] {{1.0, 2.0}, {3.0, 4.0}}).contains(new double[] {1.0, 2.0}, atIndex(1)); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualdoubles' two-dimensional array to be validated.- Returns:
- the
Double2DArrayAssertassertion object to be used for assumptions. - Since:
- 3.17.0
-
given
Creates a new assumption's instance for aBigDecimalvalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(BigDecimal.valueOf(1.0)).isOne(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(BigDecimal.valueOf(1.0)).isZero(); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualBigDecimalvalue to be validated.- Returns:
- the
AbstractBigDecimalAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for acharvalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given('A').isUpperCase(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given('A').isLowerCase(); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualcharvalue to be validated.- Returns:
- the
AbstractCharacterAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for aCharactervalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(Character.valueOf('A')).isUpperCase(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(Character.valueOf('A')).isLowerCase(); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualCharactervalue to be validated.- Returns:
- the
AbstractCharacterAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for anchars' array.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new char[] { 'A', 'B' }).contains('A'); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new char[] { 'A', 'B' }).contains('C'); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualchars' array to be validated.- Returns:
- the
AbstractCharacterAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for anchars' two-dimensional array.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new char[][] {{'A', 'B'}, {'C', 'D'}}).contains(new char[] {'A', 'B'}, atIndex(0)); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new char[][] {{'A', 'B'}, {'C', 'D'}}).contains(new char[] {'A', 'B'}, atIndex(1)); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualchars' two-dimensional array to be validated.- Returns:
- the
Char2DArrayAssertassertion object to be used for assumptions. - Since:
- 3.17.0
-
given
Creates a new assumption's instance for aCharSequencevalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given((CharSequence) "Yoda").isNotEmpty(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given((CharSequence) "Yoda").isNullOrEmpty(); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualCharSequencevalue to be validated.- Returns:
- the
AbstractCharSequenceAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
givenCharSequence
public static AbstractCharSequenceAssert<?,? extends CharSequence> givenCharSequence(CharSequence actual) Creates a new assumption's instance for aCharSequencevalue.Use this over
given(CharSequence)in case of ambiguous method resolution when the object under test implements several interfaces Assertj providesgivenfor.- Parameters:
actual- the actualCharSequencevalue to be validated.- Returns:
- the
AbstractCharSequenceAssertassertion object to be used for assumptions. - Since:
- 3.25.0
-
given
Creates a new assumption's instance for aStringvalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given("Yoda").isNotEmpty(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given("Yoda").isNullOrEmpty(); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualStringvalue to be validated.- Returns:
- the
AbstractStringAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for aStringBuildervalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new StringBuilder("Yoda")).isNotEmpty(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new StringBuilder("Yoda")).isNullOrEmpty(); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualStringBuildervalue to be validated.- Returns:
- the
AbstractCharSequenceAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for aStringBuffervalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new StringBuffer("Yoda")).isNotEmpty(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new StringBuffer("Yoda")).isNullOrEmpty(); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualStringBuffervalue to be validated.- Returns:
- the
AbstractCharSequenceAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for aClassvalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(Number.class).isAssignableFrom(Long.class); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(Number.class).isInterface(); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualClassvalue to be validated.- Returns:
- the
AbstractClassAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for an object value.Examples:
TolkienCharacter frodo = new TolkienCharacter("Frodo", 33, HOBBIT); TolkienCharacter mysteriousHobbit = new TolkienCharacter(null, 33, HOBBIT);Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(frodo).hasNoNullFieldsOrProperties(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(mysteriousHobbit).hasNoNullFieldsOrProperties(); // the remaining code is NOT executed. // ... }- Type Parameters:
T- the type of the actual object.- Parameters:
actual- the actual object to be validated.- Returns:
- the
AbstractObjectAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for an objects' array.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new String[] { "A", "B" }).hasSizeGreaterThan(1); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new String[] { "A", "B" }).hasSizeGreaterThan(2); // the remaining code is NOT executed. // ... }- Type Parameters:
T- the type of elements of the actual objects' array.- Parameters:
actual- the actual objects' array to be validated..- Returns:
- the
AbstractObjectArrayAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for an objects' two-dimensional array.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new String[][] {{"A", "B"}, {"C", "D"}}).contains(new String[] {"A", "B"}, atIndex(0)); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new String[][] {{"A", "B"}, {"C", "D"}}).contains(new String[] {"A", "B"}, atIndex(1)); // the remaining code is NOT executed. // ... }- Type Parameters:
T- the type of elements of the actual objects' two-dimensional array.- Parameters:
actual- the actual objects' two-dimensional array to be validated..- Returns:
- the
Object2DArrayAssertassertion object to be used for assumptions. - Since:
- 3.17.0
-
givenObject
Creates a new assumption's instance for an object value.This overload is useful, when an overloaded method of given(...) takes precedence over the generic
given(T), and the assumption requires to access some general assertion methods.Example:
given(List)takes precedence over the genericgiven(T)then when using some base general assert methods, e.g.
AbstractAssert.matches(Predicate), cast is necessary becausegiven(List)"forgets" actual type:
withgiven(new LinkedList<>(asList("abc"))).matches(list -> ((Deque<String>) list).getFirst().equals("abc"));givenObjectno cast is needed:givenObject(new LinkedList<>(asList("abc"))).matches(list -> list.getFirst().equals("abc"));- Type Parameters:
T- the type of the actual object.- Parameters:
actual- the actual object to be validated.- Returns:
- the
AbstractObjectAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for aComparablevalue.Examples:
class Yoda implements Comparable<Yoda> { public int compareTo(Yoda to) { return 0; } }Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new Yoda()).isEqualByComparingTo(new Yoda()); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new Yoda()).isNotEqualByComparingTo(new Yoda()); // the remaining code is NOT executed. // ... }- Type Parameters:
T- the type of the actual comparable value.- Parameters:
actual- the actualComparablevalue to be validated.- Returns:
- the
AbstractComparableAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
givenComparable
public static <T extends Comparable<? super T>> AbstractComparableAssert<?,T> givenComparable(T actual) Creates a new assumption's instance of avalue.ComparableUse this over
given(Comparable)in case of ambiguous method resolution when the object under test implements several interfaces Assertj providesgivenfor.- Type Parameters:
T- the type of elements.- Parameters:
actual- the actual value.- Returns:
- the created assumption for assertion object.
- Since:
- 3.23.0
-
given
Creates a new assumption's instance for aThrowablevalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new Exception("Yoda time")).hasMessage("Yoda time"); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new Exception("Yoda time")).hasMessage(""); // the remaining code is NOT executed. // ... }- Type Parameters:
T- the type of the actual throwable.- Parameters:
actual- the actualThrowablevalue to be validated.- Returns:
- the
AbstractThrowableAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
givenExceptionOfType
public static <T extends Throwable> ThrowableTypeAssert<T> givenExceptionOfType(Class<? extends T> exceptionType) Creates a new assumption's instance for aThrowablevalue.- Type Parameters:
T- the exception type.- Parameters:
exceptionType- the exception type class.- Returns:
- the created
ThrowableTypeAssert. - Since:
- 3.23.0
-
givenException
Alias forgivenExceptionOfType(Class)forException.- Returns:
- the
ThrowableAssertassertion object to be used for assumptions. - Since:
- 3.23.0
-
givenRuntimeException
Alias forgivenExceptionOfType(Class)forRuntimeException.- Returns:
- the
ThrowableAssertassertion object to be used for assumptions. - Since:
- 3.23.0
-
givenNullPointerException
Alias forgivenExceptionOfType(Class)forNullPointerException.- Returns:
- the
ThrowableAssertassertion object to be used for assumptions. - Since:
- 3.23.0
-
givenIllegalArgumentException
Alias forgivenExceptionOfType(Class)forIllegalArgumentException.- Returns:
- the
ThrowableAssertassertion object to be used for assumptions. - Since:
- 3.23.0
-
givenIOException
Alias forgivenExceptionOfType(Class)forIOException.- Returns:
- the
ThrowableAssertassertion object to be used for assumptions. - Since:
- 3.23.0
-
givenIndexOutOfBoundsException
Alias forgivenExceptionOfType(Class)forIndexOutOfBoundsException.- Returns:
- the
ThrowableAssertassertion object to be used for assumptions. - Since:
- 3.23.0
-
givenReflectiveOperationException
Alias forgivenExceptionOfType(Class)forReflectiveOperationException.- Returns:
- the
ThrowableAssertassertion object to be used for assumptions. - Since:
- 3.23.0
-
givenCode
public static AbstractThrowableAssert<?,? extends Throwable> givenCode(ThrowableAssert.ThrowingCallable lambda) Creates a new assumption's instance from a no parameters lambda expression,() -> { /* some code */ }.Examples:
No Exception required:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { givenCode(() -> {/* some code */ }).doesNotThrowAnyException(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { givenCode(() -> {/* some code */ }).hasMessage("Yoda time"); // the remaining code is NOT executed. // ... }Exception required:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { givenCode(() -> {throw new Exception("Yoda time");}).hasMessage("Yoda time"); // the remaining code is executed // ...Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { givenCode(() -> {throw new Exception("Yoda time");}).doesNotThrowAnyException(); // the remaining code is NOT executed. // ...- Parameters:
lambda- theThrowableAssert.ThrowingCallableor lambda with the code that may raise a throwable to be validated.- Returns:
- the
AbstractThrowableAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for anIterablevalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given((Iterable<Integer>)(Arrays.asList(1, 2))).contains(2); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given((Iterable<Integer>)(Arrays.asList(1, 2))).containsOnly(2); // the remaining code is NOT executed. // ... }- Type Parameters:
ELEMENT- the type of elements of actual iterable value.- Parameters:
actual- the actualIterablevalue to be validated.- Returns:
- the
AbstractIterableAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
givenIterable
Creates a new assumption's instance of anvalue.IterableUse this over
given(Iterable)in case of ambiguous method resolution when the object under test implements several interfaces Assertj providesgivenfor.- Type Parameters:
ELEMENT- the type of elements of actual iterable value.- Parameters:
actual- the actualIterablevalue to be validated.- Returns:
- the
AbstractIterableAssertassertion object to be used for assumptions. - Since:
- 3.23.0
-
given
Creates a new assumption's instance for anIteratorvalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(Arrays.asList(1, 2).iterator()).hasNext(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(Arrays.asList(1, 2).iterator()).isExhausted(); // the remaining code is NOT executed. // ... }- Type Parameters:
ELEMENT- the type of elements of actual iterator value.- Parameters:
actual- the actualIteratorvalue to be validated.- Returns:
- the
AbstractIteratorAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
givenIterator
Creates a new assumption's instance of anvalue.IteratorUse this over
given(Iterator)in case of ambiguous method resolution when the object under test implements several interfaces Assertj providesgivenfor.- Type Parameters:
ELEMENT- the type of elements of actual iterable value.- Parameters:
actual- the actualIteratorvalue to be validated.- Returns:
- the
AbstractIteratorAssertassertion object to be used for assumptions. - Since:
- 3.23.0
-
given
public static <E> AbstractCollectionAssert<?,Collection<? extends E>, givenE, ObjectAssert<E>> (Collection<? extends E> actual) Creates a new assumption's instance for aCollectionvalue.- Type Parameters:
E- the type of elements.- Parameters:
actual- the actual value.- Returns:
- the created assumption for assertion object.
- Since:
- 3.21.0
- See Also:
-
givenCollection
public static <E> AbstractCollectionAssert<?,Collection<? extends E>, givenCollectionE, ObjectAssert<E>> (Collection<? extends E> actual) Creates a new assumption's instance of avalue.CollectionUse this over
given(Collection)in case of ambiguous method resolution when the object under test implements several interfaces Assertj providesgivenfor.- Type Parameters:
E- the type of elements.- Parameters:
actual- the actual value.- Returns:
- the created assumption for assertion object.
- Since:
- 3.23.0
-
given
public static <ELEMENT> FactoryBasedNavigableListAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>, givenELEMENT, ObjectAssert<ELEMENT>> (List<? extends ELEMENT> actual) Creates a new assumption's instance for aListvalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(Arrays.asList(1, 2)).contains(2); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(Arrays.asList(1, 2)).containsOnly(2); // the remaining code is NOT executed. // ... }- Type Parameters:
ELEMENT- the type of elements of actual list value.- Parameters:
actual- the actualListvalue to be validated.- Returns:
- the
AbstractListAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
givenList
public static <ELEMENT> FactoryBasedNavigableListAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>, givenListELEMENT, ObjectAssert<ELEMENT>> (List<? extends ELEMENT> actual) Creates a new assumption's instance of avalue.ListUse this over
given(List)in case of ambiguous method resolution when the object under test implements several interfaces Assertj providesgivenfor.- Type Parameters:
ELEMENT- the type of elements.- Parameters:
actual- the actual value.- Returns:
- the
AbstractListAssertassertion object to be used for assumptions. - Since:
- 3.23.0
-
given
Creates a new assumption's instance for aMapvalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(Collections.singletonMap(1, 2)).containsEntry(1, 2); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(Collections.singletonMap(1, 2)).containsEntry(2, 1); // the remaining code is NOT executed. // ... }- Type Parameters:
K- the type of keys in the actual map value.V- the type of values in the actual map value.- Parameters:
actual- the actualMapvalue to be validated.- Returns:
- the
AbstractMapAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for aPredicatevalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given((Predicate<Integer>)(value -> value > 0)).accepts(1, 2); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given((Predicate<Integer>)(value -> value > 0)).accepts(-2, -1); // the remaining code is NOT executed. // ... }- Type Parameters:
T- the type of the value contained in the actual predicate value.- Parameters:
actual- the actualPredicatevalue to be validated.- Returns:
- the
AbstractPredicateAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
givenPredicate
Creates a new assumption's instance of avalue.PredicateUse this over
given(Predicate)in case of ambiguous method resolution when the object under test implements several interfaces Assertj providesgivenfor.- Type Parameters:
T- the type of elements.- Parameters:
actual- the actual value.- Returns:
- the
AbstractPredicateAssertassertion object to be used for assumptions. - Since:
- 3.23.0
-
given
Creates a new assumption's instance for anIntPredicatevalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given((IntPredicate)(value -> value > 0)).accepts(1, 2); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given((IntPredicate)(value -> value > 0)).accepts(-2, -1); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualIntPredicatevalue to be validated.- Returns:
- the
IntPredicateAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for aLongPredicatevalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given((LongPredicate)(value -> value > 0)).accepts(1, 2); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given((LongPredicate)(value -> value > 0)).accepts(-2, -1); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualLongPredicatevalue to be validated.- Returns:
- the
LongPredicateAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for aDoublePredicatevalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given((DoublePredicate)(value -> value > 0)).accepts(1.0, 2.0); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given((DoublePredicate)(value -> value > 0)).accepts(-2.0, -1.0); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualDoublePredicatevalue to be validated.- Returns:
- the
DoublePredicateAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for anOptionalvalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(Optional.empty()).isEmpty(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(Optional.empty()).isNotEmpty(); // the remaining code is NOT executed. // ... }- Type Parameters:
VALUE- the type of the value contained in the actual optional value.- Parameters:
actual- the actualOptionalvalue to be validated.- Returns:
- the
OptionalAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for anOptionalIntvalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(OptionalInt.empty()).isEmpty(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(OptionalInt.empty()).isNotEmpty(); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualOptionalIntvalue to be validated.- Returns:
- the
OptionalIntAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for anMatcher. -
given
Creates a new assumption's instance for anOptionalLongvalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(OptionalLong.empty()).isEmpty(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(OptionalLong.empty()).isNotEmpty(); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualOptionalLongvalue to be validated.- Returns:
- the
OptionalLongAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for anOptionalDoublevalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(OptionalDouble.empty()).isEmpty(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(OptionalDouble.empty()).isNotEmpty(); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualOptionalDoublevalue to be validated.- Returns:
- the
OptionalDoubleAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
public static <ELEMENT> AbstractListAssert<?,List<? extends ELEMENT>, givenELEMENT, ObjectAssert<ELEMENT>> (Stream<? extends ELEMENT> actual) Creates a new assumption's instance for aStreamvalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(Stream.of(1, 2)).contains(2); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(Stream.of(1, 2)).containsOnly(2); // the remaining code is NOT executed. // ... }- Type Parameters:
ELEMENT- the type of the value contained in the actual stream value.- Parameters:
actual- the actualStreamvalue to be validated.- Returns:
- the
AbstractListAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
givenStream
public static <ELEMENT> AbstractListAssert<?,List<? extends ELEMENT>, givenStreamELEMENT, ObjectAssert<ELEMENT>> (Stream<? extends ELEMENT> actual) Creates a new assumption's instance of avalue.StreamUse this over
given(Stream)in case of ambiguous method resolution when the object under test implements several interfaces Assertj providesgivenfor.- Type Parameters:
ELEMENT- the type of elements.- Parameters:
actual- the actualStreamvalue to be validated.- Returns:
- the
AbstractListAssertassertion object to be used for assumptions. - Since:
- 3.23.0
-
given
public static AbstractListAssert<?,List<? extends Integer>, givenInteger, ObjectAssert<Integer>> (IntStream actual) Creates a new assumption's instance for anIntStreamvalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(IntStream.of(1, 2)).contains(2); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(IntStream.of(1, 2)).containsOnly(2); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualIntStreamvalue to be validated.- Returns:
- the
AbstractListAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for aSpliteratorvalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(Stream.of(1, 2).spliterator()).hasCharacteristics(Spliterator.SIZED) // the remaining code is executed ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(Stream.of(1, 2).spliterator()).hasCharacteristics(Spliterator.DISTINCT) // the remaining code is NOT executed. }- Type Parameters:
ELEMENT- the type of the elements- Parameters:
actual- the actualSpliteratorvalue to be validated.- Returns:
- the
AbstractSpliteratorAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
public static AbstractListAssert<?,List<? extends Long>, givenLong, ObjectAssert<Long>> (LongStream actual) Creates a new assumption's instance for aLongStreamvalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(LongStream.of(1, 2)).contains(2); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(LongStream.of(1, 2)).containsOnly(2); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualLongStreamvalue to be validated.- Returns:
- the
AbstractListAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
public static AbstractListAssert<?,List<? extends Double>, givenDouble, ObjectAssert<Double>> (DoubleStream actual) Creates a new assumption's instance for aDoubleStreamvalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(DoubleStream.of(1.0, 2.0)).contains(2.0); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(DoubleStream.of(1.0, 2.0)).containsOnly(2.0); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualDoubleStreamvalue to be validated.- Returns:
- the
AbstractListAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
public static <RESULT> AbstractFutureAssert<?,? extends Future<? extends RESULT>, givenRESULT> (Future<RESULT> future) Creates a new assumption's instance for aFuturevalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(Executors.newSingleThreadExecutor().submit(() -> {})).isNotCancelled(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(Executors.newSingleThreadExecutor().submit(() -> {})).isCancelled(); // the remaining code is NOT executed. // ... }- Type Parameters:
RESULT- the type of the value contained in the actual future value.- Parameters:
future- theFuturevalue to be validated.- Returns:
- the
AbstractFutureAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for aCompletableFuturevalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(CompletableFuture.completedFuture(1)).isDone(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(CompletableFuture.completedFuture(1)).isNotDone(); // the remaining code is NOT executed. // ... }- Type Parameters:
RESULT- the type of the value contained in the actual future value.- Parameters:
future- theCompletableFuturevalue to be validated.- Returns:
- the
AbstractCompletableFutureAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for aCompletionStagevalue.Converts the
CompletionStageinto aCompletableFuture. If the givenCompletionStageis null, the associatedCompletableFuturewill also be null.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given((CompletionStage<Integer>) CompletableFuture.completedFuture(1)).isDone(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given((CompletionStage<Integer>) CompletableFuture.completedFuture(1)).isNotDone(); // the remaining code is NOT executed. // ... }- Type Parameters:
RESULT- the type of the value contained in the actual future value.- Parameters:
stage- theCompletionStagevalue to be validated.- Returns:
- the
AbstractCompletableFutureAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for anAtomicBooleanvalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new AtomicBoolean(true)).isTrue(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new AtomicBoolean(true)).isFalse(); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualAtomicBooleanvalue to be validated.- Returns:
- the
AtomicBooleanAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for anAtomicIntegervalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new AtomicInteger(1)).hasNonNegativeValue(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new AtomicInteger(1)).hasNegativeValue(); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualAtomicIntegervalue to be validated.- Returns:
- the
AtomicIntegerAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for anAtomicIntegerArrayvalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new AtomicIntegerArray(0)).isEmpty(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new AtomicIntegerArray(0)).isNotEmpty(); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualAtomicIntegerArrayvalue to be validated.- Returns:
- the
AtomicIntegerArrayAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
public static <OBJECT> AtomicIntegerFieldUpdaterAssert<OBJECT> given(AtomicIntegerFieldUpdater<OBJECT> actual) Creates a new assumption's instance for anAtomicIntegerFieldUpdatervalue.Examples:
class Yoda { public volatile int field = 0; }AtomicIntegerFieldUpdater actual = AtomicIntegerFieldUpdater.newUpdater(Yoda.class, "field"); Yoda value = new Yoda(); actual.set(value, 1);Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(actual).hasValue(1, value); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(actual).hasValue(2, value)); // the remaining code is NOT executed. // ... }- Type Parameters:
OBJECT- the type of the object holding the updatable field which gets updated by the actual value.- Parameters:
actual- the actualAtomicIntegerFieldUpdatervalue to be validated.- Returns:
- the
AtomicIntegerFieldUpdaterAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for aLongAddervalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new LongAdder()).isNotNegative(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new LongAdder()).isNegative(); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualLongAddervalue to be validated.- Returns:
- the
LongAdderAssertassertion object to be used for assumptions. - Since:
- 3.16.0
-
given
Creates a new assumption's instance for anAtomicLongvalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new AtomicLong(1L)).hasNonNegativeValue(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new AtomicLong(1L)).hasNegativeValue(); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualAtomicLongvalue to be validated.- Returns:
- the
AtomicLongAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for anAtomicLongArrayvalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new AtomicLongArray(0)).isEmpty(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new AtomicLongArray(0)).isNotEmpty(); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualAtomicLongArrayvalue to be validated.- Returns:
- the
AtomicLongArrayAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
public static <OBJECT> AtomicLongFieldUpdaterAssert<OBJECT> given(AtomicLongFieldUpdater<OBJECT> actual) Creates a new assumption's instance for anAtomicLongFieldUpdatervalue.Examples:
class Yoda { public volatile long field = 0L; }AtomicLongFieldUpdater actual = AtomicLongFieldUpdater.newUpdater(Yoda.class, "field"); Yoda value = new Yoda(); actual.set(value, 1L);Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(actual).hasValue(1L, value); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(actual).hasValue(2L, value)); // the remaining code is NOT executed. // ... }- Type Parameters:
OBJECT- the type of the object holding the updatable field which gets updated by the actual value.- Parameters:
actual- the actualAtomicLongFieldUpdatervalue to be validated.- Returns:
- the
AtomicLongFieldUpdaterAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for anAtomicReferencevalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new AtomicReference("Yoda")).hasValue("Yoda"); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new AtomicReference("Yoda")).doesNotHaveValue("Yoda"); // the remaining code is NOT executed. // ... }- Type Parameters:
VALUE- the type of the value contained by the actual reference.- Parameters:
actual- the actualAtomicReferenceto be validated.- Returns:
- the
AtomicReferenceAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
public static <ELEMENT> AtomicReferenceArrayAssert<ELEMENT> given(AtomicReferenceArray<ELEMENT> actual) Creates a new assumption's instance for anAtomicReferenceArrayvalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new AtomicReferenceArray(0)).isEmpty(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new AtomicReferenceArray(0)).isNotEmpty(); // the remaining code is NOT executed. // ... }- Type Parameters:
ELEMENT- the type of the value contained in the actual references' array.- Parameters:
actual- the actualAtomicReferenceArrayto be validated.- Returns:
- the
AtomicReferenceArrayAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
public static <FIELD,OBJECT> AtomicReferenceFieldUpdaterAssert<FIELD,OBJECT> given(AtomicReferenceFieldUpdater<OBJECT, FIELD> actual) Creates a new assumption's instance for anAtomicReferenceFieldUpdatervalue.Examples:
class Yoda { public volatile String field = ""; }AtomicReferenceFieldUpdater actual = AtomicReferenceFieldUpdater.newUpdater(Yoda.class, String.class, "field"); Yoda value = new Yoda(); actual.set(value, "Yoda");Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(actual).hasValue("Yoda", value)); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(actual).hasValue("", value)); // the remaining code is NOT executed. // ... }- Type Parameters:
FIELD- the type of the field which gets updated by the actual updater.OBJECT- the type of the object holding the updatable field which gets updated by the actual updater.- Parameters:
actual- the actualAtomicReferenceFieldUpdatervalue to be validated.- Returns:
- the
AtomicReferenceFieldUpdaterAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
public static <VALUE> AtomicMarkableReferenceAssert<VALUE> given(AtomicMarkableReference<VALUE> actual) Creates a new assumption's instance for anAtomicMarkableReferencevalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new AtomicMarkableReference("Yoda", true)).isMarked(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new AtomicMarkableReference("Yoda", true)).isNotMarked(); // the remaining code is NOT executed. // ... }- Type Parameters:
VALUE- the type of the value contained by the actual reference.- Parameters:
actual- the actualAtomicMarkableReferenceto be validated.- Returns:
- the
AtomicMarkableReferenceAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
public static <VALUE> AtomicStampedReferenceAssert<VALUE> given(AtomicStampedReference<VALUE> actual) Creates a new assumption's instance for anAtomicStampedReferencevalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new AtomicStampedReference("Yoda", 1)).hasStamp(1); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new AtomicStampedReference("Yoda", 1)).hasStamp(0); // the remaining code is NOT executed. // ... }- Type Parameters:
VALUE- the type of the value contained by the actual reference.- Parameters:
actual- the actualAtomicStampedReferenceto be validated.- Returns:
- the
AtomicStampedReferenceAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for aDatevalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(Date.from(Instant.parse("2014-12-03T10:15:30Z"))).isBefore("2016-12-03T10:15:30Z"); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(Date.from(Instant.parse("2014-12-03T10:15:30Z"))).isAfter("2016-12-03T10:15:30Z"); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualDatevalue to be validated.- Returns:
- the
AbstractDateAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for aLocalDatevalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(LocalDate.now()).isBeforeOrEqualTo(LocalDate.now()); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(LocalDate.now()).isAfter(LocalDate.now()); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualLocalDatevalue to be validated.- Returns:
- the
AbstractLocalDateAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for aLocalTimevalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(LocalTime.now()).isBeforeOrEqualTo(LocalTime.now()); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(LocalTime.now()).isAfter(LocalTime.now()); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualLocalTimevalue to be validated.- Returns:
- the
AbstractLocalTimeAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for anOffsetTimevalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(OffsetTime.now()).isBeforeOrEqualTo(OffsetTime.now()); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(OffsetTime.now()).isAfter(OffsetTime.now()); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualOffsetTimevalue to be validated.- Returns:
- the
AbstractOffsetTimeAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for aLocalDateTimevalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(LocalDateTime.now()).isBeforeOrEqualTo(LocalDateTime.now()); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(LocalDateTime.now()).isAfter(LocalDateTime.now()); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualLocalDateTimevalue to be validated.- Returns:
- the
AbstractLocalDateTimeAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for anInstantvalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(Instant.now()).isBeforeOrEqualTo(Instant.now()); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(Instant.now()).isAfter(Instant.now()); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualInstantvalue to be validated.- Returns:
- the
AbstractInstantAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for aInstantvalue.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.15.0
-
given
Creates a new assumption's instance for aPeriodvalue.- Parameters:
actual- the actual value.- Returns:
- the created assertion object.
- Since:
- 3.17.0
-
given
Creates a new assumption's instance for anOffsetDateTimevalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(OffsetDateTime.now()).isBeforeOrEqualTo(OffsetDateTime.now()); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(OffsetDateTime.now()).isAfter(OffsetDateTime.now()); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualOffsetDateTimevalue to be validated.- Returns:
- the
AbstractOffsetDateTimeAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for aZonedDateTimevalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(ZonedDateTime.now()).isBeforeOrEqualTo(ZonedDateTime.now()); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(ZonedDateTime.now()).isAfter(ZonedDateTime.now()); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualZonedDateTimevalue to be validated.- Returns:
- the
AbstractZonedDateTimeAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for anInputStreamvalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new ByteArrayInputStream("A".getBytes())).hasContent("A"); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new ByteArrayInputStream("A".getBytes())).hasContent("B"); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualInputStreamvalue to be validated.- Returns:
- the
AbstractInputStreamAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for aFilevalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new File("file.ext")).isRelative(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new File("file.ext")).isAbsolute(); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualFilevalue to be validated.- Returns:
- the
AbstractFileAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for aPathvalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new File("file.ext").toPath()).isRelative(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new File("file.ext").toPath()).isAbsolute(); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualPathvalue to be validated.- Returns:
- the
AbstractPathAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
givenPath
Creates a new assumption's instance of avalue.PathUse this over
given(Path)in case of ambiguous method resolution when the object under test implements several interfaces Assertj providesgivenfor.- Parameters:
actual- the actualPathvalue to be validated.- Returns:
- the
AbstractPathAssertassertion object to be used for assumptions. - Since:
- 3.23.0
-
given
Creates a new assumption's instance for anURIvalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new URI("http://assertj.org")).hasNoPort(); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new URI("http://assertj.org")).hasPort(80); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualURIvalue to be validated.- Returns:
- the
AbstractUriAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
given
Creates a new assumption's instance for anURLvalue.Examples:
Executed test:
@Test public void given_the_assumption_is_met_the_test_is_executed() { given(new URL("http://assertj.org")).hasProtocol("http"); // the remaining code is executed // ... }Skipped test:
@Test public void given_the_assumption_is_not_met_the_test_is_skipped() { given(new URL("http://assertj.org")).hasPort(80); // the remaining code is NOT executed. // ... }- Parameters:
actual- the actualURLvalue to be validated.- Returns:
- the
AbstractUrlAssertassertion object to be used for assumptions. - Since:
- 3.14.0
-
setPreferredAssumptionException
public static void setPreferredAssumptionException(PreferredAssumptionException preferredAssumptionException) Sets which exception is thrown if an assumption is not met.This method is useful if you are using a testing framework that supports assumptions and expect a specific exception to be thrown when an assumption is not met.
You can choose one of:
PreferredAssumptionException.TEST_NGto throw aorg.testng.SkipExceptionif you are using TestNGPreferredAssumptionException.JUNIT4to throw aorg.junit.AssumptionViolatedExceptionif you are using JUnit 4PreferredAssumptionException.JUNIT5aorg.opentest4j.TestAbortedExceptionif you are using JUnit 5PreferredAssumptionException.AUTO_DETECTto get the default behavior where AssertJ tries different exception (explained later on)
Make sure that the exception you choose can be found in the classpath otherwise AssertJ will throw an
IllegalStateException.For example JUnit4 expects
org.junit.AssumptionViolatedException, you can tell AssertJ to use it as shown below:// after this call, AssertJ will throw an org.junit.AssumptionViolatedException when an assumption is not met Assertions.setPreferredAssumptionExceptions(PreferredAssumptionException.JUNIT4);By default, AssertJ uses the
AUTO_DETECTmode and tries to throw one of the following exceptions, in this order:org.testng.SkipExceptionfor TestNG (if available in the classpath)org.junit.AssumptionViolatedExceptionfor JUnit 4 (if available in the classpath)org.opentest4j.TestAbortedExceptionfor JUnit 5
- Parameters:
preferredAssumptionException- the preferred exception to use withBDDAssumptions.- Since:
- 3.21.0
-