|
Fish & Chips Club 4.10.0.0 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Object hirondelle.fish.test.doubles.FakeDAOBehavior
public final class FakeDAOBehavior
Change the exception behavior of fake DAOs. One of the advantages of using fake DAOs is that they can be made to throw specific exceptions when desired. By default, fake DAO operations will always succeed, in the sense of not throwing an explicit exception.
You control the behavior of a fake DAO using these methods :
setBehavior(DbOperation, DbOperationResult)
to specify the desired behavior
for a given operation. If you don't call this method, then by default the fake DAO operation
will succeed.
possiblyThrowExceptionFor(DbOperation)
on the first line of your fake
DAO method. If the operation has been set to fail, then an exception will be thrown.
If not, then the operation will complete successfully.
For an illustration, see MemberDAOFake
and
TESTMemberDAO
.
Implementation Note
This class uses simple System properties to store the desired behavior. Such an implementation
is suitable only for a single threaded environment.
Nested Class Summary | |
---|---|
static class |
FakeDAOBehavior.DbOperation
Enumeration of the basic DAO operations. |
static class |
FakeDAOBehavior.DbOperationResult
Enumeration of how a basic DAO operation may succeed or fail. |
Field Summary | |
---|---|
static String |
USE_FAKE_DAOS
Name of a System property used to swap implementations between real and fake DAOs. |
Constructor Summary | |
---|---|
FakeDAOBehavior()
|
Method Summary | |
---|---|
static void |
possiblyThrowExceptionFor(FakeDAOBehavior.DbOperation aOperation)
Possibly throw an exception for the given operation. |
static void |
setBehavior(FakeDAOBehavior.DbOperation aDbOperation,
FakeDAOBehavior.DbOperationResult aDbOperationResult)
Set the desired behavior of a fake DAO operation. |
Methods inherited from class Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String USE_FAKE_DAOS
MemberDAOFake
for an illustration.
Value - "useFakeDAOs".
Constructor Detail |
---|
public FakeDAOBehavior()
Method Detail |
---|
public static void possiblyThrowExceptionFor(FakeDAOBehavior.DbOperation aOperation) throws DAOException, DuplicateException
An exception is thrown only if it has been indicated by calling
setBehavior(DbOperation, DbOperationResult)
.
DAOException
DuplicateException
public static void setBehavior(FakeDAOBehavior.DbOperation aDbOperation, FakeDAOBehavior.DbOperationResult aDbOperationResult)
|
Fish & Chips Club 4.10.0.0 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |