A pluggable sealed API result type for modeling Retrofit responses.
1.6.0
1.5.31
EitherNetController
API for testing EitherNet APIs via Test Fixtures. This is similar to OkHttp’s MockWebServer
, where results can be enqueued for specific endpoints.Simply create a new controller instance in your test using one of the newEitherNetController()
functions.
val controller = newEitherNetController<PandaApi>() // reified type
Then you can access the underlying faked api
property from it and pass that on to whatever’s being tested.
// Take the api instance from the controller and pass it to whatever's being tested
val provider = PandaDataProvider(controller.api)
Finally, enqueue results for endpoints as needed.
// Later in a test you can enqueue results for specific endpoints
controller.enqueue(PandaApi::getPandas, ApiResult.success("Po"))
You can also optionally pass in full suspend functions if you need dynamic behavior
controller.enqueue(PandaApi::getPandas) {
// This is a suspend function!
delay(1000)
ApiResult.success("Po")
}
See its section in our README for full more details.
Stable release!
ApiResult
. This is important for new versions of R8, which otherwise strips this information.ApiResult
type arguments to be non-null (i.e. T : Any
).ApiResult
. We expose a few APIs through here, namely the original OkHttp Request
or Response
instances when relevant.ApiResult
subtypes are no longer data
classes since many of their underlying properties don't reliably implement equals/hashCode/immutability.ApiResult.response
property is now removed.Thanks to @okamayana for contributing to this release!
This is our first (and hopefully final!) 1.0 release candidate. Please report any issues or API surface area issues now or forever hold your peace.
Note that we consider this stable for production use, this is mostly about API stability.
ApiResult
and ApiResult.Failure
are both now sealed interface
types rather than sealed classes. For most consumers this shouldn't be a source breaking change!ApiResult.Success
constructor is now internal
, please use the ApiResult.success(<value>)
factory.Updated dependencies
Kotlin 1.5.21
Coroutines 1.5.1
Dokka 1.5.0
Special thanks to @danieldisu and @JvmName for contributing to this release!