Skip to content

Commit

Permalink
#20 Create simple setup reproducing the issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ljacqu committed Jul 11, 2016
1 parent bfd9ed0 commit a2a6699
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
57 changes: 57 additions & 0 deletions test-module/pom.xml
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>
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
}
}
26 changes: 26 additions & 0 deletions test-module/src/main/java/ch/jalu/testmodule/Main.java
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");
}

}
}
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";
}

}
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;
}

}
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();
}
}

0 comments on commit a2a6699

Please sign in to comment.