Class BehaviorTestKit<T>

  • Direct Known Subclasses:
    BehaviorTestKitImpl

    public abstract class BehaviorTestKit<T>
    extends java.lang.Object
    Used for synchronous testing Behaviors. Stores all effects e.g. Spawning of children, watching and offers access to what effects have taken place.

    Not for user extension or instantiation. See BehaviorTestKit.create factory methods

    For asynchronous testing of Behaviors running see ActorTestKit

    • Constructor Summary

      Constructors 
      Constructor Description
      BehaviorTestKit()  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract <U> TestInbox<U> childInbox​(ActorRef<U> child)
      Get the child inbox for the child with the given name, or fail if there is no child with the given name spawned
      abstract <U> TestInbox<U> childInbox​(java.lang.String name)
      Get the child inbox for the child with the given name, or fail if there is no child with the given name spawned
      abstract <U> BehaviorTestKit<U> childTestKit​(ActorRef<U> child)
      Get the Behavior testkit for the given child ActorRef.
      abstract void clearLog()
      Clear the log entries
      static <T> BehaviorTestKit<T> create​(Behavior<T> initialBehavior)
      JAVA API
      static <T> BehaviorTestKit<T> create​(Behavior<T> initialBehavior, java.lang.String name)
      JAVA API
      abstract Behavior<T> currentBehavior()
      The current behavior, can change any time run is called
      abstract void expectEffect​(Effect expectedEffect)
      Asserts that the oldest effect is the expectedEffect.
      abstract <U extends Effect>
      U
      expectEffectClass​(java.lang.Class<U> effectClass)
      Asserts that the oldest effect is an instance of of class T.
      abstract java.util.List<Effect> getAllEffects()
      Requests all the effects.
      abstract java.util.List<CapturedLogEvent> getAllLogEntries()
      Returns all the CapturedLogEvent issued by this behavior(s)
      abstract Effect getEffect()
      Requests the oldest Effect or akka.actor.testkit.typed.javadsl.Effects.noEffects if no effects have taken place.
      ActorRef<T> getRef()
      The self reference of the actor living inside this testkit.
      abstract boolean hasEffects()
      Returns if there have been any effects.
      abstract boolean isAlive()
      Is the current behavior alive or stopped
      abstract Behavior<T> returnedBehavior()
      Returns the current behavior as it was returned from processing the previous message.
      abstract void run​(T message)
      Send the message to the behavior and record any Effects
      abstract void runOne()
      Send the first message in the selfInbox to the behavior and run it, recording Effects.
      abstract TestInbox<T> selfInbox()
      The self inbox contains messages the behavior sent to context.self
      abstract void signal​(Signal signal)
      Send the signal to the beheavior and record any Effects
      • Methods inherited from class java.lang.Object

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

      • BehaviorTestKit

        public BehaviorTestKit()
    • Method Detail

      • create

        public static <T> BehaviorTestKit<T> create​(Behavior<T> initialBehavior,
                                                    java.lang.String name)
        JAVA API
        Parameters:
        initialBehavior - (undocumented)
        name - (undocumented)
        Returns:
        (undocumented)
      • create

        public static <T> BehaviorTestKit<T> create​(Behavior<T> initialBehavior)
        JAVA API
        Parameters:
        initialBehavior - (undocumented)
        Returns:
        (undocumented)
      • getEffect

        public abstract Effect getEffect()
        Requests the oldest Effect or akka.actor.testkit.typed.javadsl.Effects.noEffects if no effects have taken place. The effect is consumed, subsequent calls won't will not include this effect.
        Returns:
        (undocumented)
      • childInbox

        public abstract <U> TestInbox<U> childInbox​(java.lang.String name)
        Get the child inbox for the child with the given name, or fail if there is no child with the given name spawned
        Parameters:
        name - (undocumented)
        Returns:
        (undocumented)
      • childInbox

        public abstract <U> TestInbox<U> childInbox​(ActorRef<U> child)
        Get the child inbox for the child with the given name, or fail if there is no child with the given name spawned
        Parameters:
        child - (undocumented)
        Returns:
        (undocumented)
      • childTestKit

        public abstract <U> BehaviorTestKit<U> childTestKit​(ActorRef<U> child)
        Get the Behavior testkit for the given child ActorRef.
        Parameters:
        child - (undocumented)
        Returns:
        (undocumented)
      • selfInbox

        public abstract TestInbox<T> selfInbox()
        The self inbox contains messages the behavior sent to context.self
        Returns:
        (undocumented)
      • getRef

        public ActorRef<T> getRef()
        The self reference of the actor living inside this testkit.
        Returns:
        (undocumented)
      • getAllEffects

        public abstract java.util.List<Effect> getAllEffects()
        Requests all the effects. The effects are consumed, subsequent calls will only see new effects.
        Returns:
        (undocumented)
      • hasEffects

        public abstract boolean hasEffects()
        Returns if there have been any effects.
        Returns:
        (undocumented)
      • expectEffect

        public abstract void expectEffect​(Effect expectedEffect)
        Asserts that the oldest effect is the expectedEffect. Removing it from further assertions.
        Parameters:
        expectedEffect - (undocumented)
      • expectEffectClass

        public abstract <U extends Effect> U expectEffectClass​(java.lang.Class<U> effectClass)
        Asserts that the oldest effect is an instance of of class T. Consumes and returns the concrete effect for further direct assertions.
        Parameters:
        effectClass - (undocumented)
        Returns:
        (undocumented)
      • currentBehavior

        public abstract Behavior<T> currentBehavior()
        The current behavior, can change any time run is called
        Returns:
        (undocumented)
      • returnedBehavior

        public abstract Behavior<T> returnedBehavior()
        Returns the current behavior as it was returned from processing the previous message. For example if Behavior.unhandled is returned it will be kept here, but not in currentBehavior().
        Returns:
        (undocumented)
      • isAlive

        public abstract boolean isAlive()
        Is the current behavior alive or stopped
        Returns:
        (undocumented)
      • run

        public abstract void run​(T message)
        Send the message to the behavior and record any Effects
        Parameters:
        message - (undocumented)
      • runOne

        public abstract void runOne()
        Send the first message in the selfInbox to the behavior and run it, recording Effects.
      • signal

        public abstract void signal​(Signal signal)
        Send the signal to the beheavior and record any Effects
        Parameters:
        signal - (undocumented)
      • getAllLogEntries

        public abstract java.util.List<CapturedLogEvent> getAllLogEntries()
        Returns all the CapturedLogEvent issued by this behavior(s)
        Returns:
        (undocumented)
      • clearLog

        public abstract void clearLog()
        Clear the log entries