# Stub

Artifact: [androidx.health.connect:connect-testing](https://developer.android.com/jetpack/androidx/releases/health-connect) [View Source](https://cs.android.com/search?q=file:androidx/health/connect/client/testing/stubs/Stub.kt+class:androidx.health.connect.client.testing.stubs.Stub) Added in [1.0.0-alpha04](https://developer.android.com/jetpack/androidx/releases/health-connect#1.0.0-alpha04)

*** ** * ** ***


```
fun interface Stub<T : Any?, R : Any>
```

<br />

Known direct subclasses [MutableStub](https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/stubs/MutableStub)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/stubs/MutableStub` | A `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/stubs/Stub` whose defaultHandler and queue can be mutated at any point. |

*** ** * ** ***

Represents a stub mapping from a request `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/stubs/Stub` to a response `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/stubs/Stub`.

Stubs are usually created with the `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/stubs/package-summary#stub(kotlin.Any)` function or the `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/stubs/MutableStub` class.

There are three possible outcomes of a stub:

- A value of type `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/stubs/Stub` is returned meaning that the request has succeeded and the value should be returned to the caller.

- An exception is thrown meaning that the request has failed and the error should be returned to the caller.u

- Null (`null`) is returned meaning that the request has not been processed by this stub, in which case the client may call another stub or somehow fallback to a default behaviour.

Example Stub where output depends on input:

```kotlin
import androidx.health.connect.client.testing.stubs.Stub
import androidx.health.connect.client.testing.stubs.stub

val stub: Stub<Int, String> = Stub { if (it == 0) "zero" else it.toString() }
stub.next(request = 0) // Returns "zero"
stub.next(request = 1) // Returns "1"
stub.next(request = 2) // Returns "2"
```

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/stubs/package-summary#stub(kotlin.Any)` |   |
| `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/stubs/MutableStub` |   |

## Summary

| ### Public functions |
|---|---|
| `R?` | `https://developer.android.com/reference/kotlin/androidx/health/connect/client/testing/stubs/Stub#next(kotlin.Any)(request: T)` Returns the next item. |

## Public functions

### next

Added in [1.0.0-alpha04](https://developer.android.com/jetpack/androidx/releases/health-connect#1.0.0-alpha04)

```
fun next(request: T): R?
```

Returns the next item.