Clockpublic final class AutoAdvancingFakeClock extends FakeClock
FakeClock extension which automatically advances time whenever an empty message is
enqueued at a future time.
The clock time is advanced to the time of enqueued empty messages. The first Handler sending
messages at a future time will be allowed to advance time to ensure there is only one primary
time source at a time. This should usually be the Handler of the internal playback loop. You can
reset the handler so that the next Handler that sends messages at a
future time becomes the primary time source.
| Constructor | Description |
|---|---|
AutoAdvancingFakeClock() |
Creates the auto-advancing clock with an initial time of 0.
|
AutoAdvancingFakeClock(long initialTimeMs) |
Creates the auto-advancing clock.
|
| Modifier and Type | Method | Description |
|---|---|---|
protected boolean |
addHandlerMessageAtTime(HandlerWrapper handler,
int message,
long timeMs) |
Adds an empty handler message to list of pending messages.
|
void |
resetHandler() |
Resets the internal handler, so that this clock can later be used with another handler.
|
addHandlerMessageAtTime, advanceTime, createHandler, currentTimeMillis, elapsedRealtime, sleep, uptimeMillispublic AutoAdvancingFakeClock()
public AutoAdvancingFakeClock(long initialTimeMs)
initialTimeMs - The initial time of the clock in milliseconds.protected boolean addHandlerMessageAtTime(HandlerWrapper handler, int message, long timeMs)
FakeClockaddHandlerMessageAtTime in class FakeClockpublic void resetHandler()