Class FakePeriodicRunner
- java.lang.Object
-
- com.pervasivecode.utils.time.testing.FakePeriodicRunner
-
- All Implemented Interfaces:
PeriodicRunner
public class FakePeriodicRunner extends Object implements PeriodicRunner
This is a fake implementation ofPeriodicRunner
, intended for use by test code.
-
-
Field Summary
Fields Modifier and Type Field Description boolean
started
-
Constructor Summary
Constructors Constructor Description FakePeriodicRunner()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
runOnce()
Simulate the periodic timer firing and running theRunnable
task.void
setPeriodicTask(Runnable task)
Specify the task that this PeriodicRunner should run periodically.void
start()
Set an internal flag saying that this runner is in the started state.void
stop()
Set an internal flag saying that this runner is not in the started state.
-
-
-
Method Detail
-
setPeriodicTask
public void setPeriodicTask(Runnable task)
Description copied from interface:PeriodicRunner
Specify the task that this PeriodicRunner should run periodically. The specified task will not be run until after thePeriodicRunner.start()
method has been called.- Specified by:
setPeriodicTask
in interfacePeriodicRunner
- Parameters:
task
- The task to run periodically.
-
start
public void start()
Set an internal flag saying that this runner is in the started state.- Specified by:
start
in interfacePeriodicRunner
- Throws:
IllegalStateException
- if no task has been provided.
-
stop
public void stop()
Set an internal flag saying that this runner is not in the started state.- Specified by:
stop
in interfacePeriodicRunner
- Throws:
IllegalStateException
- if the task is already not in the started state.
-
runOnce
public void runOnce()
Simulate the periodic timer firing and running theRunnable
task. This will invoke the specified task once.This will also verify that this runner is in the started state: that is, that the
start()
method has been called more recently than the last call tostop()
, if any.- Throws:
IllegalStateException
- if this runner is not in the started state.
-
-