{"id":42113928,"url":"https://github.com/ksaua/remock","last_synced_at":"2026-01-26T14:03:33.035Z","repository":{"id":27737178,"uuid":"31224874","full_name":"ksaua/remock","owner":"ksaua","description":"Spring mocking simplified","archived":false,"fork":false,"pushed_at":"2024-10-01T16:08:33.000Z","size":408,"stargazers_count":17,"open_issues_count":5,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-08T00:23:28.441Z","etag":null,"topics":["java","mockito","spring-test"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ksaua.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}},"created_at":"2015-02-23T19:19:59.000Z","updated_at":"2024-10-01T16:08:36.000Z","dependencies_parsed_at":"2022-09-03T03:03:46.788Z","dependency_job_id":null,"html_url":"https://github.com/ksaua/remock","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ksaua/remock","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksaua%2Fremock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksaua%2Fremock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksaua%2Fremock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksaua%2Fremock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ksaua","download_url":"https://codeload.github.com/ksaua/remock/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ksaua%2Fremock/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28780056,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-26T13:55:28.044Z","status":"ssl_error","status_checked_at":"2026-01-26T13:55:26.068Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["java","mockito","spring-test"],"created_at":"2026-01-26T14:03:23.663Z","updated_at":"2026-01-26T14:03:33.029Z","avatar_url":"https://github.com/ksaua.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Remock\n\n[![Build Status](https://travis-ci.org/ksaua/remock.svg?branch=master)](https://travis-ci.org/ksaua/remock)\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/no.saua.remock/remock/badge.svg)](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22no.saua.remock%22)\n[![Coverage Status](https://coveralls.io/repos/ksaua/remock/badge.svg)](https://coveralls.io/r/ksaua/remock)\n\nRemock is a small library which helps integration testing spring applications.\nIt is heavily inspired by [springockito-annotations](https://bitbucket.org/kubek2k/springockito/wiki/Home) which\nunfortunately appears not be maintained anymore.\n\nRemock allows you to easily:\n\n* Replace any spring bean with a Mockito mock.\n* Replace any spring bean with a Mockito spy.\n* Replace any spring bean with a different implementation.\n* Reject any spring bean from being created without replacing it.\n\nNote: Remock only works with Spring 5.0 (or later) and Java 8 (or later).\n\n# Table of Contents\n\n  * [Remock](#remock)\n  * [Getting it](#getting-it)\n  * [Using it](#using-it)\n    * [Mocking out a dependency:](#mocking-out-a-dependency)\n    * [Spying on a dependency:](#spying-on-a-dependency)\n    * [Replacing a bean with a non-mockito mock](#replacing-a-bean-with-a-non-mockito-mock)\n    * [Rejecting a dependency:](#rejecting-a-dependency)\n    * [Grouping common mocks](#grouping-common-mocks)\n    * [Lazy initialization](#lazy-initialization)\n    * [Using Remock and Spring MVC](#using-remock-and-spring-mvc)\n  * [Difference between Springockito and Remock](#difference-between-springockito-and-remock)\n\n# Getting it\n\nFollow [this link](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22no.saua.remock%22) to maven central. Choose the\nlatest version, and choose a build system.\n\n# Using it\n\ntl;dr: Annotate your Spring test-classes with `@BootstrapWith(RemockBootstrapper.class)`. Then you can annotate the\ntest-class or field with `@Reject`, `@ReplaceWithImpl`, `@ReplaceWithMock` or `@WrapWithSpy`.\n\n## Mocking out a dependency:\n\nThe following code will replace `SomeDependency` with a Mockito mock. Since `@ReplaceWithMock` is a meta-annotation for\n `@Autowired`, it will also automatically be injected into the test. Usage:\n\n    @RunWith(SpringJUnit4ClassRunner.class)\n    @BootstrapWith(RemockBootstrapper.class)\n    @ContextConfiguration(classes = SomeService.class)\n    public class ReplaceWithMockTest {\n\n        @ReplaceWithMock\n        public SomeDependency someDependency;\n\n        @Inject\n        public SomeService someService;\n\n        @Test\n        public void test() {\n            when(someDependency.method()).thenReturn(42);\n            assertEquals(21, someService.getHalf());\n            assertTrue(isMock(someDependency));\n        }\n    }\n\n`@ReplaceWithMock` can also be annotated directly test-class where it is repeatable.\n\n## Spying on a dependency:\n\nThe following code will wrap the original `SomeDependency` instance with a Mockito spy. Since `@WrapWithSpy` is a\nmeta-annotation for `@Autowired`, it will also automatically be injected into the test. Usage:\n\n    @RunWith(SpringJUnit4ClassRunner.class)\n    @BootstrapWith(RemockBootstrapper.class)\n    @ContextConfiguration(classes = SomeService.class)\n    public class ReplaceWithMockTest {\n\n        @WrapWithSpy\n        public SomeDependency someDependency;\n\n        @Inject\n        public SomeService someService;\n\n        @Test\n        public void test() {\n            someService.getHalf()\n            verify(someDependency).method();\n        }\n    }\n\n\n`@WrapWithSpy` can also be annotated directly on the test-class where it is repeatable. \n\n## Replacing a bean with a non-mockito mock\n\nThe following code will replace `ServiceImpl` with `ServiceMock`. Since @ReplaceWithImpl is a meta-annotation the\nbean will be auto injected. Usage:\n\n    @RunWith(SpringJUnit4ClassRunner.class)\n    @BootstrapWith(RemockBootstrapper.class)\n    @ContextConfiguration(classes = {ServiceImpl.class})\n    public static class ReplaceWithImplAnnotatedOnFieldTest {\n\n        @ReplaceWithImpl(value = ServiceImpl.class, with = ServiceMock.class)\n        public Service service;\n\n        @Test\n        public void test() {\n            assertEquals(ServiceMock.class, service.getClass());\n        }\n    }\n\n`@ReplaceWithImpl` can also be annotated directly on the test-class where it is repeatable.\n\n## Rejecting a dependency:\n\nThe following code will reject any bean definitions of the type `SomeDangerousService` from being defined in\nSpring's bean factory.\n\n    @RunWith(SpringJUnit4ClassRunner.class)\n    @BootstrapWith(RemockBootstrapper.class)\n    @Reject(SomeDangerousService.class)\n    @ContextConfiguration(classes = SomeService.class)\n    public class RejectTest {\n\n        @Test\n        public void test() {\n            /* SomeDangerousService does not exist */\n        }\n    }\n\nThis is a bit out of the ordinary, but it's quite powerful. This is particularly useful when you inject List or Maps of\n an interface or a superclass and want to remove some beans from the bean factory.\n\nAnother use-case is for controlling which beans are defined and lifecycled when a `@ComponentScan` is used.\n\n`@Reject` can also be used for a field, though I cannot see a reason why you would. `@Reject` is repeatable.\n\n## Grouping common mocks\n\nOften tests require the same mocks. Remock allows you to easily group mocks, either by specifying the remock-annotations\non a superclass, or by using the `@RemockContextConfiguration`.\n\n    @RunWith(SpringJUnit4ClassRunner.class)\n    @BootstrapWith(RemockBootstrapper.class)\n    @ContextConfiguration(classes = {SomeServiceWithDependencies.class, SomeDependency.class})\n    @RemockContextConfiguration(MyRemockConfig.class)\n    public class RemockContextConfigurationTest {\n\n        @Inject\n        private SomeServiceWithDependencies someServiceWithDependencies;\n\n        @Test\n        public void test() {\n            isMock(someServiceWithDependencies.getDependency());\n        }\n\n        @ReplaceWithMock(SomeServiceWithDependencies.class)\n        @Reject(SomeDependency.class)\n        public static class MyRemockConfig {\n        }\n    }\n\nFor more detailed examples see the test cases.\n\n## Lazy initialization\n\nA core goal of Remock is to be as fast as possible. Remock will therefore by default set all the beans to be lazily initialized. \nThis is to enable you to point the `@ContextConfigration` at e.g. a class that does component scanning. \n\nHowever, the following exceptions apply: \n* Remock will *not* set beans with the role ROLE_INFRASTRUCTURE to lazy with the assumption that those beans are required to correctly setup the spring context.\n* Remock will *not* set beans directly defined in the `@ContextConfiguration` to lazy. The rationale for this is that by adding a class to `@ContextConfiguration` you obviously need it in your test.\n\nAnything else will be lazy unless you use: \n\n### @DisableLazyInit\n\nAnnotating your test with `@DisableLazyInit` disables the lazy init for all classes.\n\n    @RunWith(SpringJUnit4ClassRunner.class)\n    @BootstrapWith(RemockBootstrapper.class)\n    @ContextConfiguration(classes = SomeClassAnnotatedWith_Configuration.class})\n    @DisableLazyInit\n    public class MyTest {\n\n        @Test\n        public void test() {\n            /* ... */\n        }\n    }\n\nIf you do not want everything to be eagerly initialized, you can specify which beans you want to disable lazy init for.\n\n    @DisableLazyInit(value = EagerService.class, beanName = \"eagerBean\")\n\n\n## Using Remock and Spring MVC\n\nTrying to use Spring's `@WebAppConfiguration` in conjunction with Remock will fail with an error message like:\n\n    java.lang.IllegalStateException: Configuration error: found multiple declarations of @BootstrapWith on test class\n    [org.example.MyClass] with values [class org.springframework.test.context.web.WebTestContextBootstrapper, class\n    no.saua.remock.RemockBootstrapper]\n\nInstead you'll have to use the equivalent `@RemockWebAppTest` annotation:\n\n    @RunWith(SpringJUnit4ClassRunner.class)\n    @BootstrapWith(RemockBootstrapper.class)\n    @ContextConfiguration(classes = WebAppTest.MyController.class)\n    @RemockWebAppTest\n    public class WebAppTest extends CommonTest {\n\n        @Inject\n        private WebApplicationContext context;\n\n        @Test\n        public void meh() throws Exception {\n            MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(context).build();\n            MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get(\"/abc\")).andReturn();\n            String contentAsString = mvcResult.getResponse().getContentAsString();\n            assertEquals(\"abcxyz\", contentAsString);\n        }\n\n        @Controller\n        public static class MyController {\n            @RequestMapping(\"/abc\")\n            @ResponseBody\n            public String abc() {\n                return \"abcxyz\";\n            }\n        }\n    }\n\nNote that lazy loading does not work with spring mvc `@Controller`s. They will all be eagerly instantiated.\n\n\n# Difference between Springockito and Remock\n\nThe big difference between Springockito and Remock is whether or not the original implementation lives inside springs\nbean factory. While Springockito will use @Primary on all mocked/spied beans, thus taking precedence over the originals,\nthey will still be injected if you `@Inject List\u003cInterfaceOrSuperClass\u003e`, or `@Inject Map\u003cString, InterfaceOrSuperClass\u003e`.\n\nRemock takes a different approach. It takes control over Spring's bean factory and downright rejects adding the\nbean definitions of beans it knows should be mocked or rejected.\n\nWith regards to bean factories Remock cannot reject them because it cannot know which class the bean factory will create\nuntil after Spring has resolved the bean factory. Remock will instead ensure that Spring never uses the factory-method\nby returning a bogus class if the bean factory was about to create a rejected/mocked class.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fksaua%2Fremock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fksaua%2Fremock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fksaua%2Fremock/lists"}