-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#20 Create simple setup reproducing the issue
- Loading branch information
Showing
7 changed files
with
162 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>ch.jalu</groupId> | ||
<artifactId>injector.testmodule</artifactId> | ||
<!-- Keep version in sync with ch.jalu.injector --> | ||
<version>0.2-SNAPSHOT</version> | ||
|
||
<name>Dependency Injector test module</name> | ||
<description>Test for the ch.jalu.injector project</description> | ||
<url>https://github.com/ljacqu/DependencyInjector</url> | ||
|
||
<issueManagement> | ||
<url>https://github.com/ljacqu/DependencyInjector/issues</url> | ||
<system>GitHub Issues</system> | ||
</issueManagement> | ||
|
||
<licenses> | ||
<license> | ||
<name>MIT License</name> | ||
<url>http://www.opensource.org/licenses/mit-license.php</url> | ||
<distribution>repo</distribution> | ||
</license> | ||
</licenses> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.5.1</version> | ||
<configuration> | ||
<source>1.7</source> | ||
<target>1.7</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>ch.jalu</groupId> | ||
<artifactId>injector</artifactId> | ||
<version>0.2-SNAPSHOT</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>javax.validation</groupId> | ||
<artifactId>validation-api</artifactId> | ||
<version>1.1.0.Final</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
26 changes: 26 additions & 0 deletions
26
test-module/src/main/java/ch/jalu/testmodule/ClassWithMethodParam.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
|
||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
test-module/src/main/java/ch/jalu/testmodule/services/OneService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package ch.jalu.testmodule.services; | ||
|
||
/** | ||
* Simple service for sample injection setup. | ||
*/ | ||
public class OneService { | ||
|
||
public String getName() { | ||
return "one service"; | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
test-module/src/main/java/ch/jalu/testmodule/services/ThreeService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
test-module/src/main/java/ch/jalu/testmodule/services/TwoService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |