# CacheAsserts

Artifact: [androidx.media3:media3-test-utils](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/test/utils/CacheAsserts.java+class:androidx.media3.test.utils.CacheAsserts)

*** ** * ** ***

<br />

```
@UnstableApi
class CacheAsserts
```

<br />

*** ** * ** ***

Assertion methods for `https://developer.android.com/reference/kotlin/androidx/media3/datasource/cache/Cache`.

## Summary

| ### Nested types |
|---|
| `class https://developer.android.com/reference/kotlin/androidx/media3/test/utils/CacheAsserts.RequestSet` Defines a set of data requests. |

| ### Public functions |
|---|---|
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/CacheAsserts#assertCacheEmpty(androidx.media3.datasource.cache.Cache)(cache: https://developer.android.com/reference/kotlin/androidx/media3/datasource/cache/Cache!)` Asserts that the cache is empty. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/CacheAsserts#assertCachedData(androidx.media3.datasource.cache.Cache,androidx.media3.test.utils.FakeDataSet)(cache: https://developer.android.com/reference/kotlin/androidx/media3/datasource/cache/Cache!, fakeDataSet: https://developer.android.com/reference/kotlin/androidx/media3/test/utils/FakeDataSet!)` Asserts that the cache content is equal to the data in the `fakeDataSet`. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/CacheAsserts#assertCachedData(androidx.media3.datasource.cache.Cache,androidx.media3.test.utils.CacheAsserts.RequestSet)(cache: https://developer.android.com/reference/kotlin/androidx/media3/datasource/cache/Cache!, requestSet: https://developer.android.com/reference/kotlin/androidx/media3/test/utils/CacheAsserts.RequestSet!)` Asserts that the cache contains necessary data for the `requestSet`. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/CacheAsserts#assertDataCached(androidx.media3.datasource.cache.Cache,androidx.media3.datasource.DataSpec,byte[])( cache: https://developer.android.com/reference/kotlin/androidx/media3/datasource/cache/Cache!, dataSpec: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec!, expected: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>! )` Asserts that the cache contains the given data for `dataSpec`. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/CacheAsserts#assertReadData(androidx.media3.datasource.DataSource,androidx.media3.datasource.DataSpec,byte[])( dataSource: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource!, dataSpec: https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec!, expected: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>! )` Asserts that the read data from `dataSource` specified by `dataSpec` is equal to `expected` or not. |

## Public functions

### assertCacheEmpty

```
java-static fun assertCacheEmpty(cache: Cache!): Unit
```

Asserts that the cache is empty.

### assertCachedData

```
java-static fun assertCachedData(cache: Cache!, fakeDataSet: FakeDataSet!): Unit
```

Asserts that the cache content is equal to the data in the `fakeDataSet`.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurred reading from the Cache. |

### assertCachedData

```
java-static fun assertCachedData(cache: Cache!, requestSet: CacheAsserts.RequestSet!): Unit
```

Asserts that the cache contains necessary data for the `requestSet`.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurred reading from the Cache. |

### assertDataCached

```
java-static fun assertDataCached(
    cache: Cache!,
    dataSpec: DataSpec!,
    expected: ByteArray<Byte>!
): Unit
```

Asserts that the cache contains the given data for `dataSpec`.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurred reading from the Cache. |

### assertReadData

```
java-static fun assertReadData(
    dataSource: DataSource!,
    dataSpec: DataSpec!,
    expected: ByteArray<Byte>!
): Unit
```

Asserts that the read data from `dataSource` specified by `dataSpec` is equal to `expected` or not.

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If an error occurred reading from the Cache. |