|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjdave.ContainmentSupport
jdave.mock.MockSupport
jdave.Specification<T>
public abstract class Specification<T>
| 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(Number expectedNumber,
double delta)
|
|
IEqualityCheck |
equal(Object obj)
|
|
IEqualityCheck |
equal(String obj)
|
|
void |
fail(String message)
Fail with a message. |
|
void |
fireAfterContextCreation(Object contextInstance,
Object createdContext)
|
|
void |
fireAfterContextDestroy(Object contextInstance)
|
|
void |
fireAfterContextInstantiation(Object contextInstance)
|
|
IContextObjectFactory<T> |
getContextObjectFactory()
|
|
IEqualityCheck |
isNotNull()
|
|
MapContainment |
maps(Object... keys)
|
|
boolean |
needsThreadLocalIsolation()
Returns true if thread local isolation is needed for this
specification. |
|
Not<T> |
not()
|
|
|
raise(Class<E> expected)
|
|
|
raise(Class<E> expectedType,
String expectedMessage)
|
|
|
raiseExactly(Class<E> expected)
|
|
|
raiseExactly(Class<E> expected,
String expectedMessage)
|
|
IContract |
satisfies(IContract contract)
|
|
protected void |
setContextObjectFactory(IContextObjectFactory<T> contextObjectFactory)
|
|
static void |
setStringComparisonFailure(IStringComparisonFailure failure)
|
|
|
specify(Block block,
ExpectedException<V> expectation)
The given block is expected to throw an exception. |
|
|
specify(Block block,
ExpectedNoThrow<V> expectation)
The given block is expected to not throw an exception. |
|
void |
specify(boolean expected)
|
|
|
specify(boolean[] actual,
IContainment<E> containment)
|
|
|
specify(byte[] actual,
IContainment<E> containment)
|
|
|
specify(char[] actual,
IContainment<E> containment)
|
|
|
specify(Collection<E> actual,
IContainment<E> containment)
|
|
|
specify(Collection<E> actual,
jdave.Where<E> where)
Matches all the actual objects using Hamcrest Matcher. |
|
|
specify(double[] actual,
IContainment<E> containment)
|
|
|
specify(float[] actual,
IContainment<E> containment)
|
|
|
specify(int[] actual,
IContainment<E> containment)
|
|
|
specify(Iterable<E> actual,
jdave.Where<E> where)
|
|
|
specify(Iterator<E> actual,
IContainment<E> containment)
|
|
|
specify(Iterator<E> actual,
jdave.Where<E> where)
|
|
|
specify(long[] actual,
IContainment<E> containment)
|
|
void |
specify(Map<?,?> actual,
MapContainment containment)
|
|
|
specify(Object[] actual,
IContainment<E> containment)
|
|
|
specify(Object[] actual,
jdave.Where<E> where)
|
|
void |
specify(Object obj,
IContract contract)
|
|
void |
specify(Object actual,
IEqualityCheck equalityCheck)
|
|
void |
specify(Object actual,
org.hamcrest.Matcher<?> matcher)
Matches the actual object using Hamcrest Matcher. |
|
void |
specify(Object actual,
Object expected)
|
|
|
specify(short[] actual,
IContainment<E> containment)
|
|
void |
specify(T actual,
boolean expected)
|
|
void |
specify(T actual,
Boolean expected)
|
|
|
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 java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected Specification<T> should
protected Specification<T> does
protected Specification<T> must
public T be
public T context
| Constructor Detail |
|---|
public Specification()
| Method Detail |
|---|
public Not<T> not()
public void specify(boolean expected)
public void specify(T actual,
boolean expected)
public void specify(T actual,
Boolean expected)
public <E> void specify(Iterator<E> actual,
IContainment<E> containment)
public <E> void specify(Collection<E> actual,
IContainment<E> containment)
public <E> void specify(Object[] actual,
IContainment<E> containment)
public <E> void specify(boolean[] actual,
IContainment<E> containment)
public <E> void specify(byte[] actual,
IContainment<E> containment)
public <E> void specify(char[] actual,
IContainment<E> containment)
public <E> void specify(double[] actual,
IContainment<E> containment)
public <E> void specify(float[] actual,
IContainment<E> containment)
public <E> void specify(int[] actual,
IContainment<E> containment)
public <E> void specify(long[] actual,
IContainment<E> containment)
public <E> void specify(short[] actual,
IContainment<E> containment)
public void specify(Object actual,
Object expected)
public void specify(Object actual,
IEqualityCheck equalityCheck)
public void specify(Object actual,
org.hamcrest.Matcher<?> matcher)
Hamcrest provides a library of matcher objects allowing 'match' rules to be defined declaratively.
<code>
import static org.hamcrest.Matchers.*;
public class HamcrestSampleSpec extends Specification<Person> {
public class SampleContext {
public void sample() {
specify(person.getAge(), greaterThan(30));
}
}
}
</code>
public <E> void specify(Collection<E> actual,
jdave.Where<E> where)
Hamcrest provides a library of matcher objects allowing 'match' rules to be defined declaratively.
<code>
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))); }}));
}
}
}
</code>
public <E> void specify(Iterable<E> actual,
jdave.Where<E> where)
specify(Collection, Where)
public <E> void specify(Object[] actual,
jdave.Where<E> where)
specify(Collection, Where)
public <E> void specify(Iterator<E> actual,
jdave.Where<E> where)
specify(Collection, Where)public <E> jdave.Where<E> where(Each<E> each)
public <V extends Throwable> void specify(Block block,
ExpectedException<V> expectation)
There's two variants for setting exception expectations.
<code>
specify(new Block() { ... }, should.raise(SomeException.class);
specify(new Block() { ... }, should.raiseExactly(SomeException.class);
</code>
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:
<code>
specify(new Block() { ... }, should.raise(SomeException.class, "expected message");
specify(new Block() { ... }, should.raiseExactly(SomeException.class, "expected message");
</code>
public <V extends Throwable> void specify(Block block,
ExpectedNoThrow<V> expectation)
throws Throwable
There's two variants for setting exception expectations.
<code>
specify(new Block() { ... }, should.not().raise(SomeException.class);
specify(new Block() { ... }, should.not().raiseExactly(SomeException.class);
</code>
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.
Throwable
public void specify(Object obj,
IContract contract)
public IEqualityCheck equal(long expected)
public IEqualityCheck equal(String obj)
public IEqualityCheck equal(Object obj)
public IEqualityCheck equal(Number expectedNumber,
double delta)
public <E extends Throwable> ExpectedException<E> raise(Class<E> expected)
specify(Block, ExpectedException),
specify(Block, ExpectedNoThrow)
public <E extends Throwable> ExpectedException<E> raise(Class<E> expectedType,
String expectedMessage)
specify(Block, ExpectedException),
specify(Block, ExpectedNoThrow)public <E extends Throwable> ExpectedException<E> raiseExactly(Class<E> expected)
specify(Block, ExpectedException),
specify(Block, ExpectedNoThrow)
public <E extends Throwable> ExpectedException<E> raiseExactly(Class<E> expected,
String expectedMessage)
specify(Block, ExpectedException),
specify(Block, ExpectedNoThrow)public IContract satisfies(IContract contract)
public void create()
throws Exception
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.
Exception
public void destroy()
throws Exception
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.
Exceptionpublic boolean needsThreadLocalIsolation()
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.
true if thread local isolation is needed for this
specification. The default is false.protected void setContextObjectFactory(IContextObjectFactory<T> contextObjectFactory)
public IContextObjectFactory<T> getContextObjectFactory()
protected void addListener(ILifecycleListener listener)
ILifecycleListener listener to specification.
ILifecycleListener will be notified when contexts are instantiated and context objects are created and destroyed.
listener - a listener to get lifecycle event notificationspublic void fireAfterContextInstantiation(Object contextInstance)
public void fireAfterContextCreation(Object contextInstance,
Object createdContext)
public void fireAfterContextDestroy(Object contextInstance)
public IEqualityCheck isNotNull()
public static void setStringComparisonFailure(IStringComparisonFailure failure)
public MapContainment maps(Object... keys)
public void specify(Map<?,?> actual,
MapContainment containment)
public void fail(String message)
message - a message printed to the console
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||