{"id":36602190,"url":"https://github.com/exabrial/mockito-object-injection","last_synced_at":"2026-01-12T08:39:32.690Z","repository":{"id":144589358,"uuid":"148383450","full_name":"exabrial/mockito-object-injection","owner":"exabrial","description":"Mockito Object Injection for JUnit5. Inject Strings and other Objects directly into Mocks without needing setters or constructor injection.","archived":false,"fork":false,"pushed_at":"2025-02-01T21:03:52.000Z","size":50,"stargazers_count":8,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-17T19:59:18.130Z","etag":null,"topics":["cdi","dependency-injection","java","java-ee","junit","junit-extension","junit5","junit5-framework","mocking","mockito","spring","spring-boot","springboot","testing"],"latest_commit_sha":null,"homepage":"","language":"Java","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/exabrial.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-09-11T21:37:47.000Z","updated_at":"2025-02-01T21:03:56.000Z","dependencies_parsed_at":"2023-10-11T01:03:44.769Z","dependency_job_id":"f054c32f-9683-4e72-8cc9-eba7cd971ddc","html_url":"https://github.com/exabrial/mockito-object-injection","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/exabrial/mockito-object-injection","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exabrial%2Fmockito-object-injection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exabrial%2Fmockito-object-injection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exabrial%2Fmockito-object-injection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exabrial%2Fmockito-object-injection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/exabrial","download_url":"https://codeload.github.com/exabrial/mockito-object-injection/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exabrial%2Fmockito-object-injection/sbom","scorecard":{"id":387519,"data":{"date":"2025-08-11","repo":{"name":"github.com/exabrial/mockito-object-injection","commit":"e0a5011511905a6c72cc3147de0cacbd76020878"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.7,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":1,"reason":"Found 3/24 approved changesets -- score normalized to 1","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":8,"reason":"3 out of the last 3 releases have a total of 3 signed artifacts.","details":["Info: signed release artifact: mockito-object-injection-2.3.0-javadoc.jar.asc: https://github.com/exabrial/mockito-object-injection/releases/tag/mockito-object-injection-2.3.0","Info: signed release artifact: mockito-object-injection-2.0.2-sources.jar.asc: https://github.com/exabrial/mockito-object-injection/releases/tag/mockito-object-injection-2.0.2","Info: signed release artifact: mockito-object-injection-2.0.1-sources.jar.asc: https://github.com/exabrial/mockito-object-injection/releases/tag/mockito-object-injection-2.0.1","Warn: release artifact mockito-object-injection-2.3.0 does not have provenance: https://api.github.com/repos/exabrial/mockito-object-injection/releases/197940329","Warn: release artifact mockito-object-injection-2.0.2 does not have provenance: https://api.github.com/repos/exabrial/mockito-object-injection/releases/29882765","Warn: release artifact mockito-object-injection-2.0.1 does not have provenance: https://api.github.com/repos/exabrial/mockito-object-injection/releases/29882373"],"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 9 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-18T16:59:52.951Z","repository_id":144589358,"created_at":"2025-08-18T16:59:52.951Z","updated_at":"2025-08-18T16:59:52.951Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28337599,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T06:09:07.588Z","status":"ssl_error","status_checked_at":"2026-01-12T06:05:18.301Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":["cdi","dependency-injection","java","java-ee","junit","junit-extension","junit5","junit5-framework","mocking","mockito","spring","spring-boot","springboot","testing"],"created_at":"2026-01-12T08:39:32.084Z","updated_at":"2026-01-12T08:39:32.679Z","avatar_url":"https://github.com/exabrial.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mockito Object Injection\n\n## Preamble\n\n* Mock testing leads to highly focused tests where every variable is controlled.\n* Dependency Injection + well structured programs + Mock testing = super clean codebase.\n\nThe problem is, how does one Mock a String, Boolean, or other final type if those types are being Injected?\n\n## Summary \n\nThis Junit Extension allows you to inject Strings (or any other object) into your `@InjectMocks` targets [objects under test] without booting a Spring, Weld, CDI, Arquillian, EJB, or other container. It's super lightweight, over 100,000x faster than booting Arquillian, and easy to use.\n\n## Example Problem\n\nTake this Spring Controller (or if you're using the far superior and modern CDI framework, think `@AppplicationScoped` instead of `@Controller` and `@Inject` instead of `@Autowired`)\n\n```\n@Controller\npublic class MyController {\n @Value(\"securityEnabled\")\n private Boolean securityEnabled;\n @Autowired\n private Authenticator auther;\n @Autowired\n private Logger log;\n\n public void doSomething() {\n  if (securityEnabled) {\n    auther.something();\n  } else {\n    log.warn(\"sec disabled\");\n  }\n }\n}\n```\n\nIf you wanted to write a _true unit test*_ with no external dependencies, you'd probably want to use Mockito mock your dependencies:\n\n```\n@ExtendWith({ MockitoExtension.class })\nclass MyControllerTest {\n @InjectMocks\n private MyController myController;\n @Mock\n private Logger log;\n @Mock\n private Authenticator auther;\n  \n  @Test\n  void testDoSomething() throws Exception {\n   myController.doSomething();\n   // results in NPE because myController.securityEnabled is null\n  }\n }\n```\n\n* Testing a \"unit\" of code is a unit test. In Java, typically a class is the smallest unit of code. A static funciton can also be considered a unit of code, but static functions should not be tested using Mock testing for reasons beyond the scope of this document. See: http://misko.hevery.com/2008/12/15/static-methods-are-death-to-testability\n\n## Example Solution\n\nThis JUnit5 extension allows you to arbitrarily set any field on your `@InjectMocks` [class under test] target. The injections happen _very late_; they happen when you call any non-private method on the class under test.\n\n\n```\nimport com.github.exabrial.junit5.injectmap.InjectionMap;\nimport com.github.exabrial.junit5.injectmap.InjectMapExtension;\n\n@TestInstance(Lifecycle.PER_CLASS)\n@ExtendWith({ MockitoExtension.class, InjectExtension.class })\nclass MyControllerTest {\n @InjectMocks\n private MyController myController;\n @Mock\n private Logger log;\n @Mock\n private Authenticator auther;\n @InjectionSource\n private Boolean securityEnabled;\n \n @Test\n void testDoSomething_secEnabled() throws Exception {\n  securityEnabled = Boolean.TRUE;\n  myController.doSomething();\n  // wahoo no NPE! Test the \"if then\" half of the branch\n }\n \n @Test \n void testDoSomething_secDisabled() throws Exception {\n  securityEnabled = Boolean.FALSE;\n  myController.doSomething();\n  // wahoo no NPE! Test the \"if else\" half of branch\n }\n}\n```\n\n## @PostConstruct invocation\n\nCDI and SpringFramework allow the use of `@PostConstruct`. This is like a constructor, except the method annotated will be invoked _after_ dependency injection is complete. This extension can be commanded to invoke the method annotated with `@PostConstruct` like so:\n\n\n```\n@ApplicationScoped\npublic class MyController {\n @Inject\n private Logger log; \n \n @PostConstruct\n private void postConstruct() {\n  log.info(\"initializing myController...\");\n  ... some initialization code\n }\n}\n```\n\n```\n@TestInstance(Lifecycle.PER_CLASS)\n@ExtendWith({ MockitoExtension.class, InjectExtension.class })\nclass MyControllerTest {\n\n @InjectMocks\n @InvokePostConstruct\n // The postConstruct on this controller will be invoked\n private MyController myController;\n \n @Test\n void testSometing()\n```\n\nRef: https://docs.oracle.com/javaee/7/api/javax/annotation/PostConstruct.html\n\n## Enabling/Disabling Injection Behavior\n\nThe InjectExtension provides methods to turn on and off the behavior as well as query the status of injection.\n\n```\nInjectExtension.enable();\nInjectExtension.bypass();\nInjectExtension.status(); // returns true if enabled\n```\n\nIt's recommended that if you're using the above APIs that you reset the Injector status between tests.\n\n```\n@AfterEach\nvoid afterEach() {\n    InjectExtension.enable();\n}\n```\n\n## License\n\nAll files are licensed Apache Source License 2.0. Please consider contributing any improvements you make back to the project.\n\n## Usage\n\nMaven Coordinates:\n\n```\n\u003cdependency\u003e\n \u003cgroupId\u003eorg.junit.jupiter\u003c/groupId\u003e\n \u003cartifactId\u003ejunit-jupiter-api\u003c/artifactId\u003e\n \u003cversion\u003e5.8.2\u003c/version\u003e\n \u003cscope\u003etest\u003c/scope\u003e\n\u003c/dependency\u003e\n\u003cdependency\u003e\n \u003cgroupId\u003eorg.mockito\u003c/groupId\u003e\n \u003cartifactId\u003emockito-core\u003c/artifactId\u003e\n \u003cversion\u003e4.6.1\u003c/version\u003e\n \u003cscope\u003etest\u003c/scope\u003e\n\u003c/dependency\u003e\n\u003cdependency\u003e\n \u003cgroupId\u003ecom.github.exabrial\u003c/groupId\u003e\n \u003cartifactId\u003emockito-object-injection\u003c/artifactId\u003e\n \u003cversion\u003e2.3.0\u003c/version\u003e\n \u003cscope\u003etest\u003c/scope\u003e\n\u003c/dependency\u003e\n```\n\nThe final note is that it should extraordinarily obvious that multithreading on the same test instances will cause problems. Set your forking policies accordingly to avoid race conditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexabrial%2Fmockito-object-injection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexabrial%2Fmockito-object-injection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexabrial%2Fmockito-object-injection/lists"}