jdave
Class Specification<T>

java.lang.Object
  extended by jdave.ContainmentSupport
      extended by jdave.mock.MockSupport
          extended by jdave.Specification<T>

public abstract class Specification<T>
extends MockSupport

Author:
Joni Freeman, Pekka Enberg

Field Summary
 T be
           
 T context
           
protected  Specification<T> does
           
protected  Specification<T> must
           
protected  Specification<T> should
           
 
Constructor Summary
Specification()
           
 
Method Summary
protected  void addListener(ILifecycleListener listener)
          Add a ILifecycleListener listener to specification.
 void create()
          Create this specification.
 void destroy()
          Destroy this specification.
 IEqualityCheck equal(long expected)
           
 IEqualityCheck equal(java.lang.Number expectedNumber, double delta)
           
 IEqualityCheck equal(java.lang.Object obj)
           
 IEqualityCheck equal(java.lang.String obj)
           
 void fail(java.lang.String message)
          Fail with a message.
 void fireAfterContextCreation(java.lang.Object contextInstance, java.lang.Object createdContext)
           
 void fireAfterContextDestroy(java.lang.Object contextInstance)
           
 void fireAfterContextInstantiation(java.lang.Object contextInstance)
           
 IContextObjectFactory<T> getContextObjectFactory()
           
 IEqualityCheck isNotNull()
           
 MapContainment maps(java.lang.Object... keys)
           
 boolean needsThreadLocalIsolation()
          Returns true if thread local isolation is needed for this specification.
 Not<T> not()
           
<E extends java.lang.Throwable>
ExpectedException<E>
raise(java.lang.Class<E> expected)
           
<E extends java.lang.Throwable>
ExpectedException<E>
raise(java.lang.Class<E> expectedType, java.lang.String expectedMessage)
           
<E extends java.lang.Throwable>
ExpectedException<E>
raiseExactly(java.lang.Class<E> expected)
           
<E extends java.lang.Throwable>
ExpectedException<E>
raiseExactly(java.lang.Class<E> expected, java.lang.String expectedMessage)
           
 IContract satisfies(IContract contract)
           
protected  void setContextObjectFactory(IContextObjectFactory<T> factory)
           
static void setStringComparisonFailure(IStringComparisonFailure failure)
           
<V extends java.lang.Throwable>
void
specify(Block block, ExpectedException<V> expectation)
          The given block is expected to throw an exception.
<V extends java.lang.Throwable>
void
specify(Block block, ExpectedNoThrow<V> expectation)
          The given block is expected to not throw an exception.
 void specify(boolean expected)
           
 void specify(boolean[] actual, IContainment containment)
           
 void specify(byte[] actual, IContainment containment)
           
 void specify(char[] actual, IContainment containment)
           
<E> void
specify(java.util.Collection<E> actual, IContainment containment)
           
<E> void
specify(java.util.Collection<E> actual, jdave.Where<E> where)
          Matches all the actual objects using Hamcrest Matcher.
 void specify(double[] actual, IContainment containment)
           
 void specify(float[] actual, IContainment containment)
           
 void specify(int[] actual, IContainment containment)
           
<E> void
specify(java.lang.Iterable<E> actual, IContainment containment)
           
<E> void
specify(java.lang.Iterable<E> actual, jdave.Where<E> where)
           
<E> void
specify(java.util.Iterator<E> actual, IContainment containment)
           
<E> void
specify(java.util.Iterator<E> actual, jdave.Where<E> where)
           
 void specify(long[] actual, IContainment containment)
           
 void specify(java.util.Map<?,?> actual, MapContainment containment)
           
 void specify(java.lang.Object[] actual, IContainment containment)
           
<E> void
specify(java.lang.Object[] actual, jdave.Where<E> where)
           
 void specify(java.lang.Object obj, IContract contract)
           
 void specify(java.lang.Object actual, IEqualityCheck equalityCheck)
           
 void specify(java.lang.Object actual, org.hamcrest.Matcher<?> matcher)
          Matches the actual object using Hamcrest Matcher.
 void specify(java.lang.Object actual, java.lang.Object expected)
           
 void specify(short[] actual, IContainment containment)
           
 void specify(T actual, boolean expected)
           
 void specify(T actual, java.lang.Boolean expected)
           
<E> jdave.Where<E>
where(Each<E> each)
           
 
Methods inherited from class jdave.mock.MockSupport
checking, dummy, dummy, mock, mock, mockery, sequence, setDefaultResultForType, states, verifyMocks
 
Methods inherited from class jdave.ContainmentSupport
contain, containAll, containAll, containAll, containAll, containAll, containAll, containAll, containAll, containAll, containAll, containAny, containAny, containAny, containAny, containAny, containAny, containAny, containAny, containAny, containAny, containExactly, containExactly, containExactly, containExactly, containExactly, containExactly, containExactly, containExactly, containExactly, containExactly, containInOrder, containInOrder, containInOrder, containInOrder, containInOrder, containInOrder, containInOrder, containInOrder, containInOrder, containInOrder, containInPartialOrder, containInPartialOrder, containInPartialOrder, containInPartialOrder, containInPartialOrder, containInPartialOrder, containInPartialOrder, containInPartialOrder, containInPartialOrder, containInPartialOrder, contains, containsAll, containsAll, containsAll, containsAll, containsAll, containsAll, containsAll, containsAll, containsAll, containsAll, containsAny, containsAny, containsAny, containsAny, containsAny, containsAny, containsAny, containsAny, containsAny, containsAny, containsExactly, containsExactly, containsExactly, containsExactly, containsExactly, containsExactly, containsExactly, containsExactly, containsExactly, containsExactly, containsInOrder, containsInOrder, containsInOrder, containsInOrder, containsInOrder, containsInOrder, containsInOrder, containsInOrder, containsInOrder, containsInOrder, containsInPartialOrder, containsInPartialOrder, containsInPartialOrder, containsInPartialOrder, containsInPartialOrder, containsInPartialOrder, containsInPartialOrder, containsInPartialOrder, containsInPartialOrder, containsInPartialOrder, newAllContainment, newAllContainment, newAllContainment, newAnyContainment, newAnyContainment, newAnyContainment, newExactContainment, newExactContainment, newExactContainment, newInOrderContainment, newInOrderContainment, newInOrderContainment, newInPartialOrderContainment, newInPartialOrderContainment, newInPartialOrderContainment, newObjectContainment
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

should

protected Specification<T> should

does

protected Specification<T> does

must

protected Specification<T> must

be

public T be

context

public T context
Constructor Detail

Specification

public Specification()
Method Detail

not

public Not<T> not()

specify

public void specify(boolean expected)

specify

public void specify(T actual,
                    boolean expected)

specify

public void specify(T actual,
                    java.lang.Boolean expected)

specify

public <E> void specify(java.lang.Iterable<E> actual,
                        IContainment containment)

specify

public <E> void specify(java.util.Iterator<E> actual,
                        IContainment containment)

specify

public <E> void specify(java.util.Collection<E> actual,
                        IContainment containment)

specify

public void specify(java.lang.Object[] actual,
                    IContainment containment)

specify

public void specify(boolean[] actual,
                    IContainment containment)

specify

public void specify(byte[] actual,
                    IContainment containment)

specify

public void specify(char[] actual,
                    IContainment containment)

specify

public void specify(double[] actual,
                    IContainment containment)

specify

public void specify(float[] actual,
                    IContainment containment)

specify

public void specify(int[] actual,
                    IContainment containment)

specify

public void specify(long[] actual,
                    IContainment containment)

specify

public void specify(short[] actual,
                    IContainment containment)

specify

public void specify(java.lang.Object actual,
                    java.lang.Object expected)

specify

public void specify(java.lang.Object actual,
                    IEqualityCheck equalityCheck)

specify

public void specify(java.lang.Object actual,
                    org.hamcrest.Matcher<?> matcher)
Matches the actual object using Hamcrest Matcher.

Hamcrest provides a library of matcher objects allowing 'match' rules to be defined declaratively.


 import static org.hamcrest.Matchers.*;

 public class HamcrestSampleSpec extends Specification<Person> {
     public class SampleContext {
         public void sample() {
             specify(person.getAge(), greaterThan(30));
         }
     }
 }
 

See Hamcrest home page


specify

public <E> void specify(java.util.Collection<E> actual,
                        jdave.Where<E> where)
Matches all the actual objects using Hamcrest Matcher.

Hamcrest provides a library of matcher objects allowing 'match' rules to be defined declaratively.


 import static org.hamcrest.Matchers.*;

 public class HamcrestSampleSpec extends Specification<Person> {
     public class SampleContext {
         public void sample() {
             specify(persons, where(new Each<Person>() {{ matches(item.getAge(), is(greaterThan(30))); }}));
         }
     }
 }
 

See Hamcrest home page


specify

public <E> void specify(java.lang.Iterable<E> actual,
                        jdave.Where<E> where)
See Also:
specify(Collection, Where)

specify

public <E> void specify(java.lang.Object[] actual,
                        jdave.Where<E> where)
See Also:
specify(Collection, Where)

specify

public <E> void specify(java.util.Iterator<E> actual,
                        jdave.Where<E> where)
See Also:
specify(Collection, Where)

where

public <E> jdave.Where<E> where(Each<E> each)

specify

public <V extends java.lang.Throwable> void specify(Block block,
                                                    ExpectedException<V> expectation)
The given block is expected to throw an exception.

There's two variants for setting exception expectations.


 specify(new Block() { ... }, should.raise(SomeException.class);
 specify(new Block() { ... }, should.raiseExactly(SomeException.class);
 
The first one accepts the given exception or any of its subclasses, the second one expects an exact exception type. Both can additionally be checked against expected exception message:

 specify(new Block() { ... }, should.raise(SomeException.class, "expected message");
 specify(new Block() { ... }, should.raiseExactly(SomeException.class, "expected message");
 


specify

public <V extends java.lang.Throwable> void specify(Block block,
                                                    ExpectedNoThrow<V> expectation)
             throws java.lang.Throwable
The given block is expected to not throw an exception.

There's two variants for setting exception expectations.


 specify(new Block() { ... }, should.not().raise(SomeException.class);
 specify(new Block() { ... }, should.not().raiseExactly(SomeException.class);
 
The first one expects that the given block does not throw the exception or any of its subclasses, the second one expects that the given block does not throw the given exact exception type.

Throws:
java.lang.Throwable

specify

public void specify(java.lang.Object obj,
                    IContract contract)

equal

public IEqualityCheck equal(long expected)

equal

public IEqualityCheck equal(java.lang.String obj)

equal

public IEqualityCheck equal(java.lang.Object obj)

equal

public IEqualityCheck equal(java.lang.Number expectedNumber,
                            double delta)

raise

public <E extends java.lang.Throwable> ExpectedException<E> raise(java.lang.Class<E> expected)
See Also:
specify(Block, ExpectedException), specify(Block, ExpectedNoThrow)

raise

public <E extends java.lang.Throwable> ExpectedException<E> raise(java.lang.Class<E> expectedType,
                                                                  java.lang.String expectedMessage)
See Also:
specify(Block, ExpectedException), specify(Block, ExpectedNoThrow)

raiseExactly

public <E extends java.lang.Throwable> ExpectedException<E> raiseExactly(java.lang.Class<E> expected)
See Also:
specify(Block, ExpectedException), specify(Block, ExpectedNoThrow)

raiseExactly

public <E extends java.lang.Throwable> ExpectedException<E> raiseExactly(java.lang.Class<E> expected,
                                                                         java.lang.String expectedMessage)
See Also:
specify(Block, ExpectedException), specify(Block, ExpectedNoThrow)

satisfies

public IContract satisfies(IContract contract)

create

public void create()
            throws java.lang.Exception
Create this specification.

This method is called before the create method of the executed context has been called. Override this method to add common initialization code for contexts within a specification.

Throws:
java.lang.Exception

destroy

public void destroy()
             throws java.lang.Exception
Destroy this specification.

This method is called after the optional destroy method of the excuted context has been called. Override this method to add common destroy code for contexts within a specification.

Throws:
java.lang.Exception

needsThreadLocalIsolation

public boolean needsThreadLocalIsolation()
Returns true if thread local isolation is needed for this specification.

Some contexts set thread local variables. This may cause following behaviors to fail if they depend on initial thread local state. Thread locals can be isolated for all behavior methods of current specification by overiding this method and returning true. Then a new fresh thread is created for all methods in the specification.

Returns:
true if thread local isolation is needed for this specification. The default is false.

setContextObjectFactory

protected void setContextObjectFactory(IContextObjectFactory<T> factory)

getContextObjectFactory

public IContextObjectFactory<T> getContextObjectFactory()

addListener

protected void addListener(ILifecycleListener listener)
Add a ILifecycleListener listener to specification.

ILifecycleListener will be notified when contexts are instantiated and context objects are created and destroyed.

Parameters:
listener - a listener to get lifecycle event notifications

fireAfterContextInstantiation

public void fireAfterContextInstantiation(java.lang.Object contextInstance)

fireAfterContextCreation

public void fireAfterContextCreation(java.lang.Object contextInstance,
                                     java.lang.Object createdContext)

fireAfterContextDestroy

public void fireAfterContextDestroy(java.lang.Object contextInstance)

isNotNull

public IEqualityCheck isNotNull()

setStringComparisonFailure

public static void setStringComparisonFailure(IStringComparisonFailure failure)

maps

public MapContainment maps(java.lang.Object... keys)

specify

public void specify(java.util.Map<?,?> actual,
                    MapContainment containment)

fail

public void fail(java.lang.String message)
Fail with a message.

Parameters:
message - a message printed to the console


Copyright © 2008. All Rights Reserved.