FSM Unit Tests

Purpose

The FSM Unit Tests verify the correctness and reliability of the Finite State Machine (FSM) that governs media playback and ad integration within the player system. Specifically, they ensure that the FSM transitions through appropriate states in response to playback events, ad retrieval outcomes, user interactions, and error conditions. This testing subtopic addresses the critical need to validate the complex state logic controlling content and advertisement playback, including support for VPAID ads and preroll/midroll ad flows.

Functionality

This subtopic encompasses a suite of unit tests that simulate FSM state transitions by injecting input events and asserting the resulting FSM state. The tests cover:

These tests simulate user and system events by calling the FSM’s `transit()` method with defined `Input` enums and checking the current FSM state using assertions.

Example Interaction Snippet

playerFsm.transit(Input.INITIALIZE);
assertTrue(playerFsm.getCurrentState() instanceof FetchCuePointState);

playerFsm.transit(Input.HAS_PREROLL_AD);
assertTrue(playerFsm.getCurrentState() instanceof MakingPrerollAdCallState);

playerFsm.transit(Input.PRE_ROLL_AD_RECEIVED);
assertTrue(playerFsm.getCurrentState() instanceof AdPlayingState);

playerFsm.transit(Input.VPAID_MANIFEST);
assertTrue(playerFsm.getCurrentState() instanceof VpaidState);

This snippet illustrates transitioning from initialization to preroll ad fetching, ad playing, and then to VPAID ad playback.

Integration with the Parent Topic and Other Subtopics

Under the broader topic of **Logging and Testing**, FSM Unit Tests provide a focused validation layer for the FSM playback logic that orchestrates the media player’s core behavior. While the parent topic includes logging utilities and instrumentation tests for overall system reliability, this subtopic uniquely concentrates on functional correctness of the FSM’s state transitions and error handling.

This testing ensures the FSM layer — which integrates with ad and cue point management, playback controllers, and VPAID interfaces — behaves predictably. It complements:

By validating FSM behavior independently, this subtopic helps prevent playback regressions and facilitates confident enhancements to playback and ad logic.

Diagram: FSM Unit Test State Transition Flow

The following flowchart visualizes a typical FSM state transition sequence exercised by the unit tests, highlighting key states and input triggers:

flowchart TD
    Init[Initialize FSM] --> FetchCue[FetchCuePointState]
    FetchCue -->|No Preroll Ad| MoviePlay[MoviePlayingState]
    FetchCue -->|Has Preroll Ad| PreRollCall[MakingPrerollAdCallState]
    PreRollCall --> PreRollAd[AdPlayingState]
    PreRollAd -->|Next Ad| PreRollAd
    PreRollAd -->|VPAID Manifest| VpaidState[VpaidState]
    VpaidState -->|VPAID Finish| MoviePlay
    MoviePlay --> MakeAdCall[MakingAdCallState]
    MakeAdCall --> ReceiveAd[ReceiveAdState]
    ReceiveAd --> ShowAd[AdPlayingState]
    ShowAd -->|Next Ad| ShowAd
    ShowAd -->|Ad Click| VastSandbox[VastAdInteractionSandBoxState]
    VastSandbox -->|Back to Player| ShowAd
    ShowAd -->|VPAID Manifest| VpaidState
    MoviePlay -->|Movie Finish| FinishState
    FinishState[FinishState] --> End[End]

This diagram represents the core states and transitions tested, including preroll ads, midroll ad calls, VPAID ad playback, user interactions (ad clicks), and completion. It emphasizes the sequence of inputs leading the FSM through ad and content playback cycles.


By rigorously exercising these state flows and factory behaviors, the FSM Unit Tests provide a foundation for a robust, maintainable playback engine that integrates content and advanced ad experiences seamlessly.