# 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)

*** ** * ** ***


```
public final class TestConsumer<T extends Object> implements Consumer<@NonNull T>
```

<br />

*** ** * ** ***

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

| Parameters |
|---|---|
| `<T extends https://developer.android.com/reference/java/lang/Object.html>` | the type of the input to the operation |

## Summary

| ### Public constructors |
|---|
| `<T extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/core/testing/util/TestConsumer#TestConsumer()()` |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/core/testing/util/TestConsumer#accept(kotlin.Any)(@https://developer.android.com/reference/androidx/annotation/NonNull T t)` Records the value in the order it was received. |
| `final void` | `https://developer.android.com/reference/androidx/core/testing/util/TestConsumer#assertValues(kotlin.collections.List)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull T> values)` Asserts that the `https://developer.android.com/reference/androidx/core/testing/util/TestConsumer#assertValues(kotlin.collections.List)` match the received values. |

## Public constructors

### TestConsumer

```
public <T extends Object> TestConsumer()
```

| Parameters |
|---|---|
| `<T extends https://developer.android.com/reference/java/lang/Object.html>` | the type of the input to the operation |

## Public methods

### accept

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

```
public void accept(@NonNull T t)
```

Records the value in the order it was received.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull T t` | the input argument. |

### assertValues

```
public final void assertValues(@NonNull List<@NonNull T> values)
```

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

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull T> values` | expected to be in the `https://developer.android.com/reference/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. |