FakeCaptureResult


public final class FakeCaptureResult implements 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

Nested types

public static class FakeCaptureResult.Companion

Public methods

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 FakeCaptureResult instance for Java compatibility.

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

Retrieves the mock value for the specified CaptureResult.Key.

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

Retrieves the mock value for the specified custom metadata key.

@NonNull CameraId

The CameraId of the camera that produced this result.

@NonNull CaptureRequestWrapper

The CaptureRequestWrapper that generated this capture result.

@NonNull CameraFrameNumber

The CameraFrameNumber associated with this result.

@NonNull List<@NonNull CaptureResult.Key<@NonNull ?>>

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

@NonNull Set<@NonNull Metadata.Key<@NonNull ?>>

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

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

Attempts to unwrap this fake object.

Inherited methods

From androidx.camera.common.CaptureResultMetadata
@NonNull T
<T extends Object> getOrDefault(
    @NonNull CaptureResult.Key<@NonNull T> key,
    @NonNull T default
)

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
@NonNull T
<T extends Object> getOrDefault(
    @NonNull Metadata.Key<@NonNull T> key,
    @NonNull T default
)

Retrieves the value associated with the specified Metadata.Key, or returns default 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 FakeCaptureResult instance for Java compatibility.

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

Parameters
@NonNull String cameraId

The camera ID string.

long frameNumber

The frame number.

@NonNull CaptureRequestWrapper captureRequest

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

@NonNull Map<@NonNull CaptureResult.Key<@NonNull ?>, Object> resultParameters

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

@NonNull Map<@NonNull Metadata.Key<@NonNull ?>, Object> resultMetadata

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

Returns
@NonNull FakeCaptureResult

A configured FakeCaptureResult instance.

get

Added in 1.7.0-alpha03
public T <T extends Object> get(@NonNull CaptureResult.Key<@NonNull T> key)

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
public T <T extends Object> get(@NonNull Metadata.Key<@NonNull T> key)

Retrieves the mock value for the specified custom metadata key.

Returns
T

The configured mock value, or null if not set.

getCameraId

Added in 1.7.0-alpha03
public @NonNull CameraId getCameraId()

The CameraId of the camera that produced this result.

getCaptureRequest

Added in 1.7.0-alpha03
public @NonNull CaptureRequestWrapper getCaptureRequest()

The 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-alpha03
public @NonNull CameraFrameNumber getFrameNumber()

The CameraFrameNumber associated with this result.

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

getKeys

Added in 1.7.0-alpha03
public @NonNull List<@NonNull CaptureResult.Key<@NonNull ?>> getKeys()

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

getMetadataKeys

Added in 1.7.0-alpha03
public @NonNull Set<@NonNull Metadata.Key<@NonNull ?>> getMetadataKeys()

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.

unwrapAs

Added in 1.7.0-alpha03
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 CaptureResult. This method will return null for CaptureResult. It only returns this cast to T if type is compatible with FakeCaptureResult.