Interface WithAssumptions


  • public interface WithAssumptions
    A unified entry point to all assumptions from both the new Java 8 core API and the pre-Java 8 core API. As a convenience, the methods are defined in an interface so that no static imports are necessary if the test class implements this interface.
    • Method Detail

      • assumeThat

        default <T> ObjectArrayAssert<T> assumeThat​(T[] actual)
        Creates a new instance of ObjectArrayAssert assumption.
        Type Parameters:
        T - the type of elements.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default <T> Object2DArrayAssert<T> assumeThat​(T[][] actual)
        Creates a new instance of Object2DArrayAssert assumption.
        Type Parameters:
        T - the type of elements.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        3.17.0
      • assumeThat

        default <K,​V> MapAssert<K,​V> assumeThat​(Map<K,​V> actual)
        Creates a new instance of MapAssert assumption.
        Type Parameters:
        K - the type of keys in the map.
        V - the type of values in the map.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default AbstractShortAssert<?> assumeThat​(short actual)
        Creates a new instance of ShortAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default AbstractLongAssert<?> assumeThat​(long actual)
        Creates a new instance of LongAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default AbstractLongAssert<?> assumeThat​(Long actual)
        Creates a new instance of LongAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default AbstractLongArrayAssert<?> assumeThat​(long[] actual)
        Creates a new instance of LongArrayAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default Long2DArrayAssert assumeThat​(long[][] actual)
        Creates a new instance of Long2DArrayAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        3.17.0
      • assumeThat

        default <T> ObjectAssert<T> assumeThat​(T actual)
        Creates a new instance of ObjectAssert assumption.
        Type Parameters:
        T - the type of the actual value.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default AbstractStringAssert<?> assumeThat​(String actual)
        Creates a new instance of StringAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default AbstractDateAssert<?> assumeThat​(Date actual)
        Creates a new instance of DateAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default <T extends ThrowableAbstractThrowableAssert<?,​T> assumeThat​(T actual)
        Creates a new instance of ThrowableAssert assumption.
        Type Parameters:
        T - the type of the actual value.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default AbstractBigDecimalAssert<?> assumeThat​(BigDecimal actual)
        Creates a new instance of BigDecimalAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default AbstractBigIntegerAssert<?> assumeThat​(BigInteger actual)
        Creates a new instance of BigIntegerAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default LongAdderAssert assumeThat​(LongAdder actual)
        Creates a new instance of LongAdderAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • assumeThat

        default AbstractShortArrayAssert<?> assumeThat​(short[] actual)
        Creates a new instance of ShortArrayAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default Short2DArrayAssert assumeThat​(short[][] actual)
        Creates a new instance of Short2DArrayAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        3.17.0
      • assumeThat

        default AbstractShortAssert<?> assumeThat​(Short actual)
        Creates a new instance of ShortAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default ClassAssert assumeThat​(Class<?> actual)
        Creates a new instance of ClassAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default AbstractCharacterAssert<?> assumeThat​(Character actual)
        Creates a new instance of CharacterAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default AbstractCharArrayAssert<?> assumeThat​(char[] actual)
        Creates a new instance of CharArrayAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default Char2DArrayAssert assumeThat​(char[][] actual)
        Creates a new instance of Char2DArrayAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        3.17.0
      • assumeThat

        default AbstractCharacterAssert<?> assumeThat​(char actual)
        Creates a new instance of CharacterAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default <T extends Comparable<? super T>> AbstractComparableAssert<?,​T> assumeThat​(T actual)
        Creates a new instance of GenericComparableAssert assumption.
        Type Parameters:
        T - the type of actual.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default <ELEMENT> IterableAssert<ELEMENT> assumeThat​(Iterable<? extends ELEMENT> actual)
        Creates a new instance of IterableAssert assumption.
        Type Parameters:
        ELEMENT - the type of elements.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default <ELEMENT> IteratorAssert<ELEMENT> assumeThat​(Iterator<? extends ELEMENT> actual)
        Creates a new instance of IteratorAssert assumption.

        Breaking change in version 3.12.0: this method does not return anymore an IterableAssert but an IteratorAssert.

        Type Parameters:
        ELEMENT - the type of elements.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default AbstractBooleanAssert<?> assumeThat​(Boolean actual)
        Creates a new instance of BooleanAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default AbstractBooleanArrayAssert<?> assumeThat​(boolean[] actual)
        Creates a new instance of BooleanArrayAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default Boolean2DArrayAssert assumeThat​(boolean[][] actual)
        Creates a new instance of Boolean2DArrayAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        3.17.0
      • assumeThat

        default AbstractByteAssert<?> assumeThat​(byte actual)
        Creates a new instance of ByteAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default AbstractByteAssert<?> assumeThat​(Byte actual)
        Creates a new instance of ByteAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default AbstractByteArrayAssert<?> assumeThat​(byte[] actual)
        Creates a new instance of ByteArrayAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default Byte2DArrayAssert assumeThat​(byte[][] actual)
        Creates a new instance of Byte2DArrayAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        3.17.0
      • assumeThat

        default AbstractBooleanAssert<?> assumeThat​(boolean actual)
        Creates a new instance of BooleanAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default AbstractFloatAssert<?> assumeThat​(float actual)
        Creates a new instance of FloatAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default AbstractFileAssert<?> assumeThat​(File actual)
        Creates a new instance of FileAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default <RESULT> AbstractFutureAssert<?,​? extends Future<? extends RESULT>,​RESULT> assumeThat​(Future<RESULT> actual)
        Create assertion for FutureAssert assumption.
        Type Parameters:
        RESULT - the type of the value contained in the Future.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default AbstractPathAssert<?> assumeThat​(Path actual)
        Creates a new instance of PathAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default AbstractIntArrayAssert<?> assumeThat​(int[] actual)
        Creates a new instance of IntArrayAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default Int2DArrayAssert assumeThat​(int[][] actual)
        Creates a new instance of Int2DArrayAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        3.17.0
      • assumeThat

        default AbstractFloatAssert<?> assumeThat​(Float actual)
        Creates a new instance of FloatAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default Float2DArrayAssert assumeThat​(float[][] actual)
        Creates a new instance of Float2DArrayAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        3.17.0
      • assumeThat

        default AbstractIntegerAssert<?> assumeThat​(int actual)
        Creates a new instance of IntegerAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default AbstractFloatArrayAssert<?> assumeThat​(float[] actual)
        Creates a new instance of FloatArrayAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default AbstractIntegerAssert<?> assumeThat​(Integer actual)
        Creates a new instance of IntegerAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default AbstractDoubleAssert<?> assumeThat​(double actual)
        Creates a new instance of DoubleAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default AbstractDoubleAssert<?> assumeThat​(Double actual)
        Creates a new instance of DoubleAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default <ELEMENT> FactoryBasedNavigableListAssert<ListAssert<ELEMENT>,​List<? extends ELEMENT>,​ELEMENT,​ObjectAssert<ELEMENT>> assumeThat​(List<? extends ELEMENT> list)
        Creates a new instance of ListAssert assumption.
        Type Parameters:
        ELEMENT - the type of elements.
        Parameters:
        list - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default <ELEMENT> AbstractListAssert<?,​List<? extends ELEMENT>,​ELEMENT,​ObjectAssert<ELEMENT>> assumeThat​(Stream<? extends ELEMENT> stream)
        Creates a new instance of ListAssert assumption from the given Stream.
        Type Parameters:
        ELEMENT - the type of elements.
        Parameters:
        stream - the Stream to test
        Returns:
        the created assumption for assertion object.
        Since:
        3.9.0
      • assumeThat

        default AbstractDoubleArrayAssert<?> assumeThat​(double[] actual)
        Creates a new instance of DoubleArrayAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default Double2DArrayAssert assumeThat​(double[][] actual)
        Creates a new instance of Double2DArrayAssert assumption.
        Parameters:
        actual - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        3.17.0
      • assumeThat

        default <RESULT> CompletableFutureAssert<RESULT> assumeThat​(CompletableFuture<RESULT> future)
        Creates a new instance of CompletableFutureAssert assumption.
        Type Parameters:
        RESULT - the CompletableFuture wrapped type.
        Parameters:
        future - the CompletableFuture to test
        Returns:
        the created assumption for assertion object.
        Since:
        3.9.0
      • assumeThat

        default <VALUE> OptionalAssert<VALUE> assumeThat​(Optional<VALUE> optional)
        Creates a new instance of OptionalAssert assumption.
        Type Parameters:
        VALUE - the Optional wrapped type.
        Parameters:
        optional - the Optional to test
        Returns:
        the created assumption for assertion object.
        Since:
        3.9.0
      • assumeThat

        default OptionalDoubleAssert assumeThat​(OptionalDouble optionalDouble)
        Creates a new instance of OptionalDoubleAssert assumption.
        Parameters:
        optionalDouble - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default OptionalIntAssert assumeThat​(OptionalInt optionalInt)
        Creates a new instance of OptionalIntAssert assumption.
        Parameters:
        optionalInt - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default OptionalLongAssert assumeThat​(OptionalLong optionalLong)
        Creates a new instance of OptionalLongAssert assumption.
        Parameters:
        optionalLong - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default AbstractLocalDateAssert<?> assumeThat​(LocalDate localDate)
        Creates a new instance of LocalDateAssert assumption.
        Parameters:
        localDate - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default AbstractLocalTimeAssert<?> assumeThat​(LocalTime localTime)
        Creates a new instance of LocalTimeAssert assumption.
        Parameters:
        localTime - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default AbstractInstantAssert<?> assumeThat​(Instant instant)
        Creates a new instance of InstantAssert assumption.
        Parameters:
        instant - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default AbstractDurationAssert<?> assumeThat​(Duration duration)
        Creates a new instance of DurationAssert assumption.
        Parameters:
        duration - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        3.15.0
      • assumeThat

        default AbstractPeriodAssert<?> assumeThat​(Period period)
        Creates a new instance of PeriodAssert assumption.
        Parameters:
        period - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        3.17.0
      • assumeThat

        default AbstractOffsetTimeAssert<?> assumeThat​(OffsetTime offsetTime)
        Creates a new instance of OffsetTimeAssert assumption.
        Parameters:
        offsetTime - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThatThrownBy

        default AbstractThrowableAssert<?,​? extends Throwable> assumeThatThrownBy​(ThrowableAssert.ThrowingCallable shouldRaiseThrowable)
        Allows to capture and then assume on a Throwable (easier done with lambdas).

        Example :

          @Test
          public void testException() {
            assumeThatThrownBy(() -> { throw new Exception("boom!") }).isInstanceOf(Exception.class)
                                                                      .hasMessageContaining("boom");
         }
        Parameters:
        shouldRaiseThrowable - The ThrowableAssert.ThrowingCallable or lambda with the code that should raise the throwable.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThatCode

        default AbstractThrowableAssert<?,​? extends Throwable> assumeThatCode​(ThrowableAssert.ThrowingCallable shouldRaiseOrNotThrowable)
        Allows to capture and then assume on a Throwable (easier done with lambdas).

        Example :

         ThrowingCallable callable = () -> {
           throw new Exception("boom!");
         };
        
         // assertion succeeds
         assumeThatCode(callable).isInstanceOf(Exception.class)
                                 .hasMessageContaining("boom");
        
         // assertion fails
         assumeThatCode(callable).doesNotThrowAnyException();

        This method was not named assumeThat because the java compiler reported it ambiguous when used directly with a lambda :(

        Parameters:
        shouldRaiseOrNotThrowable - The ThrowableAssert.ThrowingCallable or lambda with the code that should raise the throwable.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThatObject

        default <T> ObjectAssert<T> assumeThatObject​(T actual)
        Creates a new instance of ObjectAssert for any object.

        This overload is useful, when an overloaded method of assertThat(...) takes precedence over the generic assumeThat(Object).

        Example:

        Cast necessary because assumeThat(List) "forgets" actual type:

        assumeThat(new LinkedList<>(asList("abc"))).matches(list -> ((Deque<String>) list).getFirst().equals("abc")); 
        No cast needed, but also no additional list assertions:
        assumeThatObject(new LinkedList<>(asList("abc"))).matches(list -> list.getFirst().equals("abc")); 
        Type Parameters:
        T - the type of the actual value.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
        Since:
        3.12.0
      • assumeThat

        default <T> PredicateAssert<T> assumeThat​(Predicate<T> predicate)
        Creates a new instance of PredicateAssert assumption.
        Type Parameters:
        T - the Predicate type.
        Parameters:
        predicate - the Predicate to test
        Returns:
        the created assumption for assertion object.
        Since:
        3.9.0
      • assumeThat

        default IntPredicateAssert assumeThat​(IntPredicate intPredicate)
        Creates a new instance of IntPredicateAssert assumption.
        Parameters:
        intPredicate - the IntPredicate to test
        Returns:
        the created assumption for assertion object.
        Since:
        3.9.0
      • assumeThat

        default LongPredicateAssert assumeThat​(LongPredicate longPredicate)
        Creates a new instance of LongPredicateAssert assumption.
        Parameters:
        longPredicate - the LongPredicate to test
        Returns:
        the created assumption for assertion object.
        Since:
        3.9.0
      • assumeThat

        default AbstractUrlAssert<?> assumeThat​(URL url)
        Creates a new instance of UrlAssert assumption.
        Parameters:
        url - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default AbstractUriAssert<?> assumeThat​(URI uri)
        Creates a new instance of UriAssert assumption.
        Parameters:
        uri - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        2.9.0 / 3.9.0
      • assumeThat

        default <ELEMENT> AbstractSpliteratorAssert<?,​ELEMENT> assumeThat​(Spliterator<ELEMENT> spliterator)
        Creates a new instance of SpliteratorAssert assumption.
        Type Parameters:
        ELEMENT - the type of the elements.
        Parameters:
        spliterator - the actual value.
        Returns:
        the created assumption for assertion object.
        Since:
        3.14.0
      • setPreferredAssumptionException

        default 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:

        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:

        1. org.testng.SkipException for TestNG (if available in the classpath)
        2. org.junit.AssumptionViolatedException for JUnit 4 (if available in the classpath)
        3. org.opentest4j.TestAbortedException for JUnit 5
        Parameters:
        preferredAssumptionException - the preferred exception to use with Assumptions.
        Since:
        3.21.0