FakeCaptureResult


class FakeCaptureResult : CaptureResultWrapper


A fake implementation of 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 invoke operator (Kotlin) or create 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

Public companion functions

FakeCaptureResult
create(
    cameraId: String,
    frameNumber: Long,
    captureRequest: CaptureRequestWrapper,
    resultParameters: Map<CaptureResult.Key<*>, Any?>,
    resultMetadata: Map<Metadata.Key<*>, Any?>
)

Creates a FakeCaptureResult instance for Java compatibility.

operator FakeCaptureResult
invoke(
    cameraId: CameraId,
    frameNumber: CameraFrameNumber,
    captureRequest: CaptureRequestWrapper,
    resultParameters: Map<CaptureResult.Key<*>, Any?>,
    resultMetadata: Map<Metadata.Key<*>, Any?>
)

Creates a FakeCaptureResult instance for Kotlin clients.

Public functions

open operator T?
<T : Any> get(key: CaptureResult.Key<T>)

Retrieves the mock value for the specified CaptureResult.Key.

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

Retrieves the mock value for the specified custom metadata key.

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

Attempts to unwrap this fake object.

Public properties

open CameraId

The CameraId of the camera that produced this result.

open CaptureRequestWrapper

The CaptureRequestWrapper that generated this capture result.

open CameraFrameNumber

The CameraFrameNumber associated with this result.

open List<CaptureResult.Key<*>>

List of all CaptureResult.Keys supported by this capture result.

open Set<Metadata.Key<*>>

The set of all custom Metadata.Keys currently available in this container.

Inherited functions

From androidx.camera.common.CaptureResultMetadata
open T
<T : Any> getOrDefault(key: CaptureResult.Key<T>, default: T)

Retrieves the value of the specified CaptureResult.Key, or returns default if the key is not present or its value is null.

From androidx.camera.common.Metadata
open T
<T : Any> getOrDefault(key: Metadata.Key<T>, default: T)

Retrieves the value associated with the specified Metadata.Key, or returns default if the key is not present.

Public companion functions

create

fun create(
    cameraId: String,
    frameNumber: Long,
    captureRequest: CaptureRequestWrapper = FakeCaptureRequest(),
    resultParameters: Map<CaptureResult.Key<*>, Any?> = emptyMap(),
    resultMetadata: Map<Metadata.Key<*>, Any?> = emptyMap()
): FakeCaptureResult

Creates a FakeCaptureResult instance for Java compatibility.

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

Parameters
cameraId: String

The camera ID string.

frameNumber: Long

The frame number.

captureRequest: CaptureRequestWrapper = FakeCaptureRequest()

The capture request wrapper that generated this result. Defaults to a default FakeCaptureRequest.

resultParameters: Map<CaptureResult.Key<*>, Any?> = emptyMap()

The map of capture result keys to their mock values. Defaults to an empty map.

resultMetadata: Map<Metadata.Key<*>, Any?> = emptyMap()

The map of custom metadata keys to their mock values. Defaults to an empty map.

Returns
FakeCaptureResult

A configured FakeCaptureResult instance.

invoke

Added in 1.7.0-alpha03
operator fun invoke(
    cameraId: CameraId,
    frameNumber: CameraFrameNumber,
    captureRequest: CaptureRequestWrapper = FakeCaptureRequest(),
    resultParameters: Map<CaptureResult.Key<*>, Any?> = emptyMap(),
    resultMetadata: Map<Metadata.Key<*>, Any?> = emptyMap()
): FakeCaptureResult

Creates a FakeCaptureResult instance for Kotlin clients.

Allows constructor-like syntax in Kotlin: FakeCaptureResult(...).

Parameters
cameraId: CameraId

The strongly typed CameraId associated with the result.

frameNumber: CameraFrameNumber

The strongly typed CameraFrameNumber associated with the result.

captureRequest: CaptureRequestWrapper = FakeCaptureRequest()

Optional wrapped CaptureRequestWrapper that produced this result. Defaults to a default FakeCaptureRequest.

resultParameters: Map<CaptureResult.Key<*>, Any?> = emptyMap()

Optional map of capture result keys to their mock values. Defaults to an empty map.

resultMetadata: Map<Metadata.Key<*>, Any?> = emptyMap()

Optional map of custom metadata keys to their mock values. Defaults to an empty map.

Returns
FakeCaptureResult

A configured FakeCaptureResult instance.

Public functions

get

Added in 1.7.0-alpha03
open operator fun <T : Any> get(key: CaptureResult.Key<T>): T?

Retrieves the mock value for the specified CaptureResult.Key.

Returns
T?

The configured mock value, or null if not set.

get

Added in 1.7.0-alpha03
open operator fun <T : Any> get(key: Metadata.Key<T>): T?

Retrieves the mock value for the specified custom metadata key.

Returns
T?

The configured mock value, or null if not set.

unwrapAs

Added in 1.7.0-alpha03
open fun <T : Any> unwrapAs(type: Class<T>): T?

Attempts to unwrap this fake object.

Since this is a fake implementation, it does not wrap a native platform CaptureResult. This method will return null for CaptureResult. It only returns this cast to T if type is compatible with FakeCaptureResult.

Public properties

cameraId

Added in 1.7.0-alpha03
open val cameraIdCameraId

The CameraId of the camera that produced this result.

captureRequest

Added in 1.7.0-alpha03
open val captureRequestCaptureRequestWrapper

The CaptureRequestWrapper that generated this capture result.

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

frameNumber

Added in 1.7.0-alpha03
open val frameNumberCameraFrameNumber

The CameraFrameNumber associated with this result.

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

keys

Added in 1.7.0-alpha03
open val keysList<CaptureResult.Key<*>>

List of all CaptureResult.Keys supported by this capture result.

The list of all CaptureResult.Keys that are supported and can be queried from this result.

See also
getKeys

metadataKeys

Added in 1.7.0-alpha03
open val metadataKeysSet<Metadata.Key<*>>

The set of all custom Metadata.Keys currently available in this container.

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