All Projects → aniketbhoite → Assume

aniketbhoite / Assume

Licence: Apache-2.0 license
Easy Response Mocking for Retrofit using annotations

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Assume

Awesome Wanandroid
⚡致力于打造一款极致体验的 http://www.wanandroid.com/ 客户端,知识和美是可以并存的哦QAQn(*≧▽≦*)n
Stars: ✭ 2,525 (+10000%)
Mutual labels:  retrofit2, okhttp3
AndroidStarterAlt
A sample View-based Android app using the MVP architecture. It uses Mosby, Dagger2, RxJava, retrofit, LoganSquare, requery, EventBus, Conductor.
Stars: ✭ 27 (+8%)
Mutual labels:  retrofit2, okhttp3
Wanandroid
WanAndroid客户端,项目基于 Material Design + MVP +dagger2 + RxJava + Retrofit + Glide + greendao 等架构进行设计实现,极力打造一款 优秀的玩Android https://www.wanandroid.com 客户端,是一个不错的Android应用开发学习参考项目
Stars: ✭ 223 (+792%)
Mutual labels:  retrofit2, okhttp3
Androidbaseframemvvm
Android 组件化 MVVM 框架 基于 Jetpack + Kotlin
Stars: ✭ 169 (+576%)
Mutual labels:  retrofit2, okhttp3
Palette
Android application to get the #hexcode and rgb() values for any image
Stars: ✭ 31 (+24%)
Mutual labels:  retrofit2, okhttp3
Mockinizer
An okhttp / retrofit api call mocking library
Stars: ✭ 176 (+604%)
Mutual labels:  retrofit2, okhttp3
RxJavaKotlinSample
RxJava2 and Kotlin sample project
Stars: ✭ 13 (-48%)
Mutual labels:  retrofit2, okhttp3
Retrofiturlmanager
🔮 Let Retrofit support multiple baseUrl and can be change the baseUrl at runtime (以最简洁的 Api 让 Retrofit 同时支持多个 BaseUrl 以及动态改变 BaseUrl).
Stars: ✭ 1,961 (+7744%)
Mutual labels:  retrofit2, okhttp3
WanAndroid
wanandroid的Kotlin版,采用Android X
Stars: ✭ 20 (-20%)
Mutual labels:  retrofit2, okhttp3
HotSalesPOS
No description or website provided.
Stars: ✭ 14 (-44%)
Mutual labels:  retrofit2, okhttp3
Jbusdriver
这是去幼儿园的班车(滑稽
Stars: ✭ 2,056 (+8124%)
Mutual labels:  retrofit2, okhttp3
Atoms-mvp
A component architecture for android applications based on MVP
Stars: ✭ 63 (+152%)
Mutual labels:  retrofit2, okhttp3
Retrofitkotlindeferred
Android Networking using Retrofit2, Kotlin and its Deferred Type
Stars: ✭ 160 (+540%)
Mutual labels:  retrofit2, okhttp3
Httprequest
基于Retrofit2+RxJava2+OkHttp3的网络请求框架,可以完美的应用到组件化、MVP模式等项目中
Stars: ✭ 181 (+624%)
Mutual labels:  retrofit2, okhttp3
Mifos Mobile
Repository for the Mifos Mobile Banking App for clients
Stars: ✭ 154 (+516%)
Mutual labels:  retrofit2, okhttp3
Mockstar
Demo project on How to be a Mockstar using Mockito and MockWebServer.
Stars: ✭ 53 (+112%)
Mutual labels:  mocking, retrofit2
Bilisoleil Kotlin
An unofficial bilibili client for android --kotlin+rxjava2+mvp+okhttp3+retrofit2+dagger2
Stars: ✭ 139 (+456%)
Mutual labels:  retrofit2, okhttp3
Androidstarter
A sample Android app using the MVP architecture.
Stars: ✭ 140 (+460%)
Mutual labels:  retrofit2, okhttp3
OkhttpCacheInterceptor
The OkHttpCacheInterceptor 一个OkHttp的网络缓存拦截器,可自定义场景对请求的数据进行缓存
Stars: ✭ 32 (+28%)
Mutual labels:  retrofit2, okhttp3
RxJava2Demo
RxJava 2.X Retrofit OkHttp demo
Stars: ✭ 29 (+16%)
Mutual labels:  retrofit2, okhttp3

Assume

Response Mocking for Retrofit using annotations. Assume Provides safe and easy way to mock API responses for retrofit-okhttp3.

Download

Add Jitpack repository in project build.gradle file


allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

Add dependencies to your module's build.gradle file:


def assume_version = "1.1"

// kaptDebug to reduce unnecessary Annotation processing for release build generations
kaptDebug "com.github.aniketbhoite.Assume:processor:$assume_version"

// debugImplementation ensures APIs are mocked only in debug making it production safe
debugImplementation "com.github.aniketbhoite.Assume:annotations:$assume_version"

releaseImplementation "com.github.aniketbhoite.Assume:annotations-empty:$assume_version"

annotations-empty package adds empty placeholder classes. If you add annotation-empty then assume won't interfere with the actual response even if you keep the assume code in your codebase by mistake.

Usage

Add @Assume annotation to API method with wanted response, responseCode is optional


@Assume(
	responseCode = 200,
	response ="{\"page\":1,\"results\":[],\"total_pages\":10,\"total_results\":100}"
)
@POST("v2/top-headlines")
suspend fun getHeadline(): NewsResponse


@Assume(
	responseCode = 200,
        response = "{\"userId\": 1, \"id\": 1, \"title\": \"Test title 1\", \"body\": \"Test title 2\"}",
	ignore = true  //To get the actual response from network & skip Assume
)
@GET("posts/{id}")
suspend fun getPostById(@Path("id") id: Int): PostListModelItem

Add AssumeInterceptor inside the Okhttp3 client


val client = OkHttpClient.Builder()
        .addInterceptor(AssumeInterceptor(BASE_URL) //same base url added in retrofit
        .build()

You should be good to go.👍🏽

Benefits of Assume

  1. Saves hassles of modifying interceptors to mock response every time
  2. Can mock multiple APIs
  3. Assume support API with dynamic path variables

Gotchas to keep in mind:

  • Assume ignores Query params
  • Assume doesn’t support API's with @Url (workaround: add API endpoint in retrofit method annotation)
  • Assume is not perfect and we are working on it to make it better and easy to use. It should work with most of the endpoints and it is production safe

For any bugs or doubts raise issue & for any changes or improvements start a pull request

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].