TestNavigationEventCallback


public final class TestNavigationEventCallback<T extends NavigationEventInfo> 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.

Parameters
<T extends NavigationEventInfo>

The type of NavigationEventInfo this callback handles.

Summary

Public constructors

<T extends NavigationEventInfo> TestNavigationEventCallback(
    @NonNull T currentInfo,
    T previousInfo,
    boolean isEnabled,
    @NonNull Function2<@NonNull TestNavigationEventCallback<@NonNull T>, @NonNull NavigationEventUnit> onEventStarted,
    @NonNull Function2<@NonNull TestNavigationEventCallback<@NonNull T>, @NonNull NavigationEventUnit> onEventProgressed,
    @NonNull Function1<@NonNull TestNavigationEventCallback<@NonNull T>, Unit> onEventCancelled,
    @NonNull Function1<@NonNull TestNavigationEventCallback<@NonNull T>, Unit> onEventCompleted
)

Public methods

final int

The number of times onEventCancelled has been invoked.

final int

The number of times onEventCompleted has been invoked.

final @NonNull List<@NonNull NavigationEvent>

A List of all events received by the onEventProgressed callback.

final int

The number of times onEventProgressed 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 void

Removes this callback from the NavigationEventDispatcher it is registered with.

final void
setEnabled(boolean isEnabled)

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

final void
setInfo(@NonNull T currentInfo, T previousInfo)

Updates the current and previous navigation information for this callback.

Public constructors

TestNavigationEventCallback

public <T extends NavigationEventInfo> TestNavigationEventCallback(
    @NonNull T currentInfo,
    T previousInfo,
    boolean isEnabled,
    @NonNull Function2<@NonNull TestNavigationEventCallback<@NonNull T>, @NonNull NavigationEventUnit> onEventStarted,
    @NonNull Function2<@NonNull TestNavigationEventCallback<@NonNull T>, @NonNull NavigationEventUnit> onEventProgressed,
    @NonNull Function1<@NonNull TestNavigationEventCallback<@NonNull T>, Unit> onEventCancelled,
    @NonNull Function1<@NonNull TestNavigationEventCallback<@NonNull T>, Unit> onEventCompleted
)
Parameters
<T extends NavigationEventInfo>

The type of NavigationEventInfo this callback handles.

@NonNull T currentInfo

The initial current navigation information for the callback.

T previousInfo

The initial previous navigation information. Defaults to null.

boolean isEnabled

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

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

An optional lambda to execute when onEventStarted is called.

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

An optional lambda to execute when onEventProgressed is called.

@NonNull Function1<@NonNull TestNavigationEventCallback<@NonNull T>, Unit> onEventCancelled

An optional lambda to execute when onEventCancelled is called.

@NonNull Function1<@NonNull TestNavigationEventCallback<@NonNull T>, Unit> onEventCompleted

An optional lambda to execute when onEventCompleted is called.

Public methods

getCancelledInvocations

Added in 1.0.0-alpha06
public final int getCancelledInvocations()

The number of times onEventCancelled has been invoked.

getCompletedInvocations

Added in 1.0.0-alpha06
public final int getCompletedInvocations()

The number of times onEventCompleted has been invoked.

getProgressedEvents

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

A List of all events received by the onEventProgressed callback.

getProgressedInvocations

Added in 1.0.0-alpha06
public final int getProgressedInvocations()

The number of times onEventProgressed has been invoked.

getStartedEvents

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

A List of all events received by the onEventStarted callback.

getStartedInvocations

Added in 1.0.0-alpha06
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.