Class Java6BDDAssertions


  • public class Java6BDDAssertions
    extends java.lang.Object
    Android-compatible BDD-style assertions duplicated from BDDAssertions.
    Since:
    2.5.0 / 3.5.0
    See Also:
    BDDAssertions
    • Constructor Detail

      • Java6BDDAssertions

        protected Java6BDDAssertions()
        Creates a new BDDAssertions.
    • Method Detail

      • then

        public static AtomicBooleanAssert then​(java.util.concurrent.atomic.AtomicBoolean actual)
        Create assertion for AtomicBoolean.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
        Since:
        2.7.0 / 3.7.0
      • then

        public static AtomicIntegerAssert then​(java.util.concurrent.atomic.AtomicInteger actual)
        Create assertion for AtomicInteger.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
        Since:
        2.7.0 / 3.7.0
      • then

        public static AtomicIntegerArrayAssert then​(java.util.concurrent.atomic.AtomicIntegerArray actual)
        Create int[] assertion for AtomicIntegerArray.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
        Since:
        2.7.0 / 3.7.0
      • then

        public static <OBJECT> AtomicIntegerFieldUpdaterAssert<OBJECT> then​(java.util.concurrent.atomic.AtomicIntegerFieldUpdater<OBJECT> actual)
        Create assertion for AtomicIntegerFieldUpdater.
        Type Parameters:
        OBJECT - the type of the object holding the updatable field.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
        Since:
        2.7.0 / 3.7.0
      • then

        public static AtomicLongAssert then​(java.util.concurrent.atomic.AtomicLong actual)
        Create assertion for AtomicLong.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
        Since:
        2.7.0 / 3.7.0
      • then

        public static AtomicLongArrayAssert then​(java.util.concurrent.atomic.AtomicLongArray actual)
        Create assertion for AtomicLongArray.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
        Since:
        2.7.0 / 3.7.0
      • then

        public static <OBJECT> AtomicLongFieldUpdaterAssert<OBJECT> then​(java.util.concurrent.atomic.AtomicLongFieldUpdater<OBJECT> actual)
        Create assertion for AtomicLongFieldUpdater.
        Type Parameters:
        OBJECT - the type of the object holding the updatable field.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
        Since:
        2.7.0 / 3.7.0
      • then

        public static <VALUE> AtomicReferenceAssert<VALUE> then​(java.util.concurrent.atomic.AtomicReference<VALUE> actual)
        Create assertion for AtomicReference.
        Type Parameters:
        VALUE - the type of the value contained in the AtomicReference.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
        Since:
        2.7.0 / 3.7.0
      • then

        public static <ELEMENT> AtomicReferenceArrayAssert<ELEMENT> then​(java.util.concurrent.atomic.AtomicReferenceArray<ELEMENT> actual)
        Create assertion for AtomicReferenceArray.
        Type Parameters:
        ELEMENT - the type of the value contained in the AtomicReferenceArray.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
        Since:
        2.7.0 / 3.7.0
      • then

        public static <FIELD,​OBJECT> AtomicReferenceFieldUpdaterAssert<FIELD,​OBJECT> then​(java.util.concurrent.atomic.AtomicReferenceFieldUpdater<OBJECT,​FIELD> actual)
        Create assertion for AtomicReferenceFieldUpdater.
        Type Parameters:
        FIELD - the type of the field which gets updated by the AtomicReferenceFieldUpdater.
        OBJECT - the type of the object holding the updatable field.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
        Since:
        2.7.0 / 3.7.0
      • then

        public static <VALUE> AtomicMarkableReferenceAssert<VALUE> then​(java.util.concurrent.atomic.AtomicMarkableReference<VALUE> actual)
        Create assertion for AtomicMarkableReference.
        Type Parameters:
        VALUE - the type of the value contained in the AtomicMarkableReference.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
        Since:
        2.7.0 / 3.7.0
      • then

        public static <VALUE> AtomicStampedReferenceAssert<VALUE> then​(java.util.concurrent.atomic.AtomicStampedReference<VALUE> actual)
        Create assertion for AtomicStampedReference.
        Type Parameters:
        VALUE - the type of the value contained in the AtomicStampedReference.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
        Since:
        2.7.0 / 3.7.0
      • then

        public static AbstractBigDecimalAssert<?> then​(java.math.BigDecimal actual)
        Creates a new instance of BigDecimalAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • then

        public static AbstractBigIntegerAssert<?> then​(java.math.BigInteger actual)
        Creates a new instance of BigIntegerAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
        Since:
        2.7.0 / 3.7.0
      • then

        public static AbstractBooleanAssert<?> then​(boolean actual)
        Creates a new instance of BooleanAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • then

        public static AbstractBooleanAssert<?> then​(java.lang.Boolean actual)
        Creates a new instance of BooleanAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • then

        public static AbstractByteAssert<?> then​(byte actual)
        Creates a new instance of ByteAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • then

        public static AbstractByteAssert<?> then​(java.lang.Byte actual)
        Creates a new instance of ByteAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • then

        public static AbstractByteArrayAssert<?> then​(byte[] actual)
        Creates a new instance of ByteArrayAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • then

        public static AbstractCharacterAssert<?> then​(char actual)
        Creates a new instance of CharacterAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • then

        public static AbstractCharArrayAssert<?> then​(char[] actual)
        Creates a new instance of CharArrayAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • then

        public static AbstractCharacterAssert<?> then​(java.lang.Character actual)
        Creates a new instance of CharacterAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • then

        public static AbstractClassAssert<?> then​(java.lang.Class<?> actual)
        Creates a new instance of ClassAssert
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • then

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

        public static <T> AbstractIterableAssert<?,​java.lang.Iterable<? extends T>,​T,​ObjectAssert<T>> then​(java.lang.Iterable<? extends T> actual)
        Creates a new instance of IterableAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • then

        public static <T> AbstractIterableAssert<?,​java.lang.Iterable<? extends T>,​T,​ObjectAssert<T>> then​(java.util.Iterator<? extends T> actual)
        Creates a new instance of IterableAssert. The Iterator is first converted into an Iterable
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • then

        public static <ACTUAL extends java.lang.Iterable<? extends ELEMENT>,​ELEMENT,​ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,​ELEMENT>> FactoryBasedNavigableIterableAssert<?,​ACTUAL,​ELEMENT,​ELEMENT_ASSERT> then​(java.lang.Iterable<? extends ELEMENT> actual,
                                                                                                                                                                                                                                                                 AssertFactory<ELEMENT,​ELEMENT_ASSERT> assertFactory)
        Creates a new instance of FactoryBasedNavigableIterableAssert allowing to navigate to any Iterable element in order to perform assertions on it.

        Navigational methods provided:

        The available assertions after navigating to an element depend on the ELEMENT_ASSERT parameter of the given AssertFactory<ELEMENT, ELEMENT_ASSERT> (AssertJ can't figure it out because of Java type erasure).

        Example with String element assertions:

         Iterable<String> hobbits = newHashSet("frodo", "sam", "pippin");
        
         // build an AssertFactory for StringAssert (much nicer with Java 8 lambdas)
         AssertFactory<String, StringAssert> stringAssertFactory = new AssertFactory<String, StringAssert>() {
           @Override
           public StringAssert createAssert(String string) {
             return new StringAssert(string);
           }
         };
        
         // assertion succeeds with String assertions chained after first()
         then(hobbits, stringAssertFactory).first()
                                           .startsWith("fro")
                                           .endsWith("do");
        Parameters:
        actual - the actual value.
        assertFactory - the factory used to create the elements assert instance.
        Returns:
        the created assertion object.
      • then

        public static <ACTUAL extends java.lang.Iterable<? extends ELEMENT>,​ELEMENT,​ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,​ELEMENT>> ClassBasedNavigableIterableAssert<?,​ACTUAL,​ELEMENT,​ELEMENT_ASSERT> then​(ACTUAL actual,
                                                                                                                                                                                                                                                               java.lang.Class<ELEMENT_ASSERT> assertClass)
        Creates a new instance of ClassBasedNavigableIterableAssert allowing to navigate to any Iterable element in order to perform assertions on it.

        Navigational methods provided:

        The available assertions after navigating to an element depend on the given assertClass (AssertJ can't find the element assert type by itself because of Java type erasure).

        Example with String element assertions:

         Iterable<String> hobbits = newHashSet("frodo", "sam", "pippin");
        
         // assertion succeeds with String assertions chained after first()
         then(hobbits, StringAssert.class).first()
                                          .startsWith("fro")
                                          .endsWith("do");
        Parameters:
        actual - the actual value.
        assertClass - the class used to create the elements assert instance.
        Returns:
        the created assertion object.
      • then

        public static <ACTUAL extends java.util.List<? extends ELEMENT>,​ELEMENT,​ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,​ELEMENT>> FactoryBasedNavigableListAssert<?,​ACTUAL,​ELEMENT,​ELEMENT_ASSERT> then​(java.util.List<? extends ELEMENT> actual,
                                                                                                                                                                                                                                                         AssertFactory<ELEMENT,​ELEMENT_ASSERT> assertFactory)
        Creates a new instance of FactoryBasedNavigableListAssert allowing to navigate to any List element in order to perform assertions on it.

        Navigational methods provided:

        The available assertions after navigating to an element depend on the ELEMENT_ASSERT parameter of the given AssertFactory<ELEMENT, ELEMENT_ASSERT> (AssertJ can't figure it out because of Java type erasure).

        Example with String element assertions:

         List<String> hobbits = newArrayList("frodo", "sam", "pippin");
        
         // build an AssertFactory for StringAssert (much nicer with Java 8 lambdas)
         AssertFactory<String, StringAssert> stringAssertFactory = new AssertFactory<String, StringAssert>() {
           @Override
           public StringAssert createAssert(String string) {
             return new StringAssert(string);
           }
         };
        
         // assertion succeeds with String assertions chained after first()
         then(hobbits, stringAssertFactory).first()
                                           .startsWith("fro")
                                           .endsWith("do");
        Parameters:
        actual - the actual value.
        assertFactory - the factory used to create the elements assert instance.
        Returns:
        the created assertion object.
      • then

        public static <ELEMENT,​ACTUAL extends java.util.List<? extends ELEMENT>,​ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT,​ELEMENT>> ClassBasedNavigableListAssert<?,​ACTUAL,​ELEMENT,​ELEMENT_ASSERT> then​(java.util.List<? extends ELEMENT> actual,
                                                                                                                                                                                                                                                       java.lang.Class<ELEMENT_ASSERT> assertClass)
        Creates a new instance of ClassBasedNavigableListAssert allowing to navigate to any List element in order to perform assertions on it.

        Navigational methods provided:

        The available assertions after navigating to an element depend on the given assertClass (AssertJ can't find the element assert type by itself because of Java type erasure).

        Example with String element assertions:

         List<String> hobbits = newArrayList("frodo", "sam", "pippin");
        
         // assertion succeeds with String assertions chained after first()
         then(hobbits, StringAssert.class).first()
                                          .startsWith("fro")
                                          .endsWith("do");
        Parameters:
        actual - the actual value.
        assertClass - the class used to create the elements assert instance.
        Returns:
        the created assertion object.
      • then

        public static AbstractDoubleAssert<?> then​(double actual)
        Creates a new instance of DoubleAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • then

        public static AbstractDoubleAssert<?> then​(java.lang.Double actual)
        Creates a new instance of DoubleAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • then

        public static AbstractFileAssert<?> then​(java.io.File actual)
        Creates a new instance of FileAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • then

        public static <RESULT> AbstractFutureAssert<?,​? extends java.util.concurrent.Future<? extends RESULT>,​RESULT> then​(java.util.concurrent.Future<RESULT> actual)
        Creates a new instance of FutureAssert.
        Parameters:
        actual - the future to test
        Returns:
        the created assertion object
        Since:
        2.7.0 / 3.7.0
      • then

        public static AbstractInputStreamAssert<?,​? extends java.io.InputStream> then​(java.io.InputStream actual)
        Creates a new instance of InputStreamAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • then

        public static AbstractFloatAssert<?> then​(float actual)
        Creates a new instance of FloatAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • then

        public static AbstractFloatAssert<?> then​(java.lang.Float actual)
        Creates a new instance of FloatAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • then

        public static AbstractIntegerAssert<?> then​(int actual)
        Creates a new instance of IntegerAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • then

        public static AbstractIntArrayAssert<?> then​(int[] actual)
        Creates a new instance of IntArrayAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • then

        public static AbstractIntegerAssert<?> then​(java.lang.Integer actual)
        Creates a new instance of IntegerAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • then

        public static <T> AbstractListAssert<?,​java.util.List<? extends T>,​T,​ObjectAssert<T>> then​(java.util.List<? extends T> actual)
        Creates a new instance of ListAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • then

        public static AbstractLongAssert<?> then​(long actual)
        Creates a new instance of LongAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • then

        public static AbstractLongAssert<?> then​(java.lang.Long actual)
        Creates a new instance of LongAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • then

        public static AbstractLongArrayAssert<?> then​(long[] actual)
        Creates a new instance of LongArrayAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • then

        public static <T> AbstractObjectAssert<?,​T> then​(T actual)
        Creates a new instance of ObjectAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • then

        public static <K,​V> MapAssert<K,​V> then​(java.util.Map<K,​V> actual)
        Creates a new instance of MapAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • then

        public static AbstractShortAssert<?> then​(short actual)
        Creates a new instance of ShortAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • then

        public static AbstractShortAssert<?> then​(java.lang.Short actual)
        Creates a new instance of ShortAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • then

        public static AbstractCharSequenceAssert<?,​? extends java.lang.CharSequence> then​(java.lang.CharSequence actual)
        Creates a new instance of CharSequenceAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • then

        public static AbstractCharSequenceAssert<?,​java.lang.String> then​(java.lang.String actual)
        Creates a new instance of StringAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • then

        public static AbstractDateAssert<?> then​(java.util.Date actual)
        Creates a new instance of DateAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • then

        public static AbstractThrowableAssert<?,​? extends java.lang.Throwable> then​(java.lang.Throwable actual)
        Creates a new instance of ThrowableAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion Throwable.
      • thenThrownBy

        public static AbstractThrowableAssert<?,​? extends java.lang.Throwable> thenThrownBy​(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() {
            thenThrownBy(() -> { throw new Exception("boom!") }).isInstanceOf(Exception.class)
                                                                .hasMessageContaining("boom");
          }
        Java 7 example :
         thenThrownBy(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.
      • then

        public static AbstractUriAssert<?> then​(java.net.URI actual)
        Creates a new instance of UriAssert.
        Parameters:
        actual - the actual value.
        Returns:
        the created assertion object.
      • then

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

        public static <T extends AssertDelegateTarget> T then​(T assertion)
        Returns the given assertion. This method improves code readability by surrounding the given assertion with then.

        Consider for example the following MyButton and MyButtonAssert classes:

         public class MyButton extends JButton {
        
           private boolean blinking;
        
           public boolean isBlinking() { return this.blinking; }
        
           public void setBlinking(boolean blink) { this.blinking = blink; }
        
         }
        
         private static class MyButtonAssert implements AssertDelegateTarget {
        
           private MyButton button;
           MyButtonAssert(MyButton button) { this.button = button; }
        
           void isBlinking() {
             // standard assertion from core Assertions.then
             then(button.isBlinking()).isTrue();
           }
        
           void isNotBlinking() {
             // standard assertion from core Assertions.then
             then(button.isBlinking()).isFalse();
           }
         }
        As MyButtonAssert implements AssertDelegateTarget, you can use then(buttonAssert).isBlinking(); instead of buttonAssert.isBlinking(); to have easier to read assertions:
         @Test
         public void AssertDelegateTarget_example() {
        
           MyButton button = new MyButton();
           MyButtonAssert buttonAssert = new MyButtonAssert(button);
        
           // you can encapsulate MyButtonAssert assertions methods within then
           then(buttonAssert).isNotBlinking(); // same as : buttonAssert.isNotBlinking();
        
           button.setBlinking(true);
        
           then(buttonAssert).isBlinking(); // same as : buttonAssert.isBlinking();
         }
        Type Parameters:
        T - the generic type of the user-defined assert.
        Parameters:
        assertion - the assertion to return.
        Returns:
        the given assertion.
      • then

        public static <T> T then​(AssertProvider<T> component)
        Delegates the creation of the Assert to the AssertProvider.assertThat() of the given component.

        Read the comments on AssertProvider for an example of its usage.

        Parameters:
        component - the component that creates its own assert
        Returns:
        the associated Assert of the given component