# TestNavigationEventDispatcherOwner

Artifact: [androidx.navigationevent:navigationevent-testing](https://developer.android.com/jetpack/androidx/releases/navigationevent) [View Source](https://cs.android.com/search?q=file:androidx/navigationevent/testing/TestNavigationDispatcherOwner.kt+class:androidx.navigationevent.testing.TestNavigationEventDispatcherOwner) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/navigationevent#1.0.0)

*** ** * ** ***


```
public final class TestNavigationEventDispatcherOwner implements NavigationEventDispatcherOwner
```

<br />

*** ** * ** ***

A test implementation of `https://developer.android.com/reference/androidx/navigationevent/NavigationEventDispatcherOwner` for verifying `https://developer.android.com/reference/androidx/navigationevent/NavigationEventDispatcher` interactions.

Use this class in tests to confirm that the `onBackCompletedFallback` and `onForwardCompletedFallback` actions are invoked as expected. It tracks the number of times these events occur.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/navigationevent/testing/TestNavigationEventDispatcherOwner#TestNavigationEventDispatcherOwner(kotlin.Function1)( @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigationevent/testing/TestNavigationEventDispatcherOwner, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> onBackCompletedFallback )` |
| `https://developer.android.com/reference/androidx/navigationevent/testing/TestNavigationEventDispatcherOwner#TestNavigationEventDispatcherOwner(kotlin.Function1,kotlin.Function1)( @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigationevent/testing/TestNavigationEventDispatcherOwner, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> onForwardCompletedFallback, @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigationevent/testing/TestNavigationEventDispatcherOwner, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> onBackCompletedFallback )` Creates a `https://developer.android.com/reference/androidx/navigationevent/testing/TestNavigationEventDispatcherOwner` with both forward and back fallbacks. |

| ### Public methods |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigationevent/NavigationEventDispatcher` | `https://developer.android.com/reference/androidx/navigationevent/testing/TestNavigationEventDispatcherOwner#getNavigationEventDispatcher()()` The `https://developer.android.com/reference/androidx/navigationevent/NavigationEventDispatcher` instance managed by this owner. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigationevent/DirectNavigationEventInput` | `https://developer.android.com/reference/androidx/navigationevent/testing/TestNavigationEventDispatcherOwner#getNavigationEventInput()()` The `https://developer.android.com/reference/androidx/navigationevent/DirectNavigationEventInput` instance managed by this owner. |
| `final int` | `https://developer.android.com/reference/androidx/navigationevent/testing/TestNavigationEventDispatcherOwner#getOnBackCompletedFallbackInvocations()()` The number of times the dispatcher's `https://developer.android.com/reference/androidx/navigationevent/testing/TestNavigationEventDispatcherOwner#onBackCompletedFallback()` lambda has been invoked. |
| `final int` | `https://developer.android.com/reference/androidx/navigationevent/testing/TestNavigationEventDispatcherOwner#getOnForwardCompletedFallbackInvocations()()` The number of times the dispatcher's `https://developer.android.com/reference/androidx/navigationevent/testing/TestNavigationEventDispatcherOwner#onForwardCompletedFallback()` lambda has been invoked. |

## Public constructors

### TestNavigationEventDispatcherOwner

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/navigationevent#1.0.0)

```
public TestNavigationEventDispatcherOwner(
    @NonNull Function1<@NonNull TestNavigationEventDispatcherOwner, Unit> onBackCompletedFallback
)
```

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigationevent/testing/TestNavigationEventDispatcherOwner, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> onBackCompletedFallback` | An optional lambda to execute when the `https://developer.android.com/reference/androidx/navigationevent/NavigationEventDispatcher` back fallback is triggered. |

### TestNavigationEventDispatcherOwner

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/navigationevent#1.2.0)

```
public TestNavigationEventDispatcherOwner(
    @NonNull Function1<@NonNull TestNavigationEventDispatcherOwner, Unit> onForwardCompletedFallback,
    @NonNull Function1<@NonNull TestNavigationEventDispatcherOwner, Unit> onBackCompletedFallback
)
```

Creates a `https://developer.android.com/reference/androidx/navigationevent/testing/TestNavigationEventDispatcherOwner` with both forward and back fallbacks.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigationevent/testing/TestNavigationEventDispatcherOwner, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> onForwardCompletedFallback` | A lambda to execute when the `https://developer.android.com/reference/androidx/navigationevent/NavigationEventDispatcher` forward fallback is triggered. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigationevent/testing/TestNavigationEventDispatcherOwner, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> onBackCompletedFallback` | An optional lambda to execute when the `https://developer.android.com/reference/androidx/navigationevent/NavigationEventDispatcher` back fallback is triggered. |

## Public methods

### getNavigationEventDispatcher

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/navigationevent#1.0.0)

```
public @NonNull NavigationEventDispatcher getNavigationEventDispatcher()
```

The `https://developer.android.com/reference/androidx/navigationevent/NavigationEventDispatcher` instance managed by this owner.

This dispatcher is created with the `onBackCompletedFallback` and `onForwardCompletedFallback` lambdas provided to the `https://developer.android.com/reference/androidx/navigationevent/testing/TestNavigationEventDispatcherOwner`'s constructor, which increments `https://developer.android.com/reference/androidx/navigationevent/testing/TestNavigationEventDispatcherOwner#onBackCompletedFallbackInvocations()` and `https://developer.android.com/reference/androidx/navigationevent/testing/TestNavigationEventDispatcherOwner#onForwardCompletedFallbackInvocations()`.

### getNavigationEventInput

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/navigationevent#1.2.0)

```
public final @NonNull DirectNavigationEventInput getNavigationEventInput()
```

The `https://developer.android.com/reference/androidx/navigationevent/DirectNavigationEventInput` instance managed by this owner.

This input is automatically added to the `https://developer.android.com/reference/androidx/navigationevent/testing/TestNavigationEventDispatcherOwner#navigationEventDispatcher()` during initialization, allowing for direct simulation of navigation events.

### getOnBackCompletedFallbackInvocations

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/navigationevent#1.0.0)

```
public final int getOnBackCompletedFallbackInvocations()
```

The number of times the dispatcher's `https://developer.android.com/reference/androidx/navigationevent/testing/TestNavigationEventDispatcherOwner#onBackCompletedFallback()` lambda has been invoked.

This counter is incremented when a back navigation event completes and no `https://developer.android.com/reference/androidx/navigationevent/NavigationEventHandler` handles it.

### getOnForwardCompletedFallbackInvocations

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/navigationevent#1.2.0)

```
public final int getOnForwardCompletedFallbackInvocations()
```

The number of times the dispatcher's `https://developer.android.com/reference/androidx/navigationevent/testing/TestNavigationEventDispatcherOwner#onForwardCompletedFallback()` lambda has been invoked.

This counter is incremented when a forward navigation event completes and no `https://developer.android.com/reference/androidx/navigationevent/NavigationEventHandler` handles it.