{"id":18794313,"url":"https://github.com/soarcn/optimus","last_synced_at":"2026-02-12T08:31:50.233Z","repository":{"id":57718320,"uuid":"284904073","full_name":"soarcn/Optimus","owner":"soarcn","description":"Optimus is a dynamic mock tool for retrofit","archived":false,"fork":false,"pushed_at":"2020-08-05T07:14:41.000Z","size":1355,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-05T16:37:05.576Z","etag":null,"topics":["android","dynamic-mock","mock","network-behavior","okhttp","retrofit2","testing"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/soarcn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-08-04T07:06:50.000Z","updated_at":"2024-07-05T04:57:28.000Z","dependencies_parsed_at":"2022-09-14T22:53:26.710Z","dependency_job_id":null,"html_url":"https://github.com/soarcn/Optimus","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/soarcn/Optimus","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soarcn%2FOptimus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soarcn%2FOptimus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soarcn%2FOptimus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soarcn%2FOptimus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/soarcn","download_url":"https://codeload.github.com/soarcn/Optimus/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soarcn%2FOptimus/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275160370,"owners_count":25415767,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-14T02:00:10.474Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","dynamic-mock","mock","network-behavior","okhttp","retrofit2","testing"],"created_at":"2024-11-07T21:28:58.311Z","updated_at":"2026-02-12T08:31:50.206Z","avatar_url":"https://github.com/soarcn.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"Optimus\n============\n![Maven](https://maven-badges.herokuapp.com/maven-central/com.cocosw/optimus/badge.png?style=plastic)\n\nOptimus is a dynamic mock tool for retrofit\n\n![Sample](https://github.com/soarcn/Optimus/blob/master/optimus.gif?raw=true)\n\n\nUsage\n=======\n\nGiven you have a service interface\n\n```kotlin\ninterface Api {\n    @POST(\"api/login\")\n    fun login(): Call\u003cVoid\u003e\n}\n```\n\nStep 1 Define mock data\n\n```kotlin\nclass MockUser : MockResponse {\n    @Default\n    val HTTP200 = success {}\n    val HTTP401 = error(401,\"UnAuthorized\") { ApiError(401, \"Unauthorized\") }\n}\n```\n\nStep 2 Create an optimus instance\n\n```kotlin\nval supplier = MockResponseSupplier.create(sharedpreference)\nOptimus.Builder(supplier)\n                    .retrofit(retrofit,sharedpreference)\n                    .mockGraph(\n                               alter(Api::class.java, \"Api\") {\n                                   Api::login with MockUser::class named \"Login\"\n                               })\n                    .converter(Converter.create(moshi))\n                    .build()\n```\n\nStep 3 Replace retrofit with optimus\n\n```kotlin\noptimus.create(Api::class.java)\n```\n\nOptimus provides a view to change mock behavior in runtime, You may use it in a Alert like this\n\n```kotlin\nAlertDialog.Builder(this)\n           .setView(OptimusView(this).apply { this.setOptimus(optimus) })\n           .create().show()\n```\n\nTesting\n========\n\nOptimus makes unittest and UI test easier.\n\nStep1 User InMemory MockResponseSupplier and mockretrofit\n\n```kotlin\nval supplier = MockResponseSupplier.memory()\n\nOptimus.Builder(supplier)\n       .retrofit(retrofit)\n       .mockGraph(mockgraph)\n       .build()\n```\n\nStep2 Change mock response with Api\n\n```kotlin\n        val api = optimus.create(Api::class.java)\n        mockResponseSupplier.set(Api::call, MockUser::HTTP401)\n        assert(api.login().response.code,401)\n```\n\nDownload\n=====\n```groovy\n    implementation 'com.cocosw:optimus:1.0.0'\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoarcn%2Foptimus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoarcn%2Foptimus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoarcn%2Foptimus/lists"}