jdave.contract
Class EqualsComparableContract<T>

java.lang.Object
  extended by jdave.contract.EqualsComparableContract<T>
All Implemented Interfaces:
IContract

public abstract class EqualsComparableContract<T>
extends java.lang.Object
implements IContract

A contract which enforces the contract between equals method and Comparable interface (or Comparator interface). See the javadoc of those classes for explanation of the contract. Example usage:


 Integer obj = 5;
 specify(obj, should.satisfy(new EqualsComparableContract() {
     public Integer preceding() {
         return 4;
     }
     public Integer subsequent() {
         return 6;
     }
     public Integer equivalentByComparisonButNotByEqual() {
         // There's no Integer which would be non equal with 5 and still be equal
         // by comparison (compareTo() == 0). So return null.
         return null; 
     }
 });
 

Author:
Joni Freeman

Constructor Summary
EqualsComparableContract()
           
EqualsComparableContract(java.util.Comparator<T> comparator)
           
 
Method Summary
protected abstract  T equivalentByComparisonButNotByEqual()
          Return an instance whose compareTo is 0 with given instance, but whose equal returns false.
 void isSatisfied(java.lang.Object obj)
           
protected abstract  T preceding()
          Return an instance which should preceed the given instance.
protected abstract  T subsequent()
          Return an instance which should be after the given instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EqualsComparableContract

public EqualsComparableContract()

EqualsComparableContract

public EqualsComparableContract(java.util.Comparator<T> comparator)
Method Detail

isSatisfied

public void isSatisfied(java.lang.Object obj)
                 throws ExpectationFailedException
Specified by:
isSatisfied in interface IContract
Throws:
ExpectationFailedException

preceding

protected abstract T preceding()
Return an instance which should preceed the given instance.

See Also:
isSatisfied(Object)

subsequent

protected abstract T subsequent()
Return an instance which should be after the given instance.

See Also:
isSatisfied(Object)

equivalentByComparisonButNotByEqual

protected abstract T equivalentByComparisonButNotByEqual()
Return an instance whose compareTo is 0 with given instance, but whose equal returns false. Return null if no such instance exists.

See Also:
isSatisfied(Object)


Copyright © 2008. All Rights Reserved.