Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
59ca428
commit fafaa96
Showing
9 changed files
with
130 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package injection; | ||
|
||
public class ComponentUnderTest { | ||
|
||
private int paramToTest = 42; | ||
String param; | ||
String elseone; | ||
|
||
public ComponentUnderTest(TestDriver testDriver) { | ||
this.param = testDriver.param; | ||
this.elseone = testDriver.elseOne; | ||
} | ||
|
||
public int getParamToTest() { | ||
return paramToTest; | ||
} | ||
} |
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 injection; | ||
|
||
import com.google.inject.Inject; | ||
import com.google.inject.Provider; | ||
|
||
public class ComponentUnderTestProvider implements Provider<ComponentUnderTest> { | ||
|
||
private TestDriver testDriver; | ||
|
||
@Inject | ||
public ComponentUnderTestProvider(TestDriver testDriver) { | ||
this.testDriver = testDriver; | ||
} | ||
|
||
@Override | ||
public ComponentUnderTest get() { | ||
return new ComponentUnderTest(testDriver); | ||
} | ||
} |
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,20 @@ | ||
package injection; | ||
|
||
import com.google.inject.Inject; | ||
import org.testng.annotations.Guice; | ||
import org.testng.annotations.Test; | ||
|
||
@Guice(modules = {TestModule.class}) | ||
public class SimpleTest { | ||
|
||
@Inject | ||
ComponentUnderTest component; | ||
|
||
@Test | ||
public void sampleTest() { | ||
System.out.println(component.getParamToTest()); | ||
System.out.println(component.param); | ||
System.out.println(component.elseone); | ||
} | ||
|
||
} |
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,13 @@ | ||
package injection; | ||
|
||
import org.aeonbits.owner.Config; | ||
|
||
public interface TestConfig extends Config { | ||
|
||
@Key("param") | ||
String param(); | ||
|
||
@Key("elseOne") | ||
String elseOne(); | ||
|
||
} |
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 injection; | ||
|
||
import com.google.inject.Provider; | ||
import org.aeonbits.owner.ConfigFactory; | ||
|
||
public class TestConfigProvider implements Provider<TestConfig> { | ||
|
||
@Override | ||
public TestConfig get() { | ||
return ConfigFactory.create(TestConfig.class); | ||
} | ||
} |
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,13 @@ | ||
package injection; | ||
|
||
public class TestDriver { | ||
|
||
String param; | ||
String elseOne; | ||
|
||
public TestDriver(TestConfig config) { | ||
this.param = config.param(); | ||
this.elseOne = config.elseOne(); | ||
} | ||
|
||
} |
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,20 @@ | ||
package injection; | ||
|
||
import com.google.inject.Inject; | ||
import com.google.inject.Provider; | ||
|
||
public class TestDriverProvider implements Provider<TestDriver> { | ||
|
||
private TestConfig testConfig; | ||
|
||
@Inject | ||
public TestDriverProvider(TestConfig testConfig) { | ||
this.testConfig = testConfig; | ||
} | ||
|
||
@Override | ||
public TestDriver get() { | ||
return new TestDriver(testConfig); | ||
} | ||
|
||
} |
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,14 @@ | ||
package injection; | ||
|
||
import com.google.inject.Binder; | ||
import com.google.inject.Module; | ||
|
||
public class TestModule implements Module { | ||
|
||
@Override | ||
public void configure(Binder binder) { | ||
binder.bind(TestConfig.class).toProvider(TestConfigProvider.class); | ||
binder.bind(TestDriver.class).toProvider(TestDriverProvider.class); | ||
binder.bind(ComponentUnderTest.class).toProvider(ComponentUnderTestProvider.class); | ||
} | ||
} |
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,2 @@ | ||
param=parararam | ||
elseOne=elseoneone |