FakeCaptureRequest
class FakeCaptureRequest : CaptureRequestWrapper
A fake implementation of CaptureRequestWrapper designed for unit testing.
This class allows tests to mock camera settings by configuring mock values for both native CaptureRequest.Keys and custom Metadata.Keys.
Kotlin Example
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
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 unwrapAs
Because FakeCaptureRequest does not wrap a real, native CaptureRequest object, calling unwrapAs(CaptureRequest::class.java) will return null. It only supports unwrapping to FakeCaptureRequest itself or its supertypes.
Summary
Public companion functions |
|
|---|---|
FakeCaptureRequest |
create(Factory method to create a |
operator FakeCaptureRequest |
invoke(Creates a |
Public functions |
|
|---|---|
open operator T? |
<T : Any> get(key: CaptureRequest.Key<T>)Retrieves the mock value configured for the specified |
open operator T? |
<T : Any> get(key: Metadata.Key<T>)Retrieves the mock value configured for the specified |
open T? |
Unwraps this object to the specified type. |
Public properties |
|
|---|---|
open List<CaptureRequest.Key<*>> |
The list of |
open Set<Metadata.Key<*>> |
The set of custom |
Inherited functions |
||
|---|---|---|
|
||
|
Public companion functions
create
fun create(
requestParameters: Map<CaptureRequest.Key<*>, Any?> = emptyMap(),
requestMetadata: Map<Metadata.Key<*>, Any?> = emptyMap()
): FakeCaptureRequest
Factory method to create a FakeCaptureRequest instance for Java interoperability.
| Parameters | |
|---|---|
requestParameters: Map<CaptureRequest.Key<*>, Any?> = emptyMap() |
The map of capture request keys to their mock values. Defaults to an empty map. |
requestMetadata: Map<Metadata.Key<*>, Any?> = emptyMap() |
The map of custom metadata keys to their mock values. Defaults to an empty map. |
| Returns | |
|---|---|
FakeCaptureRequest |
A configured |
invoke
operator fun invoke(
requestParameters: Map<CaptureRequest.Key<*>, Any?> = emptyMap(),
requestMetadata: Map<Metadata.Key<*>, Any?> = emptyMap()
): FakeCaptureRequest
Creates a FakeCaptureRequest instance.
This allows constructor-like syntax in Kotlin: FakeCaptureRequest(...).
| Parameters | |
|---|---|
requestParameters: Map<CaptureRequest.Key<*>, Any?> = emptyMap() |
The map of capture request keys to their mock values. Defaults to an empty map. |
requestMetadata: Map<Metadata.Key<*>, Any?> = emptyMap() |
The map of custom metadata keys to their mock values. Defaults to an empty map. |
| Returns | |
|---|---|
FakeCaptureRequest |
A configured |
Public functions
get
open operator fun <T : Any> get(key: CaptureRequest.Key<T>): T?
Retrieves the mock value configured for the specified CaptureRequest.Key.
| Parameters | |
|---|---|
key: CaptureRequest.Key<T> |
The native capture request key to query. |
| Returns | |
|---|---|
T? |
The configured mock value, or |
get
open operator fun <T : Any> get(key: Metadata.Key<T>): T?
Retrieves the mock value configured for the specified Metadata.Key.
| Parameters | |
|---|---|
key: Metadata.Key<T> |
The custom metadata key to query. |
| Returns | |
|---|---|
T? |
The configured mock value, or |
unwrapAs
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 CaptureRequest object, this method will return null if type is CaptureRequest. It only returns this (cast to T) if type is compatible with FakeCaptureRequest.
| Parameters | |
|---|---|
type: Class<T> |
The class representing the target type. |
| Returns | |
|---|---|
T? |
This instance if compatible with |
Public properties
keys
open val keys: List<CaptureRequest.Key<*>>
The list of CaptureRequest.Keys that have configured mock values in this fake request.
metadataKeys
open val metadataKeys: Set<Metadata.Key<*>>
The set of custom Metadata.Keys that have configured mock values in this fake request.