# FakeCaptureResult

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/FakeCaptureResult.kt+class:androidx.camera.common.testing.FakeCaptureResult) Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

*** ** * ** ***


```
public final class FakeCaptureResult implements CaptureResultWrapper
```

<br />

*** ** * ** ***

A fake implementation of `https://developer.android.com/reference/androidx/camera/common/CaptureResultWrapper` for testing.

Allows mock values to be configured for capture result parameters, custom metadata, camera ID, frame number, and capture request via its companion `https://developer.android.com/reference/androidx/camera/common/testing/FakeCaptureResult.Companion#invoke(androidx.camera.common.CameraId,androidx.camera.common.CameraFrameNumber,androidx.camera.common.CaptureRequestWrapper,kotlin.collections.Map,kotlin.collections.Map)` operator (Kotlin) or `https://developer.android.com/reference/androidx/camera/common/testing/FakeCaptureResult#create(kotlin.String,kotlin.Long,androidx.camera.common.CaptureRequestWrapper,kotlin.collections.Map,kotlin.collections.Map)` factory method (Java).

### Example (Kotlin)

```
val fakeResult = FakeCaptureResult(
    cameraId = CameraId("0"),
    frameNumber = CameraFrameNumber(1L),
    resultParameters = mapOf(CaptureResult.LENS_STATE to CaptureResult.LENS_STATE_MOVING)
)
```

### Example (Java)

```
FakeCaptureResult fakeResult = FakeCaptureResult.create(
    "0",
    1L,
    new FakeCaptureRequest(),
    resultParametersMap,
    resultMetadataMap
);
```

## Summary

| ### Nested types |
|---|
| `public static class https://developer.android.com/reference/androidx/camera/common/testing/FakeCaptureResult.Companion` |

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/testing/FakeCaptureResult` | `https://developer.android.com/reference/androidx/camera/common/testing/FakeCaptureResult#create(kotlin.String,kotlin.Long,androidx.camera.common.CaptureRequestWrapper,kotlin.collections.Map,kotlin.collections.Map)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html cameraId, long frameNumber, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/CaptureRequestWrapper captureRequest, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Map.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/hardware/camera2/CaptureResult.Key.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?>, https://developer.android.com/reference/java/lang/Object.html> resultParameters, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Map.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/Metadata.Key<@https://developer.android.com/reference/androidx/annotation/NonNull ?>, https://developer.android.com/reference/java/lang/Object.html> resultMetadata )` Creates a `https://developer.android.com/reference/androidx/camera/common/testing/FakeCaptureResult` instance for Java compatibility. |
| `T` | `<T extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/camera/common/testing/FakeCaptureResult#get(android.hardware.camera2.CaptureResult.Key)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/hardware/camera2/CaptureResult.Key.html<@https://developer.android.com/reference/androidx/annotation/NonNull T> key)` Retrieves the mock value for the specified `https://developer.android.com/reference/android/hardware/camera2/CaptureResult.Key.html`. |
| `T` | `<T extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/camera/common/testing/FakeCaptureResult#get(androidx.camera.common.Metadata.Key)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/Metadata.Key<@https://developer.android.com/reference/androidx/annotation/NonNull T> key)` Retrieves the mock value for the specified custom metadata `https://developer.android.com/reference/androidx/camera/common/testing/FakeCaptureResult#get(androidx.camera.common.Metadata.Key)`. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/CameraId` | `https://developer.android.com/reference/androidx/camera/common/testing/FakeCaptureResult#getCameraId()()` The `https://developer.android.com/reference/androidx/camera/common/CameraId` of the camera that produced this result. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/CaptureRequestWrapper` | `https://developer.android.com/reference/androidx/camera/common/testing/FakeCaptureResult#getCaptureRequest()()` The `https://developer.android.com/reference/androidx/camera/common/CaptureRequestWrapper` that generated this capture result. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/CameraFrameNumber` | `https://developer.android.com/reference/androidx/camera/common/testing/FakeCaptureResult#getFrameNumber()()` The `https://developer.android.com/reference/androidx/camera/common/CameraFrameNumber` associated with this result. |
| `@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 https://developer.android.com/reference/android/hardware/camera2/CaptureResult.Key.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?>>` | `https://developer.android.com/reference/androidx/camera/common/testing/FakeCaptureResult#getKeys()()` List of all `https://developer.android.com/reference/android/hardware/camera2/CaptureResult.Key.html`s supported by this capture result. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Set.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/Metadata.Key<@https://developer.android.com/reference/androidx/annotation/NonNull ?>>` | `https://developer.android.com/reference/androidx/camera/common/testing/FakeCaptureResult#getMetadataKeys()()` The set of all custom `https://developer.android.com/reference/androidx/camera/common/Metadata.Key`s currently available in this container. |
| `T` | `<T extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/camera/common/testing/FakeCaptureResult#unwrapAs(java.lang.Class)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Class.html<@https://developer.android.com/reference/androidx/annotation/NonNull T> type)` Attempts to unwrap this fake object. |

### Inherited methods

From [androidx.camera.common.CaptureResultMetadata](https://developer.android.com/reference/androidx/camera/common/CaptureResultMetadata) `@https://developer.android.com/reference/androidx/annotation/NonNull T` `<T extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/camera/common/CaptureResultMetadata#getOrDefault(android.hardware.camera2.CaptureResult.Key,kotlin.Any)(
@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/hardware/camera2/CaptureResult.Key.html<@https://developer.android.com/reference/androidx/annotation/NonNull T> key,
@https://developer.android.com/reference/androidx/annotation/NonNull T default
)`

Retrieves the value of the specified `https://developer.android.com/reference/android/hardware/camera2/CaptureResult.Key.html`, or returns `https://developer.android.com/reference/androidx/camera/common/CaptureResultMetadata#getOrDefault(android.hardware.camera2.CaptureResult.Key,kotlin.Any)` if the key is not present or its value is null.
From [androidx.camera.common.Metadata](https://developer.android.com/reference/androidx/camera/common/Metadata) `@https://developer.android.com/reference/androidx/annotation/NonNull T` `<T extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/camera/common/Metadata#getOrDefault(androidx.camera.common.Metadata.Key,kotlin.Any)(
@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/Metadata.Key<@https://developer.android.com/reference/androidx/annotation/NonNull T> key,
@https://developer.android.com/reference/androidx/annotation/NonNull T default
)`

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

## Public methods

### create

```
public static final @NonNull FakeCaptureResult create(
    @NonNull String cameraId,
    long frameNumber,
    @NonNull CaptureRequestWrapper captureRequest,
    @NonNull Map<@NonNull CaptureResult.Key<@NonNull ?>, Object> resultParameters,
    @NonNull Map<@NonNull Metadata.Key<@NonNull ?>, Object> resultMetadata
)
```

Creates a `https://developer.android.com/reference/androidx/camera/common/testing/FakeCaptureResult` instance for Java compatibility.

This method is overloaded for Java callers to allow omitting trailing parameters with default values.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html cameraId` | The camera ID string. |
| `long frameNumber` | The frame number. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/CaptureRequestWrapper captureRequest` | The capture request wrapper that generated this result. Defaults to a default `https://developer.android.com/reference/androidx/camera/common/testing/FakeCaptureRequest`. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Map.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/hardware/camera2/CaptureResult.Key.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?>, https://developer.android.com/reference/java/lang/Object.html> resultParameters` | The map of capture result keys to their mock values. Defaults to an empty map. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Map.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/Metadata.Key<@https://developer.android.com/reference/androidx/annotation/NonNull ?>, https://developer.android.com/reference/java/lang/Object.html> resultMetadata` | The map of custom metadata keys to their mock values. Defaults to an empty map. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/common/testing/FakeCaptureResult` | A configured `https://developer.android.com/reference/androidx/camera/common/testing/FakeCaptureResult` instance. |

### get

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

```
public T <T extends Object> get(@NonNull CaptureResult.Key<@NonNull T> key)
```

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

| Returns |
|---|---|
| `T` | The configured mock value, or `null` if not set. |

### get

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

```
public T <T extends Object> get(@NonNull Metadata.Key<@NonNull T> key)
```

Retrieves the mock value for the specified custom metadata `https://developer.android.com/reference/androidx/camera/common/testing/FakeCaptureResult#get(androidx.camera.common.Metadata.Key)`.

| Returns |
|---|---|
| `T` | The configured mock value, or `null` if not set. |

### getCameraId

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

```
public @NonNull CameraId getCameraId()
```

The `https://developer.android.com/reference/androidx/camera/common/CameraId` of the camera that produced this result.

### getCaptureRequest

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

```
public @NonNull CaptureRequestWrapper getCaptureRequest()
```

The `https://developer.android.com/reference/androidx/camera/common/CaptureRequestWrapper` that generated this capture result.

This represents the request settings that were active when this result was produced.

### getFrameNumber

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

```
public @NonNull CameraFrameNumber getFrameNumber()
```

The `https://developer.android.com/reference/androidx/camera/common/CameraFrameNumber` associated with this result.

The frame number is a unique, monotonically increasing identifier for the frame.

### getKeys

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

```
public @NonNull List<@NonNull CaptureResult.Key<@NonNull ?>> getKeys()
```

List of all `https://developer.android.com/reference/android/hardware/camera2/CaptureResult.Key.html`s supported by this capture result.

The list of all `https://developer.android.com/reference/android/hardware/camera2/CaptureResult.Key.html`s that are supported and can be queried from this result.

| See also |
|---|---|
| `https://developer.android.com/reference/android/hardware/camera2/CaptureResult.html#getKeys()` |   |

### getMetadataKeys

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

```
public @NonNull Set<@NonNull Metadata.Key<@NonNull ?>> getMetadataKeys()
```

The set of all custom `https://developer.android.com/reference/androidx/camera/common/Metadata.Key`s currently available in this container.

Note that this set contains *only* custom library-defined keys. It does not include platform-specific keys (such as `https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.Key.html` or `https://developer.android.com/reference/android/hardware/camera2/CaptureResult.Key.html`), which are managed separately by the implementing wrappers.

### unwrapAs

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

```
public T <T extends Object> unwrapAs(@NonNull Class<@NonNull T> type)
```

Attempts to unwrap this fake object.

Since this is a fake implementation, it does not wrap a native platform `https://developer.android.com/reference/android/hardware/camera2/CaptureResult.html`. This method will return `null` for `https://developer.android.com/reference/android/hardware/camera2/CaptureResult.html`. It only returns `this` cast to `https://developer.android.com/reference/androidx/camera/common/testing/FakeCaptureResult#unwrapAs(java.lang.Class)` if `https://developer.android.com/reference/androidx/camera/common/testing/FakeCaptureResult#unwrapAs(java.lang.Class)` is compatible with `https://developer.android.com/reference/androidx/camera/common/testing/FakeCaptureResult`.