# DataSourceContractTest.TestResource.Builder

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/DataSourceContractTest.java+class:androidx.media3.test.utils.DataSourceContractTest.TestResource.Builder)

*** ** * ** ***


```
class DataSourceContractTest.TestResource.Builder
```

<br />

*** ** * ** ***

Builder for `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DataSourceContractTest.TestResource` instances.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DataSourceContractTest.TestResource.Builder#Builder()()` |

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DataSourceContractTest.TestResource!` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DataSourceContractTest.TestResource.Builder#build()()` |
| `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DataSourceContractTest.TestResource.Builder!` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DataSourceContractTest.TestResource.Builder#setExpectedBytes(byte[])(expectedBytes: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!)` Sets the expected contents of this resource. |
| `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DataSourceContractTest.TestResource.Builder!` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DataSourceContractTest.TestResource.Builder#setHttpMethod(int)(@https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec.HttpMethod httpMethod: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the HTTP method that should be used for the request for this resource. |
| `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DataSourceContractTest.TestResource.Builder!` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DataSourceContractTest.TestResource.Builder#setMayResolveToUnknownLength(boolean)(value: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Sets whether `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource#open(androidx.media3.datasource.DataSpec)` may return `https://developer.android.com/reference/kotlin/androidx/media3/common/C#LENGTH_UNSET()` when passed the URI of this resource and a `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec` with `length == C.LENGTH_UNSET`. |
| `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DataSourceContractTest.TestResource.Builder!` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DataSourceContractTest.TestResource.Builder#setName(java.lang.String)(name: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!)` Sets a human-readable name for this resource which will be shown in test failure messages. |
| `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DataSourceContractTest.TestResource.Builder!` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DataSourceContractTest.TestResource.Builder#setRequestBody(byte[])(requestBody: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!)` Sets the body that should be included in a request for this resource. |
| `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DataSourceContractTest.TestResource.Builder!` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DataSourceContractTest.TestResource.Builder#setRequestHeaders(java.util.Map<java.lang.String,java.lang.String>)(requestHeaders: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-map/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>!)` Sets the headers that should be included when making a request for this resource. |
| `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DataSourceContractTest.TestResource.Builder!` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DataSourceContractTest.TestResource.Builder#setResolvedUri(java.lang.String)(uri: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!)` Sets the URI where this resource is served from. |
| `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DataSourceContractTest.TestResource.Builder!` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DataSourceContractTest.TestResource.Builder#setResolvedUri(android.net.Uri)(uri: https://developer.android.com/reference/android/net/Uri.html!)` Sets the URI where this resource is served from. |
| `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DataSourceContractTest.TestResource.Builder!` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DataSourceContractTest.TestResource.Builder#setResponseHeaders(java.util.Map<java.lang.String,java.util.List<java.lang.String>>)( responseHeaders: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-map/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>!>! )` Sets the headers associated with this resource that are expected to be present in `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource#getResponseHeaders()`. |
| `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DataSourceContractTest.TestResource.Builder!` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DataSourceContractTest.TestResource.Builder#setUnexpectedResponseHeaderKeys(java.util.Set<java.lang.String>)( unexpectedResponseHeaderKeys: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-set/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!>! )` Sets the keys that must **not** be present in `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource#getResponseHeaders()` when reading this resource. |
| `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DataSourceContractTest.TestResource.Builder!` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DataSourceContractTest.TestResource.Builder#setUri(java.lang.String)(uri: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!)` Sets the URI where this resource should be requested from. |
| `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DataSourceContractTest.TestResource.Builder!` | `@https://checkerframework.org/api/com/google/errorprone/annotations/CanIgnoreReturnValue.html https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DataSourceContractTest.TestResource.Builder#setUri(android.net.Uri)(uri: https://developer.android.com/reference/android/net/Uri.html!)` Sets the URI where this resource should be requested from. |

## Public constructors

### Builder

```
Builder()
```

## Public functions

### build

```
fun build(): DataSourceContractTest.TestResource!
```

### setExpectedBytes

```
@CanIgnoreReturnValue
fun setExpectedBytes(expectedBytes: ByteArray<Byte>!): DataSourceContractTest.TestResource.Builder!
```

Sets the expected contents of this resource. Defaults to an empty byte array.

### setHttpMethod

```
@CanIgnoreReturnValue
fun setHttpMethod(@DataSpec.HttpMethod httpMethod: Int): DataSourceContractTest.TestResource.Builder!
```

Sets the HTTP method that should be used for the request for this resource.

Tests will fail if the wrong method is used.

Defaults to `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec#HTTP_METHOD_GET()`.

### setMayResolveToUnknownLength

```
@CanIgnoreReturnValue
fun setMayResolveToUnknownLength(value: Boolean): DataSourceContractTest.TestResource.Builder!
```

Sets whether `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource#open(androidx.media3.datasource.DataSpec)` may return `https://developer.android.com/reference/kotlin/androidx/media3/common/C#LENGTH_UNSET()` when passed the URI of this resource and a `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec` with `length ==
C.LENGTH_UNSET`.

This may be because the underlying resource doesn't have an end (e.g. a 'live' MP3 file that is constantly appended to) or because the resource supports compression that means the 'true' length cannot be initially determined.

Defaults to `false`.

### setName

```
@CanIgnoreReturnValue
fun setName(name: String!): DataSourceContractTest.TestResource.Builder!
```

Sets a human-readable name for this resource which will be shown in test failure messages.

### setRequestBody

```
@CanIgnoreReturnValue
fun setRequestBody(requestBody: ByteArray<Byte>!): DataSourceContractTest.TestResource.Builder!
```

Sets the body that should be included in a request for this resource.

Tests will fail if a request is made without including this body.

Must only be set if `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DataSourceContractTest.TestResource.Builder#setHttpMethod(int)` is `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec#HTTP_METHOD_POST()` or `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSpec#HTTP_METHOD_HEAD()`.

Defaults to an empty array.

### setRequestHeaders

```
@CanIgnoreReturnValue
fun setRequestHeaders(requestHeaders: (Mutable)Map<String!, String!>!): DataSourceContractTest.TestResource.Builder!
```

Sets the headers that should be included when making a request for this resource.

Tests will fail if a request is made without including these headers.

This doesn't have to be an exhaustive list, extra headers included in the request will not cause a failure. Defaults to an empty map.

### setResolvedUri

```
@CanIgnoreReturnValue
fun setResolvedUri(uri: String!): DataSourceContractTest.TestResource.Builder!
```

Sets the URI where this resource is served from. This only needs to be explicitly set if it's different to `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DataSourceContractTest.TestResource.Builder#setUri(android.net.Uri)`. See `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DataSourceContractTest.TestResource#getResolvedUri()`.

### setResolvedUri

```
@CanIgnoreReturnValue
fun setResolvedUri(uri: Uri!): DataSourceContractTest.TestResource.Builder!
```

Sets the URI where this resource is served from. This only needs to be explicitly set if it's different to `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DataSourceContractTest.TestResource.Builder#setUri(android.net.Uri)`. See `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/DataSourceContractTest.TestResource#getResolvedUri()`.

### setResponseHeaders

```
@CanIgnoreReturnValue
fun setResponseHeaders(
    responseHeaders: (Mutable)Map<String!, (Mutable)List<String!>!>!
): DataSourceContractTest.TestResource.Builder!
```

Sets the headers associated with this resource that are expected to be present in `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource#getResponseHeaders()`.

This doesn't have to be an exhaustive list, extra headers in `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource#getResponseHeaders()` are ignored. Defaults to an empty map.

### setUnexpectedResponseHeaderKeys

```
@CanIgnoreReturnValue
fun setUnexpectedResponseHeaderKeys(
    unexpectedResponseHeaderKeys: (Mutable)Set<String!>!
): DataSourceContractTest.TestResource.Builder!
```

Sets the keys that must **not** be present in `https://developer.android.com/reference/kotlin/androidx/media3/datasource/DataSource#getResponseHeaders()` when reading this resource. Defaults to an empty set.

### setUri

```
@CanIgnoreReturnValue
fun setUri(uri: String!): DataSourceContractTest.TestResource.Builder!
```

Sets the URI where this resource should be requested from.

### setUri

```
@CanIgnoreReturnValue
fun setUri(uri: Uri!): DataSourceContractTest.TestResource.Builder!
```

Sets the URI where this resource should be requested from.