{"id":36627090,"url":"https://github.com/kaiwinter/di-instantiator","last_synced_at":"2026-01-12T09:33:16.121Z","repository":{"id":34846965,"uuid":"38839788","full_name":"kaiwinter/di-instantiator","owner":"kaiwinter","description":"Unit testing support for code which uses dependency injection","archived":false,"fork":false,"pushed_at":"2020-10-26T11:49:40.000Z","size":38,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-04T03:04:17.896Z","etag":null,"topics":["integration-testing","jee","spring","unit-testing"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kaiwinter.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-09T19:06:27.000Z","updated_at":"2020-10-26T11:49:42.000Z","dependencies_parsed_at":"2022-09-15T06:51:10.732Z","dependency_job_id":null,"html_url":"https://github.com/kaiwinter/di-instantiator","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/kaiwinter/di-instantiator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaiwinter%2Fdi-instantiator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaiwinter%2Fdi-instantiator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaiwinter%2Fdi-instantiator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaiwinter%2Fdi-instantiator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kaiwinter","download_url":"https://codeload.github.com/kaiwinter/di-instantiator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kaiwinter%2Fdi-instantiator/sbom","scorecard":{"id":547847,"data":{"date":"2025-08-11","repo":{"name":"github.com/kaiwinter/di-instantiator","commit":"f933d397854f0948d9b6c91b6e38f31ca66057b0"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":1.7,"checks":[{"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":"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":"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":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","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":"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":"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":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"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":0,"reason":"license file not detected","details":["Warn: project does not have a license file"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"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":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Vulnerabilities","score":3,"reason":"7 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-vmq6-5m68-f53m","Warn: Project is vulnerable to: GHSA-668q-qrv7-99fm","Warn: Project is vulnerable to: GHSA-6v67-2wr5-gvf4","Warn: Project is vulnerable to: GHSA-pr98-23f8-jwxv","Warn: Project is vulnerable to: GHSA-5mg8-w23w-74h3","Warn: Project is vulnerable to: GHSA-7g45-4rm6-3mm3","Warn: Project is vulnerable to: GHSA-mvr2-9pj6-7w5j"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-20T09:59:23.896Z","repository_id":34846965,"created_at":"2025-08-20T09:59:23.896Z","updated_at":"2025-08-20T09:59:23.896Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28337728,"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":["integration-testing","jee","spring","unit-testing"],"created_at":"2026-01-12T09:33:16.067Z","updated_at":"2026-01-12T09:33:16.115Z","avatar_url":"https://github.com/kaiwinter.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# di-instantiator\n[![Build Status](https://api.travis-ci.org/kaiwinter/di-instantiator.svg)](https://travis-ci.org/kaiwinter/di-instantiator)\n[![Coverage Status](https://coveralls.io/repos/kaiwinter/di-instantiator/badge.svg?branch=master\u0026service=github)](https://coveralls.io/github/kaiwinter/di-instantiator?branch=master)\n\n_Inspired by [needle4j](https://github.com/needle4j/needle4j/) which creates an instance of a bean initialized with mocks._\n\nIn contrast to needle4j this library is not injecting mock objects but instances of the real objects. For interface types an implementation is looked up from the source and gets injected.\nAs a result you´ll get a completely initialized object graph with real objects.\nYou can even override the automatic implementation lookup and provide specific implementations (or mocks if you like).\n\nThe library handles all fields which are annotated with ```@Inject```. This can be configured to handle ```@EJB``` fields as well for example.\n\n## Example\n\n### The application code\nUse-case class:\n\n```java\npublic final class DemoUsecaseImpl implements DemoUsecase {\n   \n   @Inject\n   private DemoDao dao;\n   \n   @Override\n   public DemoEntity loadEntity(int id) {\n      return dao.loadEntity(id);\n   }\n   \n   @Override\n   public void saveEntity(DemoEntity entity) {\n      dao.saveEntity(entity);\n   }\n}\n```\n\nDAO class:\n```java\npublic final class DemoDaoImpl implements DemoDao {\n   \n   @PersistenceContext(unitName = \"PU\")\n   private EntityManager entityManager;\n   \n   @Override\n   public DemoEntity loadEntity(int id) {\n      return entityManager.find(DemoEntity.class, id);\n   }\n   \n   @Override\n   public void saveEntity(DemoEntity entity) {\n      entityManager.persist(entity);\n   }\n}\n```\n\n### The test\nFor demonstration purpose we are saving an entity by calling the use case method ```saveEntity()```.\nAfterwards it is loaded by its ID.\nThe test uses a real database which also could be a mock.\nThis might not be a real world example but demonstrates an advanced use of the library.\n```java\n@Test\npublic void test() {\n   // Create factory which sets fields annotated by @Inject and @PersistenceContext\n   InjectionObjectFactory factory = new InjectionObjectFactory(Inject.class, PersistenceContext.class);\n   \n   // Create entity manager for test database and let factory use it\n   EntityManager entityManager = Persistence.createEntityManagerFactory(\"TestPU\", null).createEntityManager();\n   factory.setImplementationForClassOrInterface(EntityManager.class, entityManager);\n   entityManager.getTransaction().begin();\n   \n   // Obtain fully initialized object from factory, this is what will happen:\n   // 1. Instantiate DemoUsecaseImpl\n   // 2. Lookup implementation of DemoDao\n   // 3. Instantiate DemoDaoImpl \n   // 4. Set provided EntityManager in DemoDaoImpl\n   // 5. Set DemoDaoImpl in DemoUsecaseImpl\n   DemoUsecaseImpl usecase = factory.getInstance(DemoUsecaseImpl.class);\n   \n   // Save entity and test the result of a reload\n   usecase.saveEntity(new DemoEntity(1, \"test name\"));\n   \n   DemoEntity loaded = usecase.loadEntity(1);\n   Assert.assertEquals(\"test name\", loaded.getName());\n}\n```\n\n### FAQ\n#### What happens if two implementations are found for one interface?\nIf there is more than one implementation found an Exception is thrown. To provide a specific implementation use \n```setImplementingClassForInterface(Class\u003c?\u003e interfaceClass, Class\u003c?\u003e implementationClass)``` or ```factory.setImplementationForClassOrInterface(Class\u003c? extends T\u003e classOrInterface, T object)```.\n\n#### Which annotations are processed?\nBy default the factory handles all fields which are annotated with ```@Inject```. This can be changed by passing additional annotations in the constructor:\n```InjectionObjectFactory factory = new InjectionObjectFactory(Inject.class, EJB.class, PersistenceContext.class);```\n\n## Maven\n```xml\n\u003cdependency\u003e\n   \u003cgroupId\u003ecom.github.kaiwinter\u003c/groupId\u003e\n   \u003cartifactId\u003edi-instantiator\u003c/artifactId\u003e\n   \u003cversion\u003e1.1.1\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## License\n     Copyright 2015 Kai Winter\n     \n     Licensed under the Apache License, Version 2.0 (the \"License\");\n     you may not use this file except in compliance with the License.\n     You may obtain a copy of the License at\n     \n         http://www.apache.org/licenses/LICENSE-2.0\n     \n     Unless required by applicable law or agreed to in writing, software\n     distributed under the License is distributed on an \"AS IS\" BASIS,\n     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n     See the License for the specific language governing permissions and\n     limitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaiwinter%2Fdi-instantiator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkaiwinter%2Fdi-instantiator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkaiwinter%2Fdi-instantiator/lists"}