# TestConsumer

Artifact: [androidx.core:core-testing](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/testing/util/TestConsumer.kt+class:androidx.core.testing.util.TestConsumer) Added in [1.11.0](https://developer.android.com/jetpack/androidx/releases/core#1.11.0)

*** ** * ** ***


```
class TestConsumer<T : Any?> : Consumer<T>
```

<br />

*** ** * ** ***

An implementation of `https://developer.android.com/reference/kotlin/androidx/core/util/Consumer` to capture values during a test and allows developers to perform assertions on the values.

| Parameters |
|---|---|
| `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?>` | the type of the input to the operation |

## Summary

| ### Public constructors |
|---|
| `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/core/testing/util/TestConsumer#TestConsumer()()` |

| ### Public functions |
|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/testing/util/TestConsumer#accept(kotlin.Any)(t: T)` Records the value in the order it was received. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/core/testing/util/TestConsumer#assertValues(kotlin.collections.List)(values: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<T>)` Asserts that the `https://developer.android.com/reference/kotlin/androidx/core/testing/util/TestConsumer#assertValues(kotlin.collections.List)` match the received values. |

## Public constructors

### TestConsumer

```
<T : Any?> TestConsumer()
```

| Parameters |
|---|---|
| `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?>` | the type of the input to the operation |

## Public functions

### accept

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

```
open fun accept(t: T): Unit
```

Records the value in the order it was received.

| Parameters |
|---|---|
| `t: T` | the input argument. |

### assertValues

```
fun assertValues(values: List<T>): Unit
```

Asserts that the `https://developer.android.com/reference/kotlin/androidx/core/testing/util/TestConsumer#assertValues(kotlin.collections.List)` match the received values. This method checks the order and the elements.

| Parameters |
|---|---|
| `values: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<T>` | expected to be in the `https://developer.android.com/reference/kotlin/androidx/core/testing/util/TestConsumer` |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-assertion-error/index.html` | if the values do not match the current values. |