Class Java6AbstractStandardSoftAssertions

    • Constructor Detail

      • Java6AbstractStandardSoftAssertions

        public Java6AbstractStandardSoftAssertions()
    • Method Detail

      • assertThat

        public BigIntegerAssert assertThat​(BigInteger actual)
        Creates a new instance of BigInteger.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
        Since:
        2.7.0 / 3.7.0
      • assertThat

        public BooleanAssert assertThat​(boolean actual)
        Creates a new instance of BooleanAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • assertThat

        public BooleanAssert assertThat​(Boolean actual)
        Creates a new instance of BooleanAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • assertThat

        public BooleanArrayAssert assertThat​(boolean[] actual)
        Creates a new instance of BooleanArrayAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • assertThat

        public ByteAssert assertThat​(byte actual)
        Creates a new instance of ByteAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • assertThat

        public ByteAssert assertThat​(Byte actual)
        Creates a new instance of ByteAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • assertThat

        public ByteArrayAssert assertThat​(byte[] actual)
        Creates a new instance of ByteArrayAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • assertThat

        public CharacterAssert assertThat​(char actual)
        Creates a new instance of CharacterAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • assertThat

        public CharArrayAssert assertThat​(char[] actual)
        Creates a new instance of CharArrayAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • assertThat

        public <T extends Comparable<? super T>> AbstractComparableAssert<?,​T> assertThat​(T actual)
        Creates a new instance of GenericComparableAssert with standard comparison semantics.
        Type Parameters:
        T - the actual type.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • assertThat

        public <T> ProxyableIterableAssert<T> assertThat​(Iterable<? extends T> actual)
        Creates a new instance of IterableAssert.

        We don't return IterableAssert as it has overridden methods to annotated with SafeVarargs.

        Type Parameters:
        T - the actual element's type.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • assertThat

        public <T> IteratorAssert<T> assertThat​(Iterator<? extends T> actual)
        Creates a new instance of IteratorAssert.

        This is a breaking change in version 3.12.0: this method used to return an ProxyableIterableAssert.

        Type Parameters:
        T - the actual element's type.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • assertThat

        public DoubleAssert assertThat​(double actual)
        Creates a new instance of DoubleAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • assertThat

        public DoubleAssert assertThat​(Double actual)
        Creates a new instance of DoubleAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • assertThat

        public DoubleArrayAssert assertThat​(double[] actual)
        Creates a new instance of DoubleArrayAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • assertThat

        public FileAssert assertThat​(File actual)
        Creates a new instance of FileAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • assertThat

        public <RESULT> FutureAssert<RESULT> assertThat​(Future<RESULT> actual)
        Creates a new instance of FutureAssert.
        Type Parameters:
        RESULT - the Future element type.
        Parameters:
        actual - the actual value
        Returns:
        the created assertion object
      • assertThat

        public FloatAssert assertThat​(float actual)
        Creates a new instance of FloatAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • assertThat

        public FloatAssert assertThat​(Float actual)
        Creates a new instance of FloatAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • assertThat

        public FloatArrayAssert assertThat​(float[] actual)
        Creates a new instance of FloatArrayAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • assertThat

        public IntegerAssert assertThat​(int actual)
        Creates a new instance of IntegerAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • assertThat

        public IntArrayAssert assertThat​(int[] actual)
        Creates a new instance of IntArrayAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • assertThat

        public IntegerAssert assertThat​(Integer actual)
        Creates a new instance of IntegerAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • assertThat

        public <T> ProxyableListAssert<T> assertThat​(List<? extends T> actual)
        Creates a new instance of ListAssert.

        We don't return IterableAssert as it has overridden methods to annotated with SafeVarargs.

        Type Parameters:
        T - the actual element's type.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • assertThat

        public LongAssert assertThat​(long actual)
        Creates a new instance of LongAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • assertThat

        public LongAssert assertThat​(Long actual)
        Creates a new instance of LongAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • assertThat

        public LongArrayAssert assertThat​(long[] actual)
        Creates a new instance of LongArrayAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • assertThat

        public <T> ProxyableObjectAssert<T> assertThat​(T actual)
        Creates a new instance of ObjectAssert.
        Type Parameters:
        T - the type of the actual value.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • assertThat

        public <T> ProxyableObjectArrayAssert<T> assertThat​(T[] actual)
        Creates a new instance of ObjectArrayAssert.
        Type Parameters:
        T - the type values of the actual array.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • assertThat

        public <K,​V> ProxyableMapAssert<K,​V> assertThat​(Map<K,​V> actual)
        Creates a new instance of MapAssert.

        We don't return MapAssert as it has overridden methods to annotated with SafeVarargs.

        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 assertion object.
      • assertThat

        public ShortAssert assertThat​(short actual)
        Creates a new instance of ShortAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • assertThat

        public ShortAssert assertThat​(Short actual)
        Creates a new instance of ShortAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • assertThat

        public ShortArrayAssert assertThat​(short[] actual)
        Creates a new instance of ShortArrayAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • assertThat

        public StringAssert assertThat​(String actual)
        Creates a new instance of StringAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • assertThat

        public DateAssert assertThat​(Date actual)
        Creates a new instance of DateAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • assertThat

        public AtomicLongAssert assertThat​(AtomicLong actual)
        Create assertion for AtomicLong.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • assertThatThrownBy

        public AbstractThrowableAssert<?,​? extends Throwable> assertThatThrownBy​(ThrowableAssert.ThrowingCallable shouldRaiseThrowable)
        Allows to capture and then assert on a Throwable more easily when used with Java 8 lambdas. Java 8 example :
          @Test
          public void testException() {
            SoftAssertions softly = new SoftAssertions();
            softly.assertThatThrownBy(() -> { throw new Exception("boom!"); }).isInstanceOf(Exception.class)
                                                                              .hasMessageContaining("boom");
          }
        Java 7 example :
         SoftAssertions softly = new SoftAssertions();
         softly.assertThatThrownBy(new ThrowingCallable() {
        
           @Override
           public Void call() throws Exception {
             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 captured exception or null if none was raised by the callable.
      • assertThatThrownBy

        public AbstractThrowableAssert<?,​? extends Throwable> assertThatThrownBy​(ThrowableAssert.ThrowingCallable shouldRaiseThrowable,
                                                                                       String description,
                                                                                       Object... args)
        Allows to capture and then assert on a Throwable like assertThatThrownBy(ThrowingCallable) but this method let you set the assertion description the same way you do with as(String, Object...).

        Example:

         @Test
          public void testException() {
            SoftAssertions softly = new SoftAssertions();
            // if this assertion failed (but it doesn't), the error message would start with [Test explosive code]
            softly.assertThatThrownBy(() -> { throw new IOException("boom!") }, "Test explosive code")
                     .isInstanceOf(IOException.class)
                     .hasMessageContaining("boom");
         }
        If the provided ThrowingCallable does not raise an exception, an error is immediately thrown.

        The test description provided is honored but not the one with as(String, Object...), example:

         // assertion will fail but "display me" won't appear in the error message
         softly.assertThatThrownBy(() -> {}).as("display me")
                                            .isInstanceOf(Exception.class);
        
         // assertion will fail AND "display me" will appear in the error message
         softly.assertThatThrownBy(() -> {}, "display me")
                                            .isInstanceOf(Exception.class);
        Parameters:
        shouldRaiseThrowable - The ThrowableAssert.ThrowingCallable or lambda with the code that should raise the throwable.
        description - the new description to set.
        args - optional parameter if description is a format String.
        Returns:
        the created ThrowableAssert.
        Since:
        3.9.0
      • assertThatCode

        public AbstractThrowableAssert<?,​? extends Throwable> assertThatCode​(ThrowableAssert.ThrowingCallable shouldRaiseOrNotThrowable)
        Allows to capture and then assert on a Throwable more easily when used with Java 8 lambdas.

        Example :

         ThrowingCallable callable = () -> {
           throw new Exception("boom!");
         };
        
         // assertion succeeds
         assertThatCode(callable).isInstanceOf(Exception.class)
                                 .hasMessageContaining("boom");
        
         // assertion fails
         assertThatCode(callable).doesNotThrowAnyException();
        If the provided ThrowableAssert.ThrowingCallable does not validate against next assertions, an error is immediately raised, in that case the test description provided with as(String, Object...) is not honored.
        To use a test description, use assertThatCode(ThrowableAssert.ThrowingCallable) as shown below.
         ThrowingCallable doNothing = () -> {
           // do nothing
         };
        
         // assertion fails and "display me" appears in the assertion error
         assertThatCode(doNothing).as("display me")
                                  .isInstanceOf(Exception.class);
        
         // assertion will fail AND "display me" will appear in the error
         Throwable thrown = catchThrowable(doNothing);
         assertThatCode(thrown).as("display me")
                               .isInstanceOf(Exception.class); 

        This method was not named assertThat 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 captured exception or null if none was raised by the callable.
        Since:
        3.7.0
      • assertThatObject

        public <T> ProxyableObjectAssert<T> assertThatObject​(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 assertThat(Object).

        Example:

        Cast necessary because assertThat(List) "forgets" actual type:
        assertThat(new LinkedList<>(asList("abc"))).matches(list -> ((Deque<String>) list).getFirst().equals("abc")); 
        No cast needed, but also no additional list assertions:
        assertThatObject(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
      • assertThat

        public UriAssert assertThat​(URI actual)
        Creates a new instance of UriAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • assertThat

        public AbstractUrlAssert<?> assertThat​(URL actual)
        Creates a new instance of UrlAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.