# AssertStorageAction

Artifact: [androidx.test.backup:backup](https://developer.android.com/jetpack/androidx/releases/test-backup) [View Source](https://cs.android.com/search?q=file:androidx/test/backup/actions/AssertStorageAction.kt+class:androidx.test.backup.actions.AssertStorageAction) Added in [1.0.0-alpha04](https://developer.android.com/jetpack/androidx/releases/test-backup#1.0.0-alpha04)

*** ** * ** ***


```
public final class AssertStorageAction implements BackupDeviceAction
```

<br />

*** ** * ** ***

Asserts the correctness of restored test data.

Parses the configuration from `https://developer.android.com/reference/androidx/test/backup/BackupDeviceActionArgs` and verifies `https://developer.android.com/reference/android/content/SharedPreferences.html`, Preferences DataStores, SQLite databases, or raw file contents in credential-encrypted or device-protected storage. See `https://developer.android.com/reference/androidx/test/backup/BackupActionInputKeys` for the keys each storage type consumes. With `https://developer.android.com/reference/androidx/test/backup/BackupActionInputKeys#EXPECT_NULL()`, it verifies that the data is absent.

A mismatch is reported as `https://developer.android.com/reference/androidx/test/backup/BackupDeviceActionResult#failure(kotlin.String,kotlin.collections.Map)` carrying the expected and the actual value, not as a thrown exception. Long values are shortened to the part where they differ.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/test/backup/actions/AssertStorageAction#AssertStorageAction()()` |

| ### Public methods |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/backup/BackupDeviceActionResult` | `https://developer.android.com/reference/androidx/test/backup/actions/AssertStorageAction#execute(android.content.Context,androidx.test.backup.BackupDeviceActionArgs)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/backup/BackupDeviceActionArgs args)` Runs the action payload. |

## Public constructors

### AssertStorageAction

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

```
public AssertStorageAction()
```

## Public methods

### execute

```
public @NonNull BackupDeviceActionResult execute(@NonNull Context context, @NonNull BackupDeviceActionArgs args)
```

Runs the action payload.

Implementations should report a recoverable problem, such as a missing argument or a failed assertion, by returning `https://developer.android.com/reference/androidx/test/backup/BackupDeviceActionResult#failure(kotlin.String,kotlin.collections.Map)` rather than by throwing. The host treats a thrown exception as a crash of the action and reports it with a stack trace.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/content/Context.html context` | application context on the target device |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/backup/BackupDeviceActionArgs args` | input arguments passed from the host orchestrator, keyed by `https://developer.android.com/reference/androidx/test/backup/BackupActionInputKeys` |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/test/backup/BackupDeviceActionResult` | result returned to the host, keyed by `https://developer.android.com/reference/androidx/test/backup/BackupActionOutputKeys` |