# FakeCaptureRequest

Artifact: [androidx.camera:camera-common-testing](https://developer.android.com/jetpack/androidx/releases/camera) [View Source](https://cs.android.com/search?q=file:androidx/camera/common/testing/FakeCaptureRequest.kt+class:androidx.camera.common.testing.FakeCaptureRequest) Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

*** ** * ** ***


```
class FakeCaptureRequest : CaptureRequestWrapper
```

<br />

*** ** * ** ***

A fake implementation of `https://developer.android.com/reference/kotlin/androidx/camera/common/CaptureRequestWrapper` designed for unit testing.

This class allows tests to mock camera settings by configuring mock values for both native `https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.Key.html`s and custom `https://developer.android.com/reference/kotlin/androidx/camera/common/Metadata.Key`s.

### Kotlin Example

```kotlin
val fakeRequest = FakeCaptureRequest(
    requestParameters = mapOf(CaptureRequest.CONTROL_AE_MODE to CaptureRequest.CONTROL_AE_MODE_ON),
    requestMetadata = mapOf(customMetadataKey to "custom_value")
)

// Querying values
val aeMode = fakeRequest[CaptureRequest.CONTROL_AE_MODE] // Returns CONTROL_AE_MODE_ON
```

### Java Example

```kotlin
Map<CaptureRequest.Key<?>, Object> parameters = new HashMap<>();
parameters.put(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);

FakeCaptureRequest fakeRequest = FakeCaptureRequest.create(parameters, Collections.emptyMap());
```

### Behavior of `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeCaptureRequest#unwrapAs(java.lang.Class)`

Because `FakeCaptureRequest` does not wrap a real, native `https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.html` object, calling `unwrapAs(CaptureRequest::class.java)` will return `null`. It only supports unwrapping to `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeCaptureRequest` itself or its supertypes.

## Summary

| ### Public companion functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeCaptureRequest` | `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeCaptureRequest#create(kotlin.collections.Map,kotlin.collections.Map)( requestParameters: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.Key.html<*>, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?>, requestMetadata: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://developer.android.com/reference/kotlin/androidx/camera/common/Metadata.Key<*>, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> )` Factory method to create a `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeCaptureRequest` instance for Java interoperability. |
| `operator https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeCaptureRequest` | `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeCaptureRequest#invoke(kotlin.collections.Map,kotlin.collections.Map)( requestParameters: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.Key.html<*>, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?>, requestMetadata: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://developer.android.com/reference/kotlin/androidx/camera/common/Metadata.Key<*>, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> )` Creates a `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeCaptureRequest` instance. |

| ### Public functions |
|---|---|
| `open operator T?` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeCaptureRequest#get(android.hardware.camera2.CaptureRequest.Key)(key: https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.Key.html<T>)` Retrieves the mock value configured for the specified `https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.Key.html`. |
| `open operator T?` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeCaptureRequest#get(androidx.camera.common.Metadata.Key)(key: https://developer.android.com/reference/kotlin/androidx/camera/common/Metadata.Key<T>)` Retrieves the mock value configured for the specified `https://developer.android.com/reference/kotlin/androidx/camera/common/Metadata.Key`. |
| `open T?` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeCaptureRequest#unwrapAs(java.lang.Class)(type: https://developer.android.com/reference/java/lang/Class.html<T>)` Unwraps this object to the specified type. |

| ### Public properties |
|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.Key.html<*>>` | `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeCaptureRequest#keys()` The list of `https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.Key.html`s that have configured mock values in this fake request. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html<https://developer.android.com/reference/kotlin/androidx/camera/common/Metadata.Key<*>>` | `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeCaptureRequest#metadataKeys()` The set of custom `https://developer.android.com/reference/kotlin/androidx/camera/common/Metadata.Key`s that have configured mock values in this fake request. |

### Inherited functions

From [androidx.camera.common.CaptureRequestMetadata](https://developer.android.com/reference/kotlin/androidx/camera/common/CaptureRequestMetadata) `open T` `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/camera/common/CaptureRequestMetadata#getOrDefault(android.hardware.camera2.CaptureRequest.Key,kotlin.Any)(key: https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.Key.html<T>, default: T)`

Retrieves the value of the specified `https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.Key.html`, or returns `https://developer.android.com/reference/kotlin/androidx/camera/common/CaptureRequestMetadata#getOrDefault(android.hardware.camera2.CaptureRequest.Key,kotlin.Any)` if the key is not present or its value is `null`.
From [androidx.camera.common.Metadata](https://developer.android.com/reference/kotlin/androidx/camera/common/Metadata) `open T` `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/camera/common/Metadata#getOrDefault(androidx.camera.common.Metadata.Key,kotlin.Any)(key: https://developer.android.com/reference/kotlin/androidx/camera/common/Metadata.Key<T>, default: T)`

Retrieves the value associated with the specified `https://developer.android.com/reference/kotlin/androidx/camera/common/Metadata.Key`, or returns `https://developer.android.com/reference/kotlin/androidx/camera/common/Metadata#getOrDefault(androidx.camera.common.Metadata.Key,kotlin.Any)` if the key is not present.

## Public companion functions

### create

```
fun create(
    requestParameters: Map<CaptureRequest.Key<*>, Any?> = emptyMap(),
    requestMetadata: Map<Metadata.Key<*>, Any?> = emptyMap()
): FakeCaptureRequest
```

Factory method to create a `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeCaptureRequest` instance for Java interoperability.

| Parameters |
|---|---|
| `requestParameters: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.Key.html<*>, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> = emptyMap()` | The map of capture request keys to their mock values. Defaults to an empty map. |
| `requestMetadata: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://developer.android.com/reference/kotlin/androidx/camera/common/Metadata.Key<*>, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> = emptyMap()` | The map of custom metadata keys to their mock values. Defaults to an empty map. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeCaptureRequest` | A configured `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeCaptureRequest` instance. |

### invoke

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
operator fun invoke(
    requestParameters: Map<CaptureRequest.Key<*>, Any?> = emptyMap(),
    requestMetadata: Map<Metadata.Key<*>, Any?> = emptyMap()
): FakeCaptureRequest
```

Creates a `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeCaptureRequest` instance.

This allows constructor-like syntax in Kotlin: `FakeCaptureRequest(...)`.

| Parameters |
|---|---|
| `requestParameters: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.Key.html<*>, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> = emptyMap()` | The map of capture request keys to their mock values. Defaults to an empty map. |
| `requestMetadata: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-map/index.html<https://developer.android.com/reference/kotlin/androidx/camera/common/Metadata.Key<*>, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> = emptyMap()` | The map of custom metadata keys to their mock values. Defaults to an empty map. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeCaptureRequest` | A configured `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeCaptureRequest` instance. |

## Public functions

### get

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
open operator fun <T : Any> get(key: CaptureRequest.Key<T>): T?
```

Retrieves the mock value configured for the specified `https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.Key.html`.

| Parameters |
|---|---|
| `key: https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.Key.html<T>` | The native capture request key to query. |

| Returns |
|---|---|
| `T?` | The configured mock value, or `null` if no value was configured for the key. |

### get

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
open operator fun <T : Any> get(key: Metadata.Key<T>): T?
```

Retrieves the mock value configured for the specified `https://developer.android.com/reference/kotlin/androidx/camera/common/Metadata.Key`.

| Parameters |
|---|---|
| `key: https://developer.android.com/reference/kotlin/androidx/camera/common/Metadata.Key<T>` | The custom metadata key to query. |

| Returns |
|---|---|
| `T?` | The configured mock value, or `null` if no value was configured for the key. |

### unwrapAs

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
open fun <T : Any> unwrapAs(type: Class<T>): T?
```

Unwraps this object to the specified type.

Since this is a fake implementation and does not wrap a native Android `https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.html` object, this method will return `null` if `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeCaptureRequest#unwrapAs(java.lang.Class)` is `https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.html`. It only returns `this` (cast to `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeCaptureRequest#unwrapAs(java.lang.Class)`) if `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeCaptureRequest#unwrapAs(java.lang.Class)` is compatible with `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeCaptureRequest`.

| Parameters |
|---|---|
| `type: https://developer.android.com/reference/java/lang/Class.html<T>` | The class representing the target type. |

| Returns |
|---|---|
| `T?` | This instance if compatible with `https://developer.android.com/reference/kotlin/androidx/camera/common/testing/FakeCaptureRequest#unwrapAs(java.lang.Class)`, otherwise `null`. |

## Public properties

### keys

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
open val keys: List<CaptureRequest.Key<*>>
```

The list of `https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.Key.html`s that have configured mock values in this fake request.

### metadataKeys

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
open val metadataKeys: Set<Metadata.Key<*>>
```

The set of custom `https://developer.android.com/reference/kotlin/androidx/camera/common/Metadata.Key`s that have configured mock values in this fake request.