public final class BDDAssumptions extends Assumptions
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");
}| Modifier and Type | Method and Description |
|---|---|
static AtomicBooleanAssert |
given(AtomicBoolean actual)
Creates a new assumption's instance for an
AtomicBoolean value. |
static AtomicIntegerAssert |
given(AtomicInteger actual)
Creates a new assumption's instance for an
AtomicInteger value. |
static AtomicIntegerArrayAssert |
given(AtomicIntegerArray actual)
Creates a new assumption's instance for an
AtomicIntegerArray value. |
static <OBJECT> AtomicIntegerFieldUpdaterAssert<OBJECT> |
given(AtomicIntegerFieldUpdater<OBJECT> actual)
Creates a new assumption's instance for an
AtomicIntegerFieldUpdater value. |
static AtomicLongAssert |
given(AtomicLong actual)
Creates a new assumption's instance for an
AtomicLong value. |
static AtomicLongArrayAssert |
given(AtomicLongArray actual)
Creates a new assumption's instance for an
AtomicLongArray value. |
static <OBJECT> AtomicLongFieldUpdaterAssert<OBJECT> |
given(AtomicLongFieldUpdater<OBJECT> actual)
Creates a new assumption's instance for an
AtomicLongFieldUpdater value. |
static <VALUE> AtomicMarkableReferenceAssert<VALUE> |
given(AtomicMarkableReference<VALUE> actual)
Creates a new assumption's instance for an
AtomicMarkableReference value. |
static <VALUE> AtomicReferenceAssert<VALUE> |
given(AtomicReference<VALUE> actual)
Creates a new assumption's instance for an
AtomicReference value. |
static <ELEMENT> AtomicReferenceArrayAssert<ELEMENT> |
given(AtomicReferenceArray<ELEMENT> actual)
Creates a new assumption's instance for an
AtomicReferenceArray value. |
static <FIELD,OBJECT> |
given(AtomicReferenceFieldUpdater<OBJECT,FIELD> actual)
Creates a new assumption's instance for an
AtomicReferenceFieldUpdater value. |
static <VALUE> AtomicStampedReferenceAssert<VALUE> |
given(AtomicStampedReference<VALUE> actual)
Creates a new assumption's instance for an
AtomicStampedReference value. |
static AbstractBigDecimalAssert<?> |
given(BigDecimal actual)
Creates a new assumption's instance for a
BigDecimal value. |
static AbstractBigIntegerAssert<?> |
given(BigInteger actual)
Creates a new assumption's instance for a
BigInteger value. |
static AbstractBooleanAssert<?> |
given(boolean actual)
Creates a new assumption's instance for a
boolean value. |
static AbstractBooleanAssert<?> |
given(Boolean actual)
Creates a new assumption's instance for a
Boolean value. |
static AbstractBooleanArrayAssert<?> |
given(boolean[] actual)
Creates a new assumption's instance for a
booleans' array. |
static Boolean2DArrayAssert |
given(boolean[][] actual)
Creates a new assumption's instance for a
booleans' two-dimensional array. |
static AbstractByteAssert<?> |
given(byte actual)
Creates a new assumption's instance for a
byte value. |
static AbstractByteAssert<?> |
given(Byte actual)
Creates a new assumption's instance for a
Byte value. |
static AbstractByteArrayAssert<?> |
given(byte[] actual)
Creates a new assumption's instance for a
bytes' array. |
static Byte2DArrayAssert |
given(byte[][] actual)
Creates a new assumption's instance for a
bytes' two-dimensional array. |
static AbstractCharacterAssert<?> |
given(char actual)
Creates a new assumption's instance for a
char value. |
static AbstractCharArrayAssert<?> |
given(char[] actual)
Creates a new assumption's instance for an
chars' array. |
static Char2DArrayAssert |
given(char[][] actual)
Creates a new assumption's instance for an
chars' two-dimensional array. |
static AbstractCharacterAssert<?> |
given(Character actual)
Creates a new assumption's instance for a
Character value. |
static AbstractCharSequenceAssert<?,? extends CharSequence> |
given(CharSequence actual)
Creates a new assumption's instance for a
CharSequence value. |
static ClassAssert |
given(Class<?> actual)
Creates a new assumption's instance for a
Class value. |
static <E> AbstractCollectionAssert<?,Collection<? extends E>,E,ObjectAssert<E>> |
given(Collection<? extends E> actual)
Creates a new assumption's instance for a
Collection value. |
static <RESULT> CompletableFutureAssert<RESULT> |
given(CompletableFuture<RESULT> future)
Creates a new assumption's instance for a
CompletableFuture value. |
static <RESULT> CompletableFutureAssert<RESULT> |
given(CompletionStage<RESULT> stage)
Creates a new assumption's instance for a
CompletionStage value. |
static AbstractDateAssert<?> |
given(Date actual)
Creates a new assumption's instance for a
Date value. |
static AbstractDoubleAssert<?> |
given(double actual)
Creates a new assumption's instance for a
double value. |
static AbstractDoubleAssert<?> |
given(Double actual)
Creates a new assumption's instance for a
Double value. |
static AbstractDoubleArrayAssert<?> |
given(double[] actual)
Creates a new assumption's instance for an
doubles' array. |
static Double2DArrayAssert |
given(double[][] actual)
Creates a new assumption's instance for an
doubles' two-dimensional array. |
static DoublePredicateAssert |
given(DoublePredicate actual)
Creates a new assumption's instance for a
DoublePredicate value. |
static AbstractListAssert<?,List<? extends Double>,Double,ObjectAssert<Double>> |
given(DoubleStream actual)
Creates a new assumption's instance for a
DoubleStream value. |
static AbstractDurationAssert<?> |
given(Duration actual)
Creates a new assumption's instance for a
Instant value. |
static AbstractFileAssert<?> |
given(File actual)
Creates a new assumption's instance for a
File value. |
static AbstractFloatAssert<?> |
given(float actual)
Creates a new assumption's instance for a
float value. |
static AbstractFloatAssert<?> |
given(Float actual)
Creates a new assumption's instance for a
Float value. |
static AbstractFloatArrayAssert<?> |
given(float[] actual)
Creates a new assumption's instance for a
floats' array. |
static Float2DArrayAssert |
given(float[][] actual)
Creates a new assumption's instance for a
floats' two-dimensional array. |
static <RESULT> AbstractFutureAssert<?,? extends Future<? extends RESULT>,RESULT> |
given(Future<RESULT> future)
Creates a new assumption's instance for a
Future value. |
static AbstractInputStreamAssert<?,? extends InputStream> |
given(InputStream actual)
Creates a new assumption's instance for an
InputStream value. |
static AbstractInstantAssert<?> |
given(Instant actual)
Creates a new assumption's instance for an
Instant value. |
static AbstractIntegerAssert<?> |
given(int actual)
Creates a new assumption's instance for an
int value. |
static AbstractIntArrayAssert<?> |
given(int[] actual)
Creates a new assumption's instance for an
ints' array. |
static Int2DArrayAssert |
given(int[][] actual)
Creates a new assumption's instance for an
ints' two-dimensional array. |
static AbstractIntegerAssert<?> |
given(Integer actual)
Creates a new assumption's instance for an
Integer value. |
static IntPredicateAssert |
given(IntPredicate actual)
Creates a new assumption's instance for an
IntPredicate value. |
static AbstractListAssert<?,List<? extends Integer>,Integer,ObjectAssert<Integer>> |
given(IntStream actual)
Creates a new assumption's instance for an
IntStream value. |
static <ELEMENT> IterableAssert<ELEMENT> |
given(Iterable<? extends ELEMENT> actual)
Creates a new assumption's instance for an
Iterable value. |
static <ELEMENT> IteratorAssert<ELEMENT> |
given(Iterator<? extends ELEMENT> actual)
Creates a new assumption's instance for an
Iterator value. |
static <ELEMENT> FactoryBasedNavigableListAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>> |
given(List<? extends ELEMENT> actual)
Creates a new assumption's instance for a
List value. |
static AbstractLocalDateAssert<?> |
given(LocalDate actual)
Creates a new assumption's instance for a
LocalDate value. |
static AbstractLocalDateTimeAssert<?> |
given(LocalDateTime actual)
Creates a new assumption's instance for a
LocalDateTime value. |
static AbstractLocalTimeAssert<?> |
given(LocalTime actual)
Creates a new assumption's instance for a
LocalTime value. |
static AbstractLongAssert<?> |
given(long actual)
Creates a new assumption's instance for a
long value. |
static AbstractLongAssert<?> |
given(Long actual)
Creates a new assumption's instance for a
Long value. |
static AbstractLongArrayAssert<?> |
given(long[] actual)
Creates a new assumption's instance for a
longs' array. |
static Long2DArrayAssert |
given(long[][] actual)
Creates a new assumption's instance for a
longs' two-dimensional array. |
static LongAdderAssert |
given(LongAdder actual)
Creates a new assumption's instance for a
LongAdder value. |
static LongPredicateAssert |
given(LongPredicate actual)
Creates a new assumption's instance for a
LongPredicate value. |
static AbstractListAssert<?,List<? extends Long>,Long,ObjectAssert<Long>> |
given(LongStream actual)
Creates a new assumption's instance for a
LongStream value. |
static <K,V> MapAssert<K,V> |
given(Map<K,V> actual)
Creates a new assumption's instance for a
Map value. |
static MatcherAssert |
given(Matcher actual)
Creates a new assumption's instance for an
Matcher. |
static AbstractOffsetDateTimeAssert<?> |
given(OffsetDateTime actual)
Creates a new assumption's instance for an
OffsetDateTime value. |
static AbstractOffsetTimeAssert<?> |
given(OffsetTime actual)
Creates a new assumption's instance for an
OffsetTime value. |
static <VALUE> OptionalAssert<VALUE> |
given(Optional<VALUE> actual)
Creates a new assumption's instance for an
Optional value. |
static OptionalDoubleAssert |
given(OptionalDouble actual)
Creates a new assumption's instance for an
OptionalDouble value. |
static OptionalIntAssert |
given(OptionalInt actual)
Creates a new assumption's instance for an
OptionalInt value. |
static OptionalLongAssert |
given(OptionalLong actual)
Creates a new assumption's instance for an
OptionalLong value. |
static AbstractPathAssert<?> |
given(Path actual)
Creates a new assumption's instance for a
Path value. |
static AbstractPeriodAssert<?> |
given(Period actual)
Creates a new assumption's instance for a
Period value. |
static <T> PredicateAssert<T> |
given(Predicate<T> actual)
Creates a new assumption's instance for a
Predicate value. |
static AbstractShortAssert<?> |
given(short actual)
Creates a new assumption's instance for a
short value. |
static AbstractShortAssert<?> |
given(Short actual)
Creates a new assumption's instance for a
Short value. |
static AbstractShortArrayAssert<?> |
given(short[] actual)
Creates a new assumption's instance for a
shorts' array. |
static Short2DArrayAssert |
given(short[][] actual)
Creates a new assumption's instance for a
shorts' two-dimensional array. |
static <ELEMENT> AbstractSpliteratorAssert<?,ELEMENT> |
given(Spliterator<ELEMENT> actual)
Creates a new assumption's instance for a
Spliterator value. |
static <ELEMENT> AbstractListAssert<?,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>> |
given(Stream<? extends ELEMENT> actual)
Creates a new assumption's instance for a
Stream value. |
static AbstractStringAssert<?> |
given(String actual)
Creates a new assumption's instance for a
String value. |
static AbstractCharSequenceAssert<?,? extends CharSequence> |
given(StringBuffer actual)
Creates a new assumption's instance for a
StringBuffer value. |
static AbstractCharSequenceAssert<?,? extends CharSequence> |
given(StringBuilder actual)
Creates a new assumption's instance for a
StringBuilder value. |
static <T> ObjectAssert<T> |
given(T actual)
Creates a new assumption's instance for an object value.
|
static <T extends Comparable<? super T>> |
given(T actual)
Creates a new assumption's instance for a
Comparable value. |
static <T extends Throwable> |
given(T actual)
Creates a new assumption's instance for a
Throwable 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 AbstractUriAssert<?> |
given(URI actual)
Creates a new assumption's instance for an
URI value. |
static AbstractUrlAssert<?> |
given(URL actual)
Creates a new assumption's instance for an
URL value. |
static AbstractZonedDateTimeAssert<?> |
given(ZonedDateTime actual)
Creates a new assumption's instance for a
ZonedDateTime value. |
static AbstractThrowableAssert<?,? extends Throwable> |
givenCode(ThrowableAssert.ThrowingCallable lambda)
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 a
value. |
static <T extends Comparable<? super T>> |
givenComparable(T actual)
Creates a new assumption's instance of a
value. |
static ThrowableTypeAssert<Exception> |
givenException()
Alias for
givenExceptionOfType(Class) for Exception. |
static <T extends Throwable> |
givenExceptionOfType(Class<? extends T> exceptionType)
Creates a new assumption's instance for a
Throwable value. |
static ThrowableTypeAssert<IllegalArgumentException> |
givenIllegalArgumentException()
Alias for
givenExceptionOfType(Class) for IllegalArgumentException. |
static ThrowableTypeAssert<IndexOutOfBoundsException> |
givenIndexOutOfBoundsException()
Alias for
givenExceptionOfType(Class) for IndexOutOfBoundsException. |
static ThrowableTypeAssert<IOException> |
givenIOException()
Alias for
givenExceptionOfType(Class) for IOException. |
static <ELEMENT> IterableAssert<ELEMENT> |
givenIterable(Iterable<? extends ELEMENT> actual)
Creates a new assumption's instance of an
value. |
static <ELEMENT> IteratorAssert<ELEMENT> |
givenIterator(Iterator<? extends ELEMENT> actual)
Creates a new assumption's instance of an
value. |
static <ELEMENT> FactoryBasedNavigableListAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>> |
givenList(List<? extends ELEMENT> actual)
Creates a new assumption's instance of a
value. |
static ThrowableTypeAssert<NullPointerException> |
givenNullPointerException()
Alias for
givenExceptionOfType(Class) for NullPointerException. |
static <T> ObjectAssert<T> |
givenObject(T actual)
Creates a new assumption's instance for an object value.
|
static AbstractPathAssert<?> |
givenPath(Path actual)
Creates a new assumption's instance of a
value. |
static <T> PredicateAssert<T> |
givenPredicate(Predicate<T> actual)
Creates a new assumption's instance of a
value. |
static ThrowableTypeAssert<ReflectiveOperationException> |
givenReflectiveOperationException()
Alias for
givenExceptionOfType(Class) for ReflectiveOperationException. |
static ThrowableTypeAssert<RuntimeException> |
givenRuntimeException()
Alias for
givenExceptionOfType(Class) for RuntimeException. |
static <ELEMENT> AbstractListAssert<?,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>> |
givenStream(Stream<? extends ELEMENT> actual)
Creates a new assumption's instance of a
value. |
static void |
setPreferredAssumptionException(PreferredAssumptionException preferredAssumptionException)
Sets which exception is thrown if an assumption is not met.
|
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, assumeThat, assumeThatCode, assumeThatCollection, assumeThatComparable, assumeThatException, assumeThatExceptionOfType, assumeThatIllegalArgumentException, assumeThatIndexOutOfBoundsException, assumeThatIOException, assumeThatIterable, assumeThatIterator, assumeThatList, assumeThatNullPointerException, assumeThatObject, assumeThatPath, assumeThatPredicate, assumeThatReflectiveOperationException, assumeThatRuntimeException, assumeThatStream, assumeThatThrownBy, generateAssumptionClasspublic static AbstractBooleanAssert<?> given(boolean actual)
boolean value.
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.
// ...
}actual - the actual boolean value to be validated.AbstractBooleanAssert assertion object to be used for assumptions.public static AbstractBooleanAssert<?> given(Boolean actual)
Boolean value.
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.
// ...
}actual - the actual Boolean value to be validated.AbstractBooleanAssert assertion object to be used for assumptions.public static AbstractBooleanArrayAssert<?> given(boolean[] actual)
booleans' 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.
// ...
}actual - the actual booleans' array to be validated.AbstractBooleanArrayAssert assertion object to be used for assumptions.public static Boolean2DArrayAssert given(boolean[][] actual)
booleans' 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.
// ...
}actual - the actual booleans' two-dimensional array to be validated.Boolean2DArrayAssert assertion object to be used for assumptions.public static AbstractByteAssert<?> given(byte actual)
byte value.
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.
// ...
}actual - the actual byte value to be validated.AbstractByteAssert assertion object to be used for assumptions.public static AbstractByteAssert<?> given(Byte actual)
Byte value.
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.
// ...
}actual - the actual Byte value to be validated.AbstractByteAssert assertion object to be used for assumptions.public static AbstractByteArrayAssert<?> given(byte[] actual)
bytes' 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.
// ...
}actual - the actual bytes' array to be validated.AbstractByteArrayAssert assertion object to be used for assumptions.public static Byte2DArrayAssert given(byte[][] actual)
bytes' 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.
// ...
}actual - the actual bytes' two-dimensional array to be validated.Byte2DArrayAssert assertion object to be used for assumptions.public static AbstractShortAssert<?> given(short actual)
short value.
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.
// ...
}actual - the actual short value to be validated.AbstractShortAssert assertion object to be used for assumptions.public static AbstractShortAssert<?> given(Short actual)
Short value.
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.
// ...
}actual - the actual Short value to be validated.AbstractShortAssert assertion object to be used for assumptions.public static AbstractShortArrayAssert<?> given(short[] actual)
shorts' 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.
// ...
}actual - the actual shorts' array to be validated.AbstractShortArrayAssert assertion object to be used for assumptions.public static Short2DArrayAssert given(short[][] actual)
shorts' 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.
// ...
}actual - the actual shorts' two-dimensional array to be validated.Short2DArrayAssert assertion object to be used for assumptions.public static AbstractIntegerAssert<?> given(int actual)
int value.
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.
// ...
}actual - the actual int value to be validated.AbstractIntegerAssert assertion object to be used for assumptions.public static AbstractIntegerAssert<?> given(Integer actual)
Integer value.
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.
// ...
}actual - the actual Integer value to be validated.AbstractIntegerAssert assertion object to be used for assumptions.public static AbstractIntArrayAssert<?> given(int[] actual)
ints' 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.
// ...
}actual - the actual ints' array to be validated.AbstractIntArrayAssert assertion object to be used for assumptions.public static Int2DArrayAssert given(int[][] actual)
ints' 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.
// ...
}actual - the actual ints' two-dimensional array to be validated.Int2DArrayAssert assertion object to be used for assumptions.public static AbstractBigIntegerAssert<?> given(BigInteger actual)
BigInteger value.
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.
// ...
}actual - the actual BigInteger value to be validated.AbstractBigIntegerAssert assertion object to be used for assumptions.public static AbstractLongAssert<?> given(long actual)
long value.
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.
// ...
}actual - the actual long value to be validated.AbstractLongAssert assertion object to be used for assumptions.public static AbstractLongAssert<?> given(Long actual)
Long value.
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.
// ...
}actual - the actual Long value to be validated.AbstractLongAssert assertion object to be used for assumptions.public static AbstractLongArrayAssert<?> given(long[] actual)
longs' 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.
// ...
}actual - the actual longs' array to be validated.AbstractLongArrayAssert assertion object to be used for assumptions.public static Long2DArrayAssert given(long[][] actual)
longs' 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.
// ...
}actual - the actual longs' two-dimensional array to be validated.Long2DArrayAssert assertion object to be used for assumptions.public static AbstractFloatAssert<?> given(float actual)
float value.
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.
// ...
}actual - the actual float value to be validated.AbstractFloatAssert assertion object to be used for assumptions.public static AbstractFloatAssert<?> given(Float actual)
Float value.
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.
// ...
}actual - the actual Float value to be validated.AbstractFloatAssert assertion object to be used for assumptions.public static AbstractFloatArrayAssert<?> given(float[] actual)
floats' 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.
// ...
}actual - the actual floats' array to be validated.AbstractFloatArrayAssert assertion object to be used for assumptions.public static Float2DArrayAssert given(float[][] actual)
floats' 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.
// ...
}actual - the actual floats' two-dimensional array to be validated.Float2DArrayAssert assertion object to be used for assumptions.public static AbstractDoubleAssert<?> given(double actual)
double value.
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.
// ...
}actual - the actual double value to be validated.AbstractDoubleAssert assertion object to be used for assumptions.public static AbstractDoubleAssert<?> given(Double actual)
Double value.
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.
// ...
}actual - the actual Double value to be validated.AbstractDoubleAssert assertion object to be used for assumptions.public static AbstractDoubleArrayAssert<?> given(double[] actual)
doubles' 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.
// ...
}actual - the actual doubles' array to be validated.AbstractDoubleArrayAssert assertion object to be used for assumptions.public static Double2DArrayAssert given(double[][] actual)
doubles' 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.
// ...
}actual - the actual doubles' two-dimensional array to be validated.Double2DArrayAssert assertion object to be used for assumptions.public static AbstractBigDecimalAssert<?> given(BigDecimal actual)
BigDecimal value.
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.
// ...
}actual - the actual BigDecimal value to be validated.AbstractBigDecimalAssert assertion object to be used for assumptions.public static AbstractCharacterAssert<?> given(char actual)
char value.
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.
// ...
}actual - the actual char value to be validated.AbstractCharacterAssert assertion object to be used for assumptions.public static AbstractCharacterAssert<?> given(Character actual)
Character value.
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.
// ...
}actual - the actual Character value to be validated.AbstractCharacterAssert assertion object to be used for assumptions.public static AbstractCharArrayAssert<?> given(char[] actual)
chars' 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.
// ...
}actual - the actual chars' array to be validated.AbstractCharacterAssert assertion object to be used for assumptions.public static Char2DArrayAssert given(char[][] actual)
chars' 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.
// ...
}actual - the actual chars' two-dimensional array to be validated.Char2DArrayAssert assertion object to be used for assumptions.public static AbstractCharSequenceAssert<?,? extends CharSequence> given(CharSequence actual)
CharSequence value.
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.
// ...
}actual - the actual CharSequence value to be validated.AbstractCharSequenceAssert assertion object to be used for assumptions.public static AbstractStringAssert<?> given(String actual)
String value.
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.
// ...
}actual - the actual String value to be validated.AbstractStringAssert assertion object to be used for assumptions.public static AbstractCharSequenceAssert<?,? extends CharSequence> given(StringBuilder actual)
StringBuilder value.
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.
// ...
}actual - the actual StringBuilder value to be validated.AbstractCharSequenceAssert assertion object to be used for assumptions.public static AbstractCharSequenceAssert<?,? extends CharSequence> given(StringBuffer actual)
StringBuffer value.
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.
// ...
}actual - the actual StringBuffer value to be validated.AbstractCharSequenceAssert assertion object to be used for assumptions.public static ClassAssert given(Class<?> actual)
Class value.
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.
// ...
}actual - the actual Class value to be validated.AbstractClassAssert assertion object to be used for assumptions.public static <T> ObjectAssert<T> given(T actual)
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.
// ...
}T - the type of the actual object.actual - the actual object to be validated.AbstractObjectAssert assertion object to be used for assumptions.public static <T> ObjectArrayAssert<T> given(T[] actual)
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.
// ...
}T - the type of elements of the actual objects' array.actual - the actual objects' array to be validated..AbstractObjectArrayAssert assertion object to be used for assumptions.public static <T> Object2DArrayAssert<T> given(T[][] actual)
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.
// ...
}T - the type of elements of the actual objects' two-dimensional array.actual - the actual objects' two-dimensional array to be validated..Object2DArrayAssert assertion object to be used for assumptions.public static <T> ObjectAssert<T> givenObject(T actual)
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 generic given(T)
then when using some base general assert methods, e.g. AbstractAssert.matches(Predicate), cast is necessary because given(List) "forgets" actual type:
given(new LinkedList<>(asList("abc"))).matches(list -> ((Deque<String>) list).getFirst().equals("abc"));
with givenObject no cast is needed:
givenObject(new LinkedList<>(asList("abc"))).matches(list -> list.getFirst().equals("abc")); T - the type of the actual object.actual - the actual object to be validated.AbstractObjectAssert assertion object to be used for assumptions.public static <T extends Comparable<? super T>> AbstractComparableAssert<?,T> given(T actual)
Comparable value.
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.
// ...
}T - the type of the actual comparable value.actual - the actual Comparable value to be validated.AbstractComparableAssert assertion object to be used for assumptions.public static <T extends Comparable<? super T>> AbstractComparableAssert<?,T> givenComparable(T actual)
Comparable value.
Use this over given(Comparable) in case of ambiguous method resolution when the object under test
implements several interfaces Assertj provides given for.
T - the type of elements.actual - the actual value.public static <T extends Throwable> AbstractThrowableAssert<?,T> given(T actual)
Throwable value.
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.
// ...
}T - the type of the actual throwable.actual - the actual Throwable value to be validated.AbstractThrowableAssert assertion object to be used for assumptions.public static <T extends Throwable> ThrowableTypeAssert<T> givenExceptionOfType(Class<? extends T> exceptionType)
Throwable value.T - the exception type.exceptionType - the exception type class.ThrowableTypeAssert.public static ThrowableTypeAssert<Exception> givenException()
givenExceptionOfType(Class) for Exception.ThrowableAssert assertion object to be used for assumptions.public static ThrowableTypeAssert<RuntimeException> givenRuntimeException()
givenExceptionOfType(Class) for RuntimeException.ThrowableAssert assertion object to be used for assumptions.public static ThrowableTypeAssert<NullPointerException> givenNullPointerException()
givenExceptionOfType(Class) for NullPointerException.ThrowableAssert assertion object to be used for assumptions.public static ThrowableTypeAssert<IllegalArgumentException> givenIllegalArgumentException()
givenExceptionOfType(Class) for IllegalArgumentException.ThrowableAssert assertion object to be used for assumptions.public static ThrowableTypeAssert<IOException> givenIOException()
givenExceptionOfType(Class) for IOException.ThrowableAssert assertion object to be used for assumptions.public static ThrowableTypeAssert<IndexOutOfBoundsException> givenIndexOutOfBoundsException()
givenExceptionOfType(Class) for IndexOutOfBoundsException.ThrowableAssert assertion object to be used for assumptions.public static ThrowableTypeAssert<ReflectiveOperationException> givenReflectiveOperationException()
givenExceptionOfType(Class) for ReflectiveOperationException.ThrowableAssert assertion object to be used for assumptions.public static AbstractThrowableAssert<?,? extends Throwable> givenCode(ThrowableAssert.ThrowingCallable lambda)
() -> { /* 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.
// ...
lambda - the ThrowableAssert.ThrowingCallable or lambda with the code that may raise a throwable to be validated.AbstractThrowableAssert assertion object to be used for assumptions.public static <ELEMENT> IterableAssert<ELEMENT> given(Iterable<? extends ELEMENT> actual)
Iterable value.
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.
// ...
}ELEMENT - the type of elements of actual iterable value.actual - the actual Iterable value to be validated.AbstractIterableAssert assertion object to be used for assumptions.public static <ELEMENT> IterableAssert<ELEMENT> givenIterable(Iterable<? extends ELEMENT> actual)
Iterable value.
Use this over given(Iterable) in case of ambiguous method resolution when the object under test
implements several interfaces Assertj provides given for.
ELEMENT - the type of elements of actual iterable value.actual - the actual Iterable value to be validated.AbstractIterableAssert assertion object to be used for assumptions.public static <ELEMENT> IteratorAssert<ELEMENT> given(Iterator<? extends ELEMENT> actual)
Iterator value.
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.
// ...
}ELEMENT - the type of elements of actual iterator value.actual - the actual Iterator value to be validated.AbstractIteratorAssert assertion object to be used for assumptions.public static <ELEMENT> IteratorAssert<ELEMENT> givenIterator(Iterator<? extends ELEMENT> actual)
Iterator value.
Use this over given(Iterator) in case of ambiguous method resolution when the object under test
implements several interfaces Assertj provides given for.
ELEMENT - the type of elements of actual iterable value.actual - the actual Iterator value to be validated.AbstractIteratorAssert assertion object to be used for assumptions.public static <E> AbstractCollectionAssert<?,Collection<? extends E>,E,ObjectAssert<E>> given(Collection<? extends E> actual)
Collection value.E - the type of elements.actual - the actual value.Assumptions.assumeThat(Collection)public static <E> AbstractCollectionAssert<?,Collection<? extends E>,E,ObjectAssert<E>> givenCollection(Collection<? extends E> actual)
Collection value.
Use this over given(Collection) in case of ambiguous method resolution when the object under test
implements several interfaces Assertj provides given for.
E - the type of elements.actual - the actual value.public static <ELEMENT> FactoryBasedNavigableListAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>> given(List<? extends ELEMENT> actual)
List value.
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.
// ...
}ELEMENT - the type of elements of actual list value.actual - the actual List value to be validated.AbstractListAssert assertion object to be used for assumptions.public static <ELEMENT> FactoryBasedNavigableListAssert<ListAssert<ELEMENT>,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>> givenList(List<? extends ELEMENT> actual)
List value.
Use this over given(List) in case of ambiguous method resolution when the object under test
implements several interfaces Assertj provides given for.
ELEMENT - the type of elements.actual - the actual value.AbstractListAssert assertion object to be used for assumptions.public static <K,V> MapAssert<K,V> given(Map<K,V> actual)
Map value.
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.
// ...
}K - the type of keys in the actual map value.V - the type of values in the actual map value.actual - the actual Map value to be validated.AbstractMapAssert assertion object to be used for assumptions.public static <T> PredicateAssert<T> given(Predicate<T> actual)
Predicate value.
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.
// ...
}T - the type of the value contained in the actual predicate value.actual - the actual Predicate value to be validated.AbstractPredicateAssert assertion object to be used for assumptions.public static <T> PredicateAssert<T> givenPredicate(Predicate<T> actual)
Predicate value.
Use this over given(Predicate) in case of ambiguous method resolution when the object under test
implements several interfaces Assertj provides given for.
T - the type of elements.actual - the actual value.AbstractPredicateAssert assertion object to be used for assumptions.public static IntPredicateAssert given(IntPredicate actual)
IntPredicate value.
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.
// ...
}actual - the actual IntPredicate value to be validated.IntPredicateAssert assertion object to be used for assumptions.public static LongPredicateAssert given(LongPredicate actual)
LongPredicate value.
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.
// ...
}actual - the actual LongPredicate value to be validated.LongPredicateAssert assertion object to be used for assumptions.public static DoublePredicateAssert given(DoublePredicate actual)
DoublePredicate value.
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.
// ...
}actual - the actual DoublePredicate value to be validated.DoublePredicateAssert assertion object to be used for assumptions.public static <VALUE> OptionalAssert<VALUE> given(Optional<VALUE> actual)
Optional value.
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.
// ...
}VALUE - the type of the value contained in the actual optional value.actual - the actual Optional value to be validated.OptionalAssert assertion object to be used for assumptions.public static OptionalIntAssert given(OptionalInt actual)
OptionalInt value.
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.
// ...
}actual - the actual OptionalInt value to be validated.OptionalIntAssert assertion object to be used for assumptions.public static MatcherAssert given(Matcher actual)
Matcher.
public static OptionalLongAssert given(OptionalLong actual)
OptionalLong value.
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.
// ...
}actual - the actual OptionalLong value to be validated.OptionalLongAssert assertion object to be used for assumptions.public static OptionalDoubleAssert given(OptionalDouble actual)
OptionalDouble value.
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.
// ...
}actual - the actual OptionalDouble value to be validated.OptionalDoubleAssert assertion object to be used for assumptions.public static <ELEMENT> AbstractListAssert<?,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>> given(Stream<? extends ELEMENT> actual)
Stream value.
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.
// ...
}ELEMENT - the type of the value contained in the actual stream value.actual - the actual Stream value to be validated.AbstractListAssert assertion object to be used for assumptions.public static <ELEMENT> AbstractListAssert<?,List<? extends ELEMENT>,ELEMENT,ObjectAssert<ELEMENT>> givenStream(Stream<? extends ELEMENT> actual)
Stream value.
Use this over given(Stream) in case of ambiguous method resolution when the object under test
implements several interfaces Assertj provides given for.
ELEMENT - the type of elements.actual - the actual Stream value to be validated.AbstractListAssert assertion object to be used for assumptions.public static AbstractListAssert<?,List<? extends Integer>,Integer,ObjectAssert<Integer>> given(IntStream actual)
IntStream value.
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.
// ...
}actual - the actual IntStream value to be validated.AbstractListAssert assertion object to be used for assumptions.public static <ELEMENT> AbstractSpliteratorAssert<?,ELEMENT> given(Spliterator<ELEMENT> actual)
Spliterator value.
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.
}ELEMENT - the type of the elementsactual - the actual Spliterator value to be validated.AbstractSpliteratorAssert assertion object to be used for assumptions.public static AbstractListAssert<?,List<? extends Long>,Long,ObjectAssert<Long>> given(LongStream actual)
LongStream value.
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.
// ...
}actual - the actual LongStream value to be validated.AbstractListAssert assertion object to be used for assumptions.public static AbstractListAssert<?,List<? extends Double>,Double,ObjectAssert<Double>> given(DoubleStream actual)
DoubleStream value.
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.
// ...
}actual - the actual DoubleStream value to be validated.AbstractListAssert assertion object to be used for assumptions.public static <RESULT> AbstractFutureAssert<?,? extends Future<? extends RESULT>,RESULT> given(Future<RESULT> future)
Future value.
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.
// ...
}RESULT - the type of the value contained in the actual future value.future - the Future value to be validated.AbstractFutureAssert assertion object to be used for assumptions.public static <RESULT> CompletableFutureAssert<RESULT> given(CompletableFuture<RESULT> future)
CompletableFuture value.
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.
// ...
}RESULT - the type of the value contained in the actual future value.future - the CompletableFuture value to be validated.AbstractCompletableFutureAssert assertion object to be used for assumptions.public static <RESULT> CompletableFutureAssert<RESULT> given(CompletionStage<RESULT> stage)
CompletionStage value.
Converts the CompletionStage into a CompletableFuture.
If the given CompletionStage is null, the associated CompletableFuture will 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.
// ...
}RESULT - the type of the value contained in the actual future value.stage - the CompletionStage value to be validated.AbstractCompletableFutureAssert assertion object to be used for assumptions.public static AtomicBooleanAssert given(AtomicBoolean actual)
AtomicBoolean value.
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.
// ...
}actual - the actual AtomicBoolean value to be validated.AtomicBooleanAssert assertion object to be used for assumptions.public static AtomicIntegerAssert given(AtomicInteger actual)
AtomicInteger value.
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.
// ...
}actual - the actual AtomicInteger value to be validated.AtomicIntegerAssert assertion object to be used for assumptions.public static AtomicIntegerArrayAssert given(AtomicIntegerArray actual)
AtomicIntegerArray value.
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.
// ...
}actual - the actual AtomicIntegerArray value to be validated.AtomicIntegerArrayAssert assertion object to be used for assumptions.public static <OBJECT> AtomicIntegerFieldUpdaterAssert<OBJECT> given(AtomicIntegerFieldUpdater<OBJECT> actual)
AtomicIntegerFieldUpdater value.
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.
// ...
}OBJECT - the type of the object holding the updatable field which gets updated by the the actual value.actual - the actual AtomicIntegerFieldUpdater value to be validated.AtomicIntegerFieldUpdaterAssert assertion object to be used for assumptions.public static LongAdderAssert given(LongAdder actual)
LongAdder value.
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.
// ...
}actual - the actual LongAdder value to be validated.LongAdderAssert assertion object to be used for assumptions.public static AtomicLongAssert given(AtomicLong actual)
AtomicLong value.
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.
// ...
}actual - the actual AtomicLong value to be validated.AtomicLongAssert assertion object to be used for assumptions.public static AtomicLongArrayAssert given(AtomicLongArray actual)
AtomicLongArray value.
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.
// ...
}actual - the actual AtomicLongArray value to be validated.AtomicLongArrayAssert assertion object to be used for assumptions.public static <OBJECT> AtomicLongFieldUpdaterAssert<OBJECT> given(AtomicLongFieldUpdater<OBJECT> actual)
AtomicLongFieldUpdater value.
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.
// ...
}OBJECT - the type of the object holding the updatable field which gets updated by the the actual value.actual - the actual AtomicLongFieldUpdater value to be validated.AtomicLongFieldUpdaterAssert assertion object to be used for assumptions.public static <VALUE> AtomicReferenceAssert<VALUE> given(AtomicReference<VALUE> actual)
AtomicReference value.
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.
// ...
}VALUE - the type of the value contained by the actual reference.actual - the actual AtomicReference to be validated.AtomicReferenceAssert assertion object to be used for assumptions.public static <ELEMENT> AtomicReferenceArrayAssert<ELEMENT> given(AtomicReferenceArray<ELEMENT> actual)
AtomicReferenceArray value.
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.
// ...
}ELEMENT - the type of the value contained in the actual references' array.actual - the actual AtomicReferenceArray to be validated.AtomicReferenceArrayAssert assertion object to be used for assumptions.public static <FIELD,OBJECT> AtomicReferenceFieldUpdaterAssert<FIELD,OBJECT> given(AtomicReferenceFieldUpdater<OBJECT,FIELD> actual)
AtomicReferenceFieldUpdater value.
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.
// ...
}FIELD - the type of the field which gets updated by the the actual updater.OBJECT - the type of the object holding the updatable field which gets updated by the the actual updater.actual - the actual AtomicReferenceFieldUpdater value to be validated.AtomicReferenceFieldUpdaterAssert assertion object to be used for assumptions.public static <VALUE> AtomicMarkableReferenceAssert<VALUE> given(AtomicMarkableReference<VALUE> actual)
AtomicMarkableReference value.
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.
// ...
}VALUE - the type of the value contained by the actual reference.actual - the actual AtomicMarkableReference to be validated.AtomicMarkableReferenceAssert assertion object to be used for assumptions.public static <VALUE> AtomicStampedReferenceAssert<VALUE> given(AtomicStampedReference<VALUE> actual)
AtomicStampedReference value.
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.
// ...
}VALUE - the type of the value contained by the actual reference.actual - the actual AtomicStampedReference to be validated.AtomicStampedReferenceAssert assertion object to be used for assumptions.public static AbstractDateAssert<?> given(Date actual)
Date value.
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.
// ...
}actual - the actual Date value to be validated.AbstractDateAssert assertion object to be used for assumptions.public static AbstractLocalDateAssert<?> given(LocalDate actual)
LocalDate value.
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.
// ...
}actual - the actual LocalDate value to be validated.AbstractLocalDateAssert assertion object to be used for assumptions.public static AbstractLocalTimeAssert<?> given(LocalTime actual)
LocalTime value.
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.
// ...
}actual - the actual LocalTime value to be validated.AbstractLocalTimeAssert assertion object to be used for assumptions.public static AbstractOffsetTimeAssert<?> given(OffsetTime actual)
OffsetTime value.
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.
// ...
}actual - the actual OffsetTime value to be validated.AbstractOffsetTimeAssert assertion object to be used for assumptions.public static AbstractLocalDateTimeAssert<?> given(LocalDateTime actual)
LocalDateTime value.
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.
// ...
}actual - the actual LocalDateTime value to be validated.AbstractLocalDateTimeAssert assertion object to be used for assumptions.public static AbstractInstantAssert<?> given(Instant actual)
Instant value.
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.
// ...
}actual - the actual Instant value to be validated.AbstractInstantAssert assertion object to be used for assumptions.public static AbstractDurationAssert<?> given(Duration actual)
Instant value.actual - the actual value.public static AbstractPeriodAssert<?> given(Period actual)
Period value.actual - the actual value.public static AbstractOffsetDateTimeAssert<?> given(OffsetDateTime actual)
OffsetDateTime value.
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.
// ...
}actual - the actual OffsetDateTime value to be validated.AbstractOffsetDateTimeAssert assertion object to be used for assumptions.public static AbstractZonedDateTimeAssert<?> given(ZonedDateTime actual)
ZonedDateTime value.
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.
// ...
}actual - the actual ZonedDateTime value to be validated.AbstractZonedDateTimeAssert assertion object to be used for assumptions.public static AbstractInputStreamAssert<?,? extends InputStream> given(InputStream actual)
InputStream value.
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.
// ...
}actual - the actual InputStream value to be validated.AbstractInputStreamAssert assertion object to be used for assumptions.public static AbstractFileAssert<?> given(File actual)
File value.
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.
// ...
}actual - the actual File value to be validated.AbstractFileAssert assertion object to be used for assumptions.public static AbstractPathAssert<?> given(Path actual)
Path value.
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.
// ...
}actual - the actual Path value to be validated.AbstractPathAssert assertion object to be used for assumptions.public static AbstractPathAssert<?> givenPath(Path actual)
Path value.
Use this over given(Path) in case of ambiguous method resolution when the object under test
implements several interfaces Assertj provides given for.
actual - the actual Path value to be validated.AbstractPathAssert assertion object to be used for assumptions.public static AbstractUriAssert<?> given(URI actual)
URI value.
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.
// ...
}actual - the actual URI value to be validated.AbstractUriAssert assertion object to be used for assumptions.public static AbstractUrlAssert<?> given(URL actual)
URL value.
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.
// ...
}actual - the actual URL value to be validated.AbstractUrlAssert assertion object to be used for assumptions.public static void setPreferredAssumptionException(PreferredAssumptionException preferredAssumptionException)
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_NG to throw a org.testng.SkipException if you are using TestNGPreferredAssumptionException.JUNIT4 to throw a org.junit.AssumptionViolatedException if you are using JUnit 4PreferredAssumptionException.JUNIT5 a org.opentest4j.TestAbortedException if you are using JUnit 5PreferredAssumptionException.AUTO_DETECT to 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_DETECT mode and tries to throw one of the following exceptions, in this order:
org.testng.SkipException for TestNG (if available in the classpath)org.junit.AssumptionViolatedException for JUnit 4 (if available in the classpath)org.opentest4j.TestAbortedException for JUnit 5preferredAssumptionException - the preferred exception to use with BDDAssumptions.Copyright © 2025. All rights reserved.