Class AtomicReferenceAssert<V>

    • Constructor Detail

      • AtomicReferenceAssert

        public AtomicReferenceAssert​(java.util.concurrent.atomic.AtomicReference<V> actual)
    • Method Detail

      • hasValue

        public AtomicReferenceAssert<V> hasValue​(V expectedValue)
        Verifies that the atomic under test has the given value.

        Example:

         // assertion succeeds
         assertThat(new AtomicReference("foo")).hasValue("foo");
        
         // assertion fails
         assertThat(new AtomicReference("foo")).hasValue("bar");
        Parameters:
        expectedValue - the expected value.
        Returns:
        this assertion object.
        Throws:
        java.lang.AssertionError - if the atomic under test is null.
        java.lang.AssertionError - if the atomic under test does not have the given value.
        Since:
        2.7.0 / 3.7.0
      • doesNotHaveValue

        public AtomicReferenceAssert<V> doesNotHaveValue​(V nonExpectedValue)
        Verifies that the atomic under test does not have the given value.

        Example:

         // assertion succeeds
         assertThat(new AtomicReference("foo")).doesNotHaveValue("bar");
        
         // assertion fails
         assertThat(new AtomicReference("foo")).doesNotHaveValue("foo");
        Parameters:
        nonExpectedValue - the value not expected.
        Returns:
        this assertion object.
        Throws:
        java.lang.AssertionError - if the atomic under test is null.
        java.lang.AssertionError - if the atomic under test has the given value.
        Since:
        2.7.0 / 3.7.0
      • hasValueMatching

        public AtomicReferenceAssert<V> hasValueMatching​(java.util.function.Predicate<? super V> predicate)
        Verifies that the atomic under test has a value satisfying the given predicate.

        Example:

         // assertion succeeds
         assertThat(new AtomicReference("foo")).hasValueMatching(result -> result != null);
        
         // assertion fails
         assertThat(new AtomicReference("foo")).hasValueMatching(result -> result == null); 
        Parameters:
        predicate - the Predicate to apply on the resulting value.
        Returns:
        this assertion object.
        Throws:
        java.lang.NullPointerException - if the given Predicate is null
        java.lang.AssertionError - if the atomic under test is null.
        java.lang.AssertionError - if the atomic under test value does not matches with the given predicate.
        Since:
        3.18.0
      • hasValueMatching

        public AtomicReferenceAssert<V> hasValueMatching​(java.util.function.Predicate<? super V> predicate,
                                                         java.lang.String description)
        Verifies that the atomic under test has a value satisfying the given predicate, the string parameter is used in the error message to describe the predicate.

        Example:

         // assertion succeeds
         assertThat(new AtomicReference("foo")).hasValueMatching(result -> result != null, "expected not null");
        
         // assertion fails
         assertThat(new AtomicReference("foo")).hasValueMatching(result -> result == null, "expected null");
         
        Parameters:
        predicate - the Predicate to apply on the resulting value.
        description - the Predicate description.
        Returns:
        this assertion object.
        Throws:
        java.lang.NullPointerException - if the given Predicate is null
        java.lang.AssertionError - if the atomic under test is null.
        java.lang.AssertionError - if the atomic under test value does not matches with the given predicate.
        Since:
        3.18.0
      • hasValueSatisfying

        public AtomicReferenceAssert<V> hasValueSatisfying​(java.util.function.Consumer<? super V> requirements)
        Verifies that the atomic under test has a value satisfying the given requirements.

        Example:

         // assertion succeeds
         assertThat(new AtomicReference("foo")).hasValueSatisfying(result -> assertThat(result).isNotBlank());
        
         // assertion fails
         assertThat(new AtomicReference("foo")).hasValueSatisfying(result -> assertThat(result).isBlank()); 
        Parameters:
        requirements - to assert on the actual object - must not be null.
        Returns:
        this assertion object.
        Throws:
        java.lang.NullPointerException - if the given Consumer is null
        java.lang.AssertionError - if the atomic under test is null.
        java.lang.AssertionError - if the atomic under test value does not satisfies with the given requirements.
        Since:
        3.18.0
      • hasNullValue

        public AtomicReferenceAssert<V> hasNullValue()
        Verifies that the atomic under test has the null value.

        Example:

         // assertion succeeds
         assertThat(new AtomicReference(null)).hasNullValue();
        
         // assertion fails
         assertThat(new AtomicReference("foo")).hasNullValue();
        Returns:
        this assertion object.
        Throws:
        java.lang.AssertionError - if the atomic under test does not have the null value.
        Since:
        3.25.0
      • doesNotHaveNullValue

        public AtomicReferenceAssert<V> doesNotHaveNullValue()
        Verifies that the atomic under test does not have the null value.

        Example:

         // assertion succeeds
         assertThat(new AtomicReference("foo")).doesNotHaveNullValue();
        
         // assertion fails
         assertThat(new AtomicReference(null)).doesNotHaveNullValue();
        Returns:
        this assertion object.
        Throws:
        java.lang.AssertionError - if the atomic under test has the null value.
        Since:
        3.25.0