Last active
December 27, 2021 23:39
-
-
Save Zulqurnain/ed1d605333ec8e771e6904914b2129cd to your computer and use it in GitHub Desktop.
MockCallInterceptor working in kotlin using Gson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MockCallInterceptor<T> constructor(val value: T) : Interceptor { | |
override fun intercept(chain: Interceptor.Chain): Response { | |
val uri = chain.request().url().uri().toString() | |
val responseString: String = Gson().toJson(T::class.java) | |
val response = Response.Builder() | |
.code(200) | |
.message(responseString) | |
.request(chain.request()) | |
.protocol(Protocol.HTTP_1_0) | |
.body( | |
ResponseBody.create( | |
MediaType.parse("application/json"), | |
responseString | |
) | |
) | |
.addHeader("content-type", "application/json") | |
.build() | |
return response | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment