Class Null

java.lang.Object
org.jmock.expectation.Null

public class Null extends Object
A class that represents the null value. The Null class is used when an Expectation is set to expect nothing.

Example usage:

 public class MockX {
    private Expectation... anExpectation = new Expectation...(...);
 

public MockX() { anExpectation.setExpectNothing(); }

public void setAnExpectation(Object value) { anExpectation.setExpected(value); }

public void setActual(Object value) { anExpectation.setActual(value); } }

The act of calling Expectation.setExpectNothing() tells the expectation that it should expect no values to change. Since all Null objects are equal to themselves, most expectations set their expected value to an instance of Null, and at the same time, set their actual value to another instance of Null. This way, when
invalid reference
org.jmock.expectation.Verifiable#verify()
checks expectations, they will compare two Null objects together, which is guaranteed to succeed.
Version:
$Id$
Author:
Francois Beausoleil (fbos@users.sourceforge.net)
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The default description for all Null objects.
    static final Null
    A default Null object.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Instantiates a new Null object with the default description.
    Null(String description)
    Instantiates a new Null object and sets it's description.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    equals(Object other)
    Determines equality between two objects.
    int
    Returns this Null object's hashCode.
    Returns a string representation of this Null object.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • DEFAULT_DESCRIPTION

      public static final String DEFAULT_DESCRIPTION
      The default description for all Null objects. This String is equal to "Null".
      See Also:
    • NULL

      public static final Null NULL
      A default Null object. Instead of always instantiating new Null objects, consider using a reference to this object instead. This way, the virtual machine will not be taking the time required to instantiate an object everytime it is required.
  • Constructor Details

    • Null

      public Null()
      Instantiates a new Null object with the default description.
      See Also:
    • Null

      public Null(String description)
      Instantiates a new Null object and sets it's description.
      Parameters:
      description -
  • Method Details

    • equals

      public boolean equals(Object other)
      Determines equality between two objects. Null objects are only equal to another instance of themselves.
      Overrides:
      equals in class Object
      Parameters:
      other -
    • hashCode

      public int hashCode()
      Returns this Null object's hashCode. All Null return the same hashCode value.
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Returns a string representation of this Null object. This merely returns the string passed to the constructor initially.
      Overrides:
      toString in class Object