Class ReturnsEmptyValues

  • All Implemented Interfaces:
    java.io.Serializable, Answer<java.lang.Object>

    public class ReturnsEmptyValues
    extends java.lang.Object
    implements Answer<java.lang.Object>, java.io.Serializable
    Default answer of every Mockito mock.
    • Returns appropriate primitive for primitive-returning methods
    • Returns consistent values for primitive wrapper classes (e.g. int-returning method returns 0 and Integer-returning method returns 0, too)
    • Returns empty collection for collection-returning methods (works for most commonly used collection types)
    • Returns description of mock for toString() method
    • Returns zero if references are equals otherwise non-zero for Comparable#compareTo(T other) method (see issue 184)
    • Returns an java.util.Optional#empty() empty Optional for Optional. Similarly for primitive optional variants.
    • Returns an java.util.stream.Stream#empty() empty Stream for Stream. Similarly for primitive stream variants.
    • Returns an java.time.Duration.ZERO zero Duration for empty Duration and java.time.Period.ZERO zero Period for empty Period.
    • Returns null for everything else
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static long serialVersionUID  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object answer​(InvocationOnMock invocation)  
      (package private) java.lang.Object returnValueFor​(java.lang.Class<?> type)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ReturnsEmptyValues

        public ReturnsEmptyValues()
    • Method Detail

      • answer

        public java.lang.Object answer​(InvocationOnMock invocation)
        Specified by:
        answer in interface Answer<java.lang.Object>
        Parameters:
        invocation - the invocation on the mock.
        Returns:
        the value to be returned
      • returnValueFor

        java.lang.Object returnValueFor​(java.lang.Class<?> type)