diff --git a/.gitignore b/.gitignore index a09f7f4..2026dfc 100644 --- a/.gitignore +++ b/.gitignore @@ -42,7 +42,7 @@ fabric.properties ### Intellij Patch ### # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 -# *.iml +*.iml # modules.xml # .idea/misc.xml # *.ipr diff --git a/test-module/pom.xml b/test-module/pom.xml new file mode 100644 index 0000000..9f68660 --- /dev/null +++ b/test-module/pom.xml @@ -0,0 +1,57 @@ + + 4.0.0 + + ch.jalu + injector.testmodule + + 0.2-SNAPSHOT + + Dependency Injector test module + Test for the ch.jalu.injector project + https://github.com/ljacqu/DependencyInjector + + + https://github.com/ljacqu/DependencyInjector/issues + GitHub Issues + + + + + MIT License + http://www.opensource.org/licenses/mit-license.php + repo + + + + + UTF-8 + + + + + + maven-compiler-plugin + 3.5.1 + + 1.7 + 1.7 + + + + + + + + ch.jalu + injector + 0.2-SNAPSHOT + + + + javax.validation + validation-api + 1.1.0.Final + provided + + + diff --git a/test-module/src/main/java/ch/jalu/testmodule/ClassWithMethodParam.java b/test-module/src/main/java/ch/jalu/testmodule/ClassWithMethodParam.java new file mode 100644 index 0000000..214b8b0 --- /dev/null +++ b/test-module/src/main/java/ch/jalu/testmodule/ClassWithMethodParam.java @@ -0,0 +1,26 @@ +package ch.jalu.testmodule; + +import ch.jalu.testmodule.services.TwoService; + +import javax.inject.Inject; +import javax.validation.Validator; + +/** + * Sample class with a method param from a non-provided dependency. + */ +public class ClassWithMethodParam { + + @Inject + private TwoService twoService; + + ClassWithMethodParam() { + } + + public String getName() { + return twoService.getName(); + } + + private void processValidator(Validator validator) { + // noop + } +} diff --git a/test-module/src/main/java/ch/jalu/testmodule/Main.java b/test-module/src/main/java/ch/jalu/testmodule/Main.java new file mode 100644 index 0000000..fcdfd70 --- /dev/null +++ b/test-module/src/main/java/ch/jalu/testmodule/Main.java @@ -0,0 +1,26 @@ +package ch.jalu.testmodule; + +import ch.jalu.injector.Injector; +import ch.jalu.injector.InjectorBuilder; + +import javax.validation.Validation; + +public class Main { + + public static void main(String... args) { + // Initially check that class from provided-scoped dependency is NOT present + try { + new Validation(); + throw new IllegalStateException("Expected Validation not to be in class path!"); + } catch (NoClassDefFoundError e) { + // all good + } + + Injector injector = new InjectorBuilder().addDefaultHandlers("ch.jalu.testmodule").create(); + ClassWithMethodParam classWithMethodParam = injector.getSingleton(ClassWithMethodParam.class); + if (!"one service".equals(classWithMethodParam.getName())) { + throw new IllegalStateException("ClassWithMethodParam#getName was not as expected"); + } + + } +} \ No newline at end of file diff --git a/test-module/src/main/java/ch/jalu/testmodule/services/OneService.java b/test-module/src/main/java/ch/jalu/testmodule/services/OneService.java new file mode 100644 index 0000000..2378206 --- /dev/null +++ b/test-module/src/main/java/ch/jalu/testmodule/services/OneService.java @@ -0,0 +1,12 @@ +package ch.jalu.testmodule.services; + +/** + * Simple service for sample injection setup. + */ +public class OneService { + + public String getName() { + return "one service"; + } + +} diff --git a/test-module/src/main/java/ch/jalu/testmodule/services/ThreeService.java b/test-module/src/main/java/ch/jalu/testmodule/services/ThreeService.java new file mode 100644 index 0000000..01b8081 --- /dev/null +++ b/test-module/src/main/java/ch/jalu/testmodule/services/ThreeService.java @@ -0,0 +1,21 @@ +package ch.jalu.testmodule.services; + +import javax.inject.Inject; + +/** + * Simple service for sample injection setup. + */ +public class ThreeService { + + private final String name; + + @Inject + ThreeService(TwoService twoService) { + this.name = twoService.getName(); + } + + public String getName() { + return name; + } + +} diff --git a/test-module/src/main/java/ch/jalu/testmodule/services/TwoService.java b/test-module/src/main/java/ch/jalu/testmodule/services/TwoService.java new file mode 100644 index 0000000..296eaf6 --- /dev/null +++ b/test-module/src/main/java/ch/jalu/testmodule/services/TwoService.java @@ -0,0 +1,19 @@ +package ch.jalu.testmodule.services; + +import javax.inject.Inject; + +/** + * Simple service for sample injection setup. + */ +public class TwoService { + + @Inject + private OneService oneService; + + TwoService() { + } + + public String getName() { + return oneService.getName(); + } +}