{"id":15578358,"url":"https://github.com/infinum/retromock","last_synced_at":"2025-08-15T15:19:59.186Z","repository":{"id":36272119,"uuid":"151698084","full_name":"infinum/Retromock","owner":"infinum","description":"Library for mocking responses in a Retrofit service.","archived":false,"fork":false,"pushed_at":"2025-07-08T15:39:52.000Z","size":340,"stargazers_count":68,"open_issues_count":1,"forks_count":3,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-08-09T03:54:30.542Z","etag":null,"topics":["android","android-development","android-library","java-library","kotlin","kotlin-android","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":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-10-05T09:24:37.000Z","updated_at":"2025-07-04T13:19:01.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":6,"template":false,"template_full_name":null,"purl":"pkg:github/infinum/Retromock","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","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/infinum%2FRetromock/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270586487,"owners_count":24611317,"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-08-15T02:00:12.559Z","response_time":110,"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","android-development","android-library","java-library","kotlin","kotlin-android","mock","mocking","open-source","retrofit","testing","testing-tools"],"created_at":"2024-10-02T19:09:35.641Z","updated_at":"2025-08-15T15:19:59.178Z","avatar_url":"https://github.com/infinum.png","language":"Kotlin","funding_links":[],"categories":[],"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\n## Description\n\nAdapts Java interface created by [Retrofit][retrofit] using annotations on declared methods to define response mocks.\n\n## Table of contents\n\n* [Requirements](#requirements)\n* [Getting started](#getting-started)\n* [Usage](#usage)\n* [Contributing](#contributing)\n* [License](#license)\n* [Credits](#credits)\n\n## Requirements\n\nYou need to use [Retrofit][retrofit] in your project\n\n## Getting started\n\nTo include _Retromock_ in your project, you have to add buildscript dependencies in your project\nlevel `build.gradle` or `build.gradle.kts`:\n\n**Groovy**\n\n```groovy\nbuildscript {\n    repositories {\n        mavenCentral()\n    }\n}\n```\n\n**KotlinDSL**\n\n```kotlin\nbuildscript {\n    repositories {\n        mavenCentral()\n    }\n}\n```\n\nThen, you can include the library in your module's `build.gradle` or `build.gradle.kts`:\n\n**Groovy**\n\n```groovy\nimplementation 'com.infinum:retromock:1.2.1'\n```\n\n**KotlinDSL**\n\n```kotlin\nimplementation(\"com.infinum:retromock:1.2.1\")\n```\n\n## Usage\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\n#### ProGuard\n\nThe library does not require any ProGuard rules.\n\nHowever, you might need rules for Retrofit and its dependencies.\n\n## Contributing\n\nWe believe that the community can help us improve and build better a product.\nPlease refer to our [contributing guide](CONTRIBUTING.md) to learn about the types of contributions we accept and the process for submitting them.\n\nTo ensure that our community remains respectful and professional, we defined a [code of conduct](CODE_OF_CONDUCT.md) that we expect all contributors to follow.\n\nFor easier developing a `samples` with proper implementations are provided.\n\nWe appreciate your interest and look forward to your contributions.\n\n## License\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.com).\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"}