|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.emarsys.ecommon.time.MockTime
public final class MockTime
MockTime
is a singleton to mock the Time
in (unit) test cases.
If you want to use the MockTime
instead of the
default SystemTime
to test your ecommon classes
you need to set to corresponding MockTimeBuilder
for Time
instances in the Builders
registry:
Builders.set( Time.class, new MockTimeBuilder() );
Then every instance created by TimeBuilder
,
DateBuilder
or CalendarBuilder
will use
MockTime
instead of the SystemTime
.
NOTE that Builders.set(Class, com.emarsys.ecommon.builder.Builder)
will throw a BuilderException
if another Builder
is
already registered with Time
!
A short cut for installing the MockTime
instead of the
default SystemTime
in ecommon's Builders
is to call
install()
.
Method Summary | |
---|---|
long |
currentTimeMillis()
Returns the current time in milliseconds. |
static MockTime |
getInstance()
Returns the singleton instance of MockTime . |
static void |
install()
Installs the MockTime for system wide (classloader)
usage through ecommon's Builders . |
void |
setTime(long currentTimeMillis)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static final MockTime getInstance()
Returns the singleton instance of MockTime
.
If not already present a new instance will be created.
public static final void install() throws BuilderException
Installs the MockTime
for system wide (classloader)
usage through ecommon's Builders
.
After a successfull call MockTime
will be used
instead of SystemTime
in the TimeBuilder
(as well as DateBuilder
and CalendarBuilder
)
in order to be able to change the current time "systemwide"
(at least in every class that uses the ecommon builder framework).
This is a very usefull feature to "control" the system time
in test cases.
NOTE that this is only possible before any other Builder
has been registered
with
for creating Time
instances, otherwise a
BuilderException
will be raised.
This also means that there must not have been a call to
TimeBuilder.getInstance()
before installing the
MockTime
.
BuilderException
- - if another Builder
instance
has already been registered for building Time
objects.Builders.set(Class, Builder)
,
MockTimeBuilder
public void setTime(long currentTimeMillis)
currentTimeMillis
- public long currentTimeMillis()
Time
Returns the current time in milliseconds.
Subsequent calls to Time.currentTimeMillis()
must not
return values that are smaller then previous ones.
currentTimeMillis
in interface Time
Time.currentTimeMillis()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |