androidx.health.connect.client.testing


Classes

FakeHealthConnectClient

Fake HealthConnectClient to be used in tests for components that use it as a dependency.

FakeHealthConnectClientOverrides

Used to override or intercept responses to emulate scenarios that FakeHealthConnectClient doesn't support.

FakePermissionController

A fake PermissionController that enables full control of permissions in tests for a HealthConnectClient.

Top-level functions summary

AggregationResult
AggregationResult(
    dataOrigins: Set<DataOrigin>,
    metrics: Map<AggregateMetric<Any>, Any>
)

Creates an AggregationResult from a map of metrics.

Extension functions summary

Metadata
Metadata.populatedWithTestValues(
    id: String,
    dataOrigin: DataOrigin,
    lastModifiedTime: Instant
)

Creates a new Metadata object by copying existing fields and overriding specified properties for testing.

Top-level functions

fun AggregationResult(
    dataOrigins: Set<DataOrigin> = emptySet(),
    metrics: Map<AggregateMetric<Any>, Any> = emptyMap()
): AggregationResult

Creates an AggregationResult from a map of metrics.

Extension functions

populatedWithTestValues

fun Metadata.populatedWithTestValues(
    id: String = this.id,
    dataOrigin: DataOrigin = this.dataOrigin,
    lastModifiedTime: Instant = this.lastModifiedTime
): Metadata

Creates a new Metadata object by copying existing fields and overriding specified properties for testing.

This method facilitates the creation of Metadata instances with controlled values, particularly useful for unit testing scenarios where specific metadata properties need to be set. It constructs a new Metadata object based on the current instance, allowing the modification of the id, dataOrigin, and lastModifiedTime fields.

Parameters
id: String = this.id

The ID to assign to the new Metadata. If not provided, the ID from the current Metadata instance will be used.

dataOrigin: DataOrigin = this.dataOrigin

The DataOrigin to assign to the new Metadata. If not provided, the data origin from the current Metadata instance will be used.

lastModifiedTime: Instant = this.lastModifiedTime

The Instant representing the last modified time. If not provided, the last modified time from the current Metadata instance will be used.