{"id":13610069,"url":"https://github.com/infinum/Retromock","last_synced_at":"2025-04-12T22:32:38.856Z","repository":{"id":36272119,"uuid":"151698084","full_name":"infinum/Retromock","owner":"infinum","description":"Java library for mocking responses in a Retrofit service.","archived":false,"fork":false,"pushed_at":"2024-10-11T08:58:30.000Z","size":335,"stargazers_count":67,"open_issues_count":2,"forks_count":3,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-04-07T08:21:19.048Z","etag":null,"topics":["android","android-development","android-library","java-library","mock","mocking","open-source","retrofit","testing","testing-tools"],"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/infinum.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-05T09:24:37.000Z","updated_at":"2025-02-05T21:00:12.000Z","dependencies_parsed_at":"2024-08-01T19:43:50.159Z","dependency_job_id":"3cb5f2f4-8d0a-46cb-aa50-cb8c902eb040","html_url":"https://github.com/infinum/Retromock","commit_stats":{"total_commits":154,"total_committers":9,"mean_commits":17.11111111111111,"dds":"0.44805194805194803","last_synced_commit":"52b0c79f8b34e7282aff395570cc9c75fc9c3f04"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infinum%2FRetromock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infinum%2FRetromock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infinum%2FRetromock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infinum%2FRetromock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/infinum","download_url":"https://codeload.github.com/infinum/Retromock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248641246,"owners_count":21138172,"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","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","android-development","android-library","java-library","mock","mocking","open-source","retrofit","testing","testing-tools"],"created_at":"2024-08-01T19:01:40.910Z","updated_at":"2025-04-12T22:32:38.347Z","avatar_url":"https://github.com/infinum.png","language":"Kotlin","funding_links":[],"categories":["Kotlin"],"sub_categories":[],"readme":"# Retromock\n[![Build Status](https://app.bitrise.io/app/7b832efc5bb97051/status.svg?token=S3Efgo8YEz6s8tFv2ocKzA\u0026branch=master)](https://app.bitrise.io/app/7b832efc5bb97051)\n[ ![Download](https://img.shields.io/maven-central/v/co.infinum/retromock) ](https://search.maven.org/artifact/co.infinum/retromock)\n\n\u003cimg src='./logo.svg' width='264'/\u003e\n\nAdapts Java interface created by [Retrofit][retrofit] using annotations on declared methods to define response mocks.\n\nQuick guide\n-------\n\n#### Add dependency\n```gradle\nimplementation 'co.infinum:retromock:1.1.1'\n```\n\n#### Initialize\n```java\nRetromock retromock = new Retromock.Builder()\n  .retrofit(retrofit)\n  .build();\n```\n\n#### Create a service class\n```java\nService service = retromock.create(Service.class);\n```\n\n#### Setup mocks\n```java\npublic interface Service {\n\n  @Mock\n  @MockResponse(body = \"{\\\"name\\\":\\\"John\\\", \\\"surname\\\":\\\"Doe\\\"}\")\n  @GET(\"/endpoint\")\n  Call\u003cUser\u003e getUser();\n}\n```\n\n#### Use the service\n```java\nCall\u003cUser\u003e = service.getUser();\n```\n\n##### Load responses from streams\nIf you would like to load response from a stream set a default body factory that loads a response stream by a body parameter(`response.json`) in annotation.\n```java\nRetromock retromock = new Retromock.Builder()\n  .retrofit(retrofit)\n  .defaultBodyFactory(...)\n  .build();\n```\n\n```java\npublic interface Service {\n\n  @Mock\n  @MockResponse(body = \"response.json\")\n  @GET(\"/endpoint\")\n  Call\u003cUser\u003e getUser();\n}\n```\n\n##### Load responses from Android assets\n```java\nRetromock retromock = new Retromock.Builder()\n  .retrofit(retrofit)\n  .defaultBodyFactory(context.getAssets()::open)\n  .build();\n```\n\n```java\npublic interface Service {\n\n  @Mock\n  @MockResponse(body = \"retromock/response.json\")\n  @GET(\"/endpoint\")\n  Call\u003cUser\u003e getUser();\n}\n```\n\nSave a response body content in file named `retromock/response.json`.\n\nIf you use `Retromock` only in some variants you can exclude files with mock responses from final .apk with configuration similar to:\n```groovy\napplicationVariants.all { variant -\u003e\n  if (variant.buildType.name.contains('production')) {\n    variant.mergeAssets.doLast {\n      delete(fileTree(dir: variant.mergeAssets.outputDir, includes: ['**/retromock/*']))\n    }\n  }\n}\n```\n\nNote: if you set custom default body factory and do not declare a `bodyFactory` parameter in `@MockResponse` annotation your body factory will be called with value of `body` parameter.\nThat also applies if you don't specificaly set a `body` - in that case `body` is empty by default.\nIf you wouldn't like to handle the case of empty `body` wrap your default body factory into `NonEmptyBodyFactory` class as follows:\n```java\nRetromock retromock = new Retromock.Builder()\n  .retrofit(retrofit)\n  .defaultBodyFactory(new NonEmptyBodyFactory(...))\n  .build();\n```\n\n#### For more information please see [the full specification][specification].\n-------\n\n\n\nProGuard\n-------\nThe library does not require any ProGuard rules.\n\nHowever, you might need rules for Retrofit and its dependencies.\n\nLicense\n-------\n```\nCopyright 2019 Infinum\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n   http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n\n## Credits\n\nMaintained and sponsored by [Infinum](http://www.infinum.co).\n\n\u003cp align=\"center\"\u003e\n  \u003ca href='https://infinum.com'\u003e\n    \u003cpicture\u003e\n        \u003csource srcset=\"https://assets.infinum.com/brand/logo/static/white.svg\" media=\"(prefers-color-scheme: dark)\"\u003e\n        \u003cimg src=\"https://assets.infinum.com/brand/logo/static/default.svg\"\u003e\n    \u003c/picture\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n [retrofit]: https://square.github.io/retrofit/\n [specification]: SPECIFICATION.md\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfinum%2FRetromock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finfinum%2FRetromock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfinum%2FRetromock/lists"}