Class DeterministicExecutor

  • All Implemented Interfaces:
    java.util.concurrent.Executor

    public class DeterministicExecutor
    extends java.lang.Object
    implements java.util.concurrent.Executor
    An Executor that executes commands on the thread that calls runPendingCommands or runUntilIdle. This is useful when using Mock Objects to test code that spawns background tasks.
    Author:
    nat
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void execute​(java.lang.Runnable command)  
      boolean isIdle()
      Returns whether this executor is idle -- has no pending background tasks waiting to be run.
      void runPendingCommands()
      Runs all commands that are currently pending.
      void runUntilIdle()
      Runs executed commands until there are no commands pending execution, but does not tick time forward.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DeterministicExecutor

        public DeterministicExecutor()
    • Method Detail

      • isIdle

        public boolean isIdle()
        Returns whether this executor is idle -- has no pending background tasks waiting to be run.
        Returns:
        true if there are no background tasks to be run, false otherwise.
        See Also:
        runPendingCommands(), runUntilIdle()
      • runPendingCommands

        public void runPendingCommands()
        Runs all commands that are currently pending. If those commands also schedule commands for execution, the scheduled commands will not be executed until the next call to runPendingCommands() or runUntilIdle().
      • runUntilIdle

        public void runUntilIdle()
        Runs executed commands until there are no commands pending execution, but does not tick time forward.
      • execute

        public void execute​(java.lang.Runnable command)
        Specified by:
        execute in interface java.util.concurrent.Executor