Last active
April 21, 2023 10:03
-
-
Save wahibhaq/20124ed53ae0e3929ca90bb44c96ad78 to your computer and use it in GitHub Desktop.
Revisions
-
wahibhaq renamed this gist
Mar 19, 2019 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ * This will help us to test our networking code while a particular API is not implemented * yet on Backend side. */ class MockInterceptor : Interceptor { override fun intercept(chain: Interceptor.Chain): Response { if (BuildConfig.DEBUG) { @@ -24,7 +24,7 @@ class MockedInterceptor : Interceptor { .build() } else { //just to be on safe side. throw IllegalAccessError("MockInterceptor is only meant for Testing Purposes and " + "bound to be used only with DEBUG mode") } } -
wahibhaq revised this gist
Mar 19, 2019 . 1 changed file with 25 additions and 20 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,23 +1,8 @@ /** * This will help us to test our networking code while a particular API is not implemented * yet on Backend side. */ class MockedInterceptor : Interceptor { override fun intercept(chain: Interceptor.Chain): Response { @@ -44,4 +29,24 @@ class MockedInterceptor : Interceptor { } } } const val getListOfReposBeingStarredJson = """ [{ "id": 1296269, "node_id": "MDEwOlJlcG9zaXRvcnkxMjk2MjY5", "name": "Hello-World", "full_name": "octocat/Hello-World", "private": false, "html_url": "https://github.com/octocat/Hello-World", "description": "This your first repo!", "fork": false, "languages_url": "http://api.github.com/repos/octocat/Hello-World/languages", "stargazers_count": 80, "watchers_count": 80, "pushed_at": "2011-01-26T19:06:43Z", "created_at": "2011-01-26T19:01:12Z", "updated_at": "2011-01-26T19:14:43Z", "subscribers_count": 42 }] """ -
wahibhaq revised this gist
Mar 19, 2019 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ const val getListOfReposBeingStarredJson = """ [{ "id": 1296269, "node_id": "MDEwOlJlcG9zaXRvcnkxMjk2MjY5", @@ -24,7 +24,7 @@ class MockedInterceptor : Interceptor { if (BuildConfig.DEBUG) { val uri = chain.request().url().uri().toString() val responseString = when { uri.endsWith("starred") -> getListOfReposBeingStarredJson else -> "" } -
wahibhaq revised this gist
Mar 19, 2019 . 1 changed file with 20 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,19 +1,30 @@ const val getListRepositoriesBeingStarredJson = """ [{ "id": 1296269, "node_id": "MDEwOlJlcG9zaXRvcnkxMjk2MjY5", "name": "Hello-World", "full_name": "octocat/Hello-World", "private": false, "html_url": "https://github.com/octocat/Hello-World", "description": "This your first repo!", "fork": false, "languages_url": "http://api.github.com/repos/octocat/Hello-World/languages", "stargazers_count": 80, "watchers_count": 80, "pushed_at": "2011-01-26T19:06:43Z", "created_at": "2011-01-26T19:01:12Z", "updated_at": "2011-01-26T19:14:43Z", "subscribers_count": 42 }] """ class MockedInterceptor : Interceptor { override fun intercept(chain: Interceptor.Chain): Response { if (BuildConfig.DEBUG) { val uri = chain.request().url().uri().toString() val responseString = when { uri.endsWith("starred") -> getListRepositoriesBeingStarredJson else -> "" } -
wahibhaq revised this gist
Mar 19, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ class MockedInterceptor : Interceptor { private fun buildJsonResponse(body: String) = "{\n" + "\t\t\t\t$body\n" + -
wahibhaq revised this gist
Feb 21, 2019 . 1 changed file with 31 additions and 23 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,28 +1,36 @@ class FakeInterceptor : Interceptor { private fun buildJsonResponse(body: String) = "{\n" + "\t\t\t\t$body\n" + "\t\t\t,\n" + "\t\t\t\"response\": {\n" + "\t\t\t\t\"code\": 200\n" + "\t\t\t}\n" + "\t\t}" override fun intercept(chain: Interceptor.Chain): Response { if (BuildConfig.DEBUG) { val uri = chain.request().url().uri().toString() val responseString = when { uri.endsWith("getAllItems") -> buildJsonResponse(getAllItems) else -> "" } return chain.proceed(chain.request()) .newBuilder() .code(SUCCESS_CODE) .protocol(Protocol.HTTP_2) .message(responseString) .body(ResponseBody.create(MediaType.parse("application/json"), responseString.toByteArray())) .addHeader("content-type", "application/json") .build() } else { //just to be on safe side. throw IllegalAccessError("MockedInterceptor is only meant for Testing Purposes and " + "bound to be used only with DEBUG mode") } } } -
wahibhaq created this gist
Feb 21, 2019 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ class FakeInterceptor : Interceptor { override fun intercept(chain: Interceptor.Chain): Response { if (BuildConfig.DEBUG) { val uri = chain.request().url().uri().toString() val responseString = when { uri.endsWith("getAllItems") -> buildJsonResponse(getAllItems) else -> "" } return chain.proceed(chain.request()) .newBuilder() .code(SUCCESS_CODE) .protocol(Protocol.HTTP_2) .message(responseString) .body(ResponseBody.create(MediaType.parse("application/json"), responseString.toByteArray())) .addHeader("content-type", "application/json") .build() } else { //just to be on safe side. throw IllegalAccessError("MockedInterceptor is only meant for Testing Purposes and " + "bound to be used only with DEBUG mode") } } }