generated from micronaut-projects/micronaut-project-template
-
Notifications
You must be signed in to change notification settings - Fork 0
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
4573442
commit 0df1173
Showing
4 changed files
with
86 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
5 changes: 5 additions & 0 deletions
5
micronaut-guice/src/test/java/io/micronaut/guice/doc/examples/bindings/injector2/Engine.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,5 @@ | ||
package io.micronaut.guice.doc.examples.bindings.injector2; | ||
|
||
public record Engine<T>(T cylinder) { | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
...-guice/src/test/java/io/micronaut/guice/doc/examples/bindings/injector2/InjectorTest.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,51 @@ | ||
package io.micronaut.guice.doc.examples.bindings.injector2; | ||
|
||
import com.google.inject.AbstractModule; | ||
import com.google.inject.Injector; | ||
import com.google.inject.Key; | ||
import com.google.inject.Provides; | ||
import com.google.inject.Singleton; | ||
import com.google.inject.TypeLiteral; | ||
import io.micronaut.guice.annotation.Guice; | ||
import io.micronaut.test.extensions.junit5.annotation.MicronautTest; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
@MicronautTest(startApplication = false, environments = "generic-test") | ||
@Guice(modules = FooModule.class, environments = "generic-test") | ||
public class InjectorTest { | ||
@Test | ||
void testInjector(Injector injector) { | ||
Foo foo = injector.getInstance(Foo.class); | ||
Assertions.assertNotNull(foo); | ||
|
||
Engine<V8> v8 = injector.getInstance(Key.get(new TypeLiteral<Engine<V8>>() { | ||
})); | ||
Engine<V6> v6 = injector.getInstance(Key.get(new TypeLiteral<Engine<V6>>() { | ||
})); | ||
|
||
Assertions.assertNotNull(v8); | ||
Assertions.assertInstanceOf(V8.class, v8.cylinder()); | ||
|
||
Assertions.assertNotNull(v6); | ||
Assertions.assertInstanceOf(V6.class, v6.cylinder()); | ||
} | ||
} | ||
|
||
class FooModule extends AbstractModule { | ||
|
||
@Provides | ||
public Engine<V8> v8() { | ||
return new Engine<>(new V8()); | ||
} | ||
|
||
@Provides | ||
public Engine<V6> v6() { | ||
return new Engine<>(new V6()); | ||
} | ||
} | ||
@Singleton | ||
class Foo {} | ||
|
||
class V8 {} | ||
class V6 {} |