Class NotNull<T>

java.lang.Object
org.mockito.internal.matchers.NotNull<T>
All Implemented Interfaces:
Serializable, ArgumentMatcher<T>

public class NotNull<T> extends Object implements ArgumentMatcher<T>, Serializable
See Also:
  • Field Details

  • Constructor Details

    • NotNull

      public NotNull(Class<T> type)
  • Method Details

    • matches

      public boolean matches(Object actual)
      Description copied from interface: ArgumentMatcher
      Informs if this matcher accepts the given argument.

      The method should never assert if the argument doesn't match. It should only return false.

      See the example in the top level javadoc for ArgumentMatcher

      Specified by:
      matches in interface ArgumentMatcher<T>
      Parameters:
      actual - the argument
      Returns:
      true if this matcher accepts the given argument.
    • type

      public Class<T> type()
      Description copied from interface: ArgumentMatcher
      The type of the argument this matcher matches.

      This method is used to differentiate between a matcher used to match a raw vararg array parameter from a matcher used to match a single value passed as a vararg parameter.

      Where the matcher:

      • is at the parameter index of a vararg parameter
      • is the last matcher passed
      • this method returns a type assignable to the vararg parameter's raw type, i.e. its array type.
      ...then the matcher is matched against the raw vararg parameter, rather than the first element of the raw parameter.

      For example:

      
        // Given vararg method with signature:
        int someVarargMethod(String... args);
      
        // The following will match invocations with any number of parameters, i.e. any number of elements in the raw array.
        mock.someVarargMethod(isA(String[].class));
      
        // The following will match invocations with a single parameter, i.e. one string in the raw array.
        mock.someVarargMethod(isA(String.class));
      
        // The following will match invocations with two parameters, i.e. two strings in the raw array
        mock.someVarargMethod(isA(String.class), isA(String.class));
       

      Only matcher implementations that can conceptually match a raw vararg parameter should override this method.

      Specified by:
      type in interface ArgumentMatcher<T>
      Returns:
      the type this matcher handles. The default value of Void means the type is not known.
    • toString

      public String toString()
      Overrides:
      toString in class Object