public fun interface Stub<T extends Object, R extends Object>

Known direct subclasses
MutableStub

A Stub whose defaultHandler and queue can be mutated at any point.


Represents a stub mapping from a request T to a response R.

Stubs are usually created with the stub function or the MutableStub class.

There are three possible outcomes of a stub:

  • A value of type R is returned meaning that the request has succeeded and the value should be returned to the caller.

  • An exception is thrown meaning that the request has failed and the error should be returned to the caller.

  • Null (null) is returned meaning that the request has not been processed by this stub, in which case the client may call another stub or somehow fallback to a default behaviour.

Example Stub where output depends on input:

import androidx.health.connect.client.testing.stubs.Stub
import androidx.health.connect.client.testing.stubs.stub

val stub: Stub<Int, String> = Stub { if (it == 0) "zero" else it.toString() }
stub.next(request = 0) // Returns "zero"
stub.next(request = 1) // Returns "1"
stub.next(request = 2) // Returns "2"
See also
stub
MutableStub

Summary

Public methods

abstract R
next(@NonNull T request)

Returns the next item.

Public methods

next

Added in 1.0.0-alpha01
abstract R next(@NonNull T request)

Returns the next item.