TestNavigationEventCallback


public final class TestNavigationEventCallback extends NavigationEventCallback


A test implementation of NavigationEventCallback that records received events and invocation counts.

This class is primarily used in tests to verify that specific navigation event callbacks are triggered as expected. It captures the NavigationEvent objects and counts how many times each callback is fired.

Summary

Public constructors

TestNavigationEventCallback(
    boolean isEnabled,
    boolean isPassThrough,
    @NonNull Function2<@NonNull TestNavigationEventCallback, @NonNull NavigationEventUnit> onEventStarted,
    @NonNull Function2<@NonNull TestNavigationEventCallback, @NonNull NavigationEventUnit> onEventProgressed,
    @NonNull Function1<@NonNull TestNavigationEventCallbackUnit> onEventCancelled,
    @NonNull Function1<@NonNull TestNavigationEventCallbackUnit> onEventCompleted
)

Public methods

final int

The number of times cancelledInvocations has been invoked.

final int

The number of times completedInvocations has been invoked.

final @NonNull List<@NonNull NavigationEvent>

A List of all events received by the onEventProgressed callback.

final int

The number of times progressedInvocations has been invoked.

final @NonNull List<@NonNull NavigationEvent>

A List of all events received by the onEventStarted callback.

final int

The number of times onEventStarted has been invoked.

void

Callback for handling NavigationEventDispatcher.dispatchOnCancelled.

void

Callback for handling NavigationEventDispatcher.dispatchOnCompleted.

void

Callback for handling NavigationEventDispatcher.dispatchOnProgressed.

void

Callback for handling NavigationEventDispatcher.dispatchOnStarted.

Inherited methods

From androidx.navigationevent.NavigationEventCallback
final boolean

Controls whether this callback is active and should be considered for event dispatching.

final boolean

Whether this callback should consume the events from NavigationEventDispatcher or allow it to continue.

final void
final void
setEnabled(boolean isEnabled)

Controls whether this callback is active and should be considered for event dispatching.

Public constructors

TestNavigationEventCallback

Added in 1.0.0-alpha05
public TestNavigationEventCallback(
    boolean isEnabled,
    boolean isPassThrough,
    @NonNull Function2<@NonNull TestNavigationEventCallback, @NonNull NavigationEventUnit> onEventStarted,
    @NonNull Function2<@NonNull TestNavigationEventCallback, @NonNull NavigationEventUnit> onEventProgressed,
    @NonNull Function1<@NonNull TestNavigationEventCallbackUnit> onEventCancelled,
    @NonNull Function1<@NonNull TestNavigationEventCallbackUnit> onEventCompleted
)
Parameters
boolean isEnabled

Determines if the callback should process events. Defaults to true.

boolean isPassThrough

If true, events are passed to the next callback in the chain. Defaults to false.

@NonNull Function2<@NonNull TestNavigationEventCallback, @NonNull NavigationEventUnit> onEventStarted

An optional lambda to execute when onEventStarted is called.

@NonNull Function2<@NonNull TestNavigationEventCallback, @NonNull NavigationEventUnit> onEventProgressed

An optional lambda to execute when onEventProgressed is called.

@NonNull Function1<@NonNull TestNavigationEventCallbackUnit> onEventCancelled

An optional lambda to execute when onEventCancelled is called.

@NonNull Function1<@NonNull TestNavigationEventCallbackUnit> onEventCompleted

An optional lambda to execute when onEventCompleted is called.

Public methods

getCancelledInvocations

Added in 1.0.0-alpha05
public final int getCancelledInvocations()

The number of times cancelledInvocations has been invoked.

getCompletedInvocations

Added in 1.0.0-alpha05
public final int getCompletedInvocations()

The number of times completedInvocations has been invoked.

getProgressedEvents

Added in 1.0.0-alpha05
public final @NonNull List<@NonNull NavigationEventgetProgressedEvents()

A List of all events received by the onEventProgressed callback.

getProgressedInvocations

Added in 1.0.0-alpha05
public final int getProgressedInvocations()

The number of times progressedInvocations has been invoked.

getStartedEvents

Added in 1.0.0-alpha05
public final @NonNull List<@NonNull NavigationEventgetStartedEvents()

A List of all events received by the onEventStarted callback.

getStartedInvocations

Added in 1.0.0-alpha05
public final int getStartedInvocations()

The number of times onEventStarted has been invoked.

onEventCancelled

public void onEventCancelled()

Callback for handling NavigationEventDispatcher.dispatchOnCancelled.

onEventCompleted

public void onEventCompleted()

Callback for handling NavigationEventDispatcher.dispatchOnCompleted.

onEventProgressed

public void onEventProgressed(@NonNull NavigationEvent event)

Callback for handling NavigationEventDispatcher.dispatchOnProgressed.

onEventStarted

public void onEventStarted(@NonNull NavigationEvent event)

Callback for handling NavigationEventDispatcher.dispatchOnStarted.