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 booleanstarted
-
Constructor Summary
Constructors Constructor Description FakePeriodicRunner()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidrunOnce()Simulate the periodic timer firing and running theRunnabletask.voidsetPeriodicTask(Runnable task)Specify the task that this PeriodicRunner should run periodically.voidstart()Set an internal flag saying that this runner is in the started state.voidstop()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:PeriodicRunnerSpecify 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:
setPeriodicTaskin 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:
startin 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:
stopin interfacePeriodicRunner- Throws:
IllegalStateException- if the task is already not in the started state.
-
runOnce
public void runOnce()
Simulate the periodic timer firing and running theRunnabletask. 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.
-
-