FakeHealthConnectClientOverrides


class FakeHealthConnectClientOverrides


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

Every call in FakeHealthConnectClient can be overridden.

For example:

import androidx.health.connect.client.testing.stubs.stub // Sets a default return value for client.aggregate() and a queue with one item. client.overrides.aggregate = stub(queue = listOf(resultOnce)) { result }
import androidx.health.connect.client.aggregate.AggregationResult import androidx.health.connect.client.testing.AggregationResult import androidx.health.connect.client.testing.stubs.MutableStub import androidx.health.connect.client.testing.stubs.enqueue // Sets a default exception that will be thrown for client.aggregate(). val aggregationStub = MutableStub<AggregationResult>(exception) client.overrides.aggregate = aggregationStub // Only the first call to client.aggregate() will return this result. Subsequent calls will // throw the default. aggregationStub.enqueue(result) // Setting a default response removes the default exception. aggregationStub.defaultHandler = { AggregationResult() }
import androidx.health.connect.client.aggregate.AggregationResult import androidx.health.connect.client.records.ExerciseSessionRecord import androidx.health.connect.client.records.HeartRateRecord import androidx.health.connect.client.testing.AggregationResult import androidx.health.connect.client.testing.stubs.stub val result =  AggregationResult(  metrics =  buildMap {  put(HeartRateRecord.BPM_AVG, 74.0)  put(ExerciseSessionRecord.EXERCISE_DURATION_TOTAL, Duration.ofMinutes(30))  }  ) client.overrides.aggregate = stub(result)
import androidx.health.connect.client.aggregate.AggregationResult import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.testing.AggregationResult import androidx.health.connect.client.testing.stubs.stub val result = buildList {  add(  AggregationResultGroupedByDuration(  aggregationResult1,  startTime1,  endTime1,  ZoneOffset.UTC  )  )  add(  AggregationResultGroupedByDuration(  aggregationResult2,  startTime2,  endTime2,  ZoneOffset.UTC  )  ) } client.overrides.aggregateGroupByDuration = stub(default = result)
import androidx.health.connect.client.aggregate.AggregationResult import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.testing.AggregationResult import androidx.health.connect.client.testing.stubs.stub val result = buildList {  add(AggregationResultGroupedByPeriod(aggregationResult1, startTime1, endTime1))  add(AggregationResultGroupedByPeriod(aggregationResult2, startTime2, endTime2)) } client.overrides.aggregateGroupByPeriod = stub(default = result)
import androidx.health.connect.client.aggregate.AggregationResult import androidx.health.connect.client.records.ExerciseSessionRecord import androidx.health.connect.client.records.HeartRateRecord import androidx.health.connect.client.testing.AggregationResult import androidx.health.connect.client.testing.stubs.stub val result =  AggregationResult(  metrics =  buildMap {  put(HeartRateRecord.BPM_AVG, 74.0)  put(ExerciseSessionRecord.EXERCISE_DURATION_TOTAL, Duration.ofMinutes(30))  }  ) client.overrides.aggregate = stub(result)

Summary

Public constructors

FakeHealthConnectClientOverrides(
    getChanges: Stub<StringChangesResponse>?,
    getChangesToken: Stub<ChangesTokenRequestString>?,
    readRecords: Stub<ReadRecordsRequest<*>, ReadRecordsResponse<*>>?,
    readRecord: Stub<StringReadRecordResponse<*>>?,
    insertRecords: Stub<List<*>, InsertRecordsResponse>?,
    updateRecords: Stub<AnyNothing>?,
    deleteRecords: Stub<AnyNothing>?,
    aggregate: Stub<AggregateRequestAggregationResult>?,
    aggregateGroupByDuration: Stub<AggregateGroupByDurationRequestList<AggregationResultGroupedByDuration>>?,
    aggregateGroupByPeriod: Stub<AggregateGroupByPeriodRequestList<AggregationResultGroupedByPeriod>>?
)

Public properties

Stub<AggregateRequestAggregationResult>?

A Stub used to set the next responses used in FakeHealthConnectClient.aggregate.

Stub<AggregateGroupByDurationRequestList<AggregationResultGroupedByDuration>>?

A Stub used to set the next responses used in FakeHealthConnectClient.aggregateGroupByDuration.

Stub<AggregateGroupByPeriodRequestList<AggregationResultGroupedByPeriod>>?

A Stub used to set the next responses used in FakeHealthConnectClient.aggregateGroupByPeriod.

Stub<AnyNothing>?

A Stub used only to throw exceptions in deleteRecords.

Stub<StringChangesResponse>?

A Stub used to set the next responses used in getChanges.

Stub<ChangesTokenRequestString>?

A Stub used to set the next responses used in getChangesToken.

Stub<List<*>, InsertRecordsResponse>?

A Stub used to set the next responses used in insertRecords.

Stub<StringReadRecordResponse<*>>?

A Stub used to set the next responses used in readRecord.

Stub<ReadRecordsRequest<*>, ReadRecordsResponse<*>>?

A Stub used to set the next responses used in readRecords.

Stub<AnyNothing>?

A Stub used only to throw exceptions in updateRecords.

Public constructors

FakeHealthConnectClientOverrides

FakeHealthConnectClientOverrides(
    getChanges: Stub<StringChangesResponse>? = null,
    getChangesToken: Stub<ChangesTokenRequestString>? = null,
    readRecords: Stub<ReadRecordsRequest<*>, ReadRecordsResponse<*>>? = null,
    readRecord: Stub<StringReadRecordResponse<*>>? = null,
    insertRecords: Stub<List<*>, InsertRecordsResponse>? = null,
    updateRecords: Stub<AnyNothing>? = null,
    deleteRecords: Stub<AnyNothing>? = null,
    aggregate: Stub<AggregateRequestAggregationResult>? = null,
    aggregateGroupByDuration: Stub<AggregateGroupByDurationRequestList<AggregationResultGroupedByDuration>>? = null,
    aggregateGroupByPeriod: Stub<AggregateGroupByPeriodRequestList<AggregationResultGroupedByPeriod>>? = null
)
Parameters
getChanges: Stub<StringChangesResponse>? = null

A Stub used only to throw exceptions in getChanges.

getChangesToken: Stub<ChangesTokenRequestString>? = null

A Stub used only to throw exceptions in getChangesToken.

readRecords: Stub<ReadRecordsRequest<*>, ReadRecordsResponse<*>>? = null

A Stub used only to throw exceptions in readRecords.

readRecord: Stub<StringReadRecordResponse<*>>? = null

A Stub used only to throw exceptions in readRecord.

insertRecords: Stub<List<*>, InsertRecordsResponse>? = null

A Stub used only to throw exceptions in insertRecords.

updateRecords: Stub<AnyNothing>? = null

A Stub used only to throw exceptions in updateRecords.

deleteRecords: Stub<AnyNothing>? = null

A Stub used only to throw exceptions in deleteRecords.

aggregate: Stub<AggregateRequestAggregationResult>? = null

A Stub used to set the next responses used in FakeHealthConnectClient.aggregate.

aggregateGroupByDuration: Stub<AggregateGroupByDurationRequestList<AggregationResultGroupedByDuration>>? = null

A Stub used to set the next responses used in FakeHealthConnectClient.aggregateGroupByDuration.

aggregateGroupByPeriod: Stub<AggregateGroupByPeriodRequestList<AggregationResultGroupedByPeriod>>? = null

A Stub used to set the next responses used in FakeHealthConnectClient.aggregateGroupByPeriod.

Public properties

aggregate

Added in 1.0.0-alpha03
var aggregateStub<AggregateRequestAggregationResult>?

A Stub used to set the next responses used in FakeHealthConnectClient.aggregate.

import androidx.health.connect.client.aggregate.AggregationResult import androidx.health.connect.client.records.ExerciseSessionRecord import androidx.health.connect.client.records.HeartRateRecord import androidx.health.connect.client.testing.AggregationResult import androidx.health.connect.client.testing.stubs.stub val result =  AggregationResult(  metrics =  buildMap {  put(HeartRateRecord.BPM_AVG, 74.0)  put(ExerciseSessionRecord.EXERCISE_DURATION_TOTAL, Duration.ofMinutes(30))  }  ) client.overrides.aggregate = stub(result)

aggregateGroupByDuration

Added in 1.0.0-alpha03
var aggregateGroupByDurationStub<AggregateGroupByDurationRequestList<AggregationResultGroupedByDuration>>?

A Stub used to set the next responses used in FakeHealthConnectClient.aggregateGroupByDuration.

import androidx.health.connect.client.aggregate.AggregationResult import androidx.health.connect.client.aggregate.AggregationResultGroupedByDuration import androidx.health.connect.client.testing.AggregationResult import androidx.health.connect.client.testing.stubs.stub val result = buildList {  add(  AggregationResultGroupedByDuration(  aggregationResult1,  startTime1,  endTime1,  ZoneOffset.UTC  )  )  add(  AggregationResultGroupedByDuration(  aggregationResult2,  startTime2,  endTime2,  ZoneOffset.UTC  )  ) } client.overrides.aggregateGroupByDuration = stub(default = result)

aggregateGroupByPeriod

Added in 1.0.0-alpha03
var aggregateGroupByPeriodStub<AggregateGroupByPeriodRequestList<AggregationResultGroupedByPeriod>>?

A Stub used to set the next responses used in FakeHealthConnectClient.aggregateGroupByPeriod.

import androidx.health.connect.client.aggregate.AggregationResult import androidx.health.connect.client.aggregate.AggregationResultGroupedByPeriod import androidx.health.connect.client.testing.AggregationResult import androidx.health.connect.client.testing.stubs.stub val result = buildList {  add(AggregationResultGroupedByPeriod(aggregationResult1, startTime1, endTime1))  add(AggregationResultGroupedByPeriod(aggregationResult2, startTime2, endTime2)) } client.overrides.aggregateGroupByPeriod = stub(default = result)

deleteRecords

Added in 1.0.0-alpha03
var deleteRecordsStub<AnyNothing>?

A Stub used only to throw exceptions in deleteRecords.

getChanges

Added in 1.0.0-alpha03
var getChangesStub<StringChangesResponse>?

A Stub used to set the next responses used in getChanges.

getChangesToken

Added in 1.0.0-alpha03
var getChangesTokenStub<ChangesTokenRequestString>?

A Stub used to set the next responses used in getChangesToken.

insertRecords

Added in 1.0.0-alpha03
var insertRecordsStub<List<*>, InsertRecordsResponse>?

A Stub used to set the next responses used in insertRecords.

readRecord

Added in 1.0.0-alpha03
var readRecordStub<StringReadRecordResponse<*>>?

A Stub used to set the next responses used in readRecord.

readRecords

Added in 1.0.0-alpha03
var readRecordsStub<ReadRecordsRequest<*>, ReadRecordsResponse<*>>?

A Stub used to set the next responses used in readRecords.

updateRecords

Added in 1.0.0-alpha03
var updateRecordsStub<AnyNothing>?

A Stub used only to throw exceptions in updateRecords.