forked from quarkusio/quarkus
-
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.
Merge pull request quarkusio#37075 from manovotn/issue37042
- Loading branch information
Showing
6 changed files
with
266 additions
and
5 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
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
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
108 changes: 108 additions & 0 deletions
108
...ects/arc/tests/src/test/java/io/quarkus/arc/test/defaultbean/DefaultBeanPriorityTest.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,108 @@ | ||
package io.quarkus.arc.test.defaultbean; | ||
|
||
import jakarta.annotation.Priority; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.inject.spi.CDI; | ||
import jakarta.inject.Inject; | ||
import jakarta.inject.Singleton; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.DefaultBean; | ||
import io.quarkus.arc.test.ArcTestContainer; | ||
|
||
public class DefaultBeanPriorityTest { | ||
|
||
@RegisterExtension | ||
public ArcTestContainer container = new ArcTestContainer(MyBean.class, FooInterface.class, FooImpl1.class, FooImpl2.class, | ||
BarInterface.class, BarImpl1.class, BarImpl2.class); | ||
|
||
@Test | ||
public void testInjection() { | ||
MyBean myBean = Arc.container().select(MyBean.class).get(); | ||
Assertions.assertEquals(FooImpl2.class.getSimpleName(), myBean.getFoo().ping()); | ||
Assertions.assertEquals(BarImpl2.class.getSimpleName(), myBean.getBar().ping()); | ||
} | ||
|
||
@Test | ||
public void testSelect() { | ||
FooInterface foo = CDI.current().select(FooInterface.class).get(); | ||
Assertions.assertEquals(FooImpl2.class.getSimpleName(), foo.ping()); | ||
|
||
BarInterface bar = CDI.current().select(BarInterface.class).get(); | ||
Assertions.assertEquals(BarImpl2.class.getSimpleName(), bar.ping()); | ||
} | ||
|
||
@Singleton | ||
static class MyBean { | ||
|
||
@Inject | ||
FooInterface foo; | ||
|
||
@Inject | ||
BarInterface bar; | ||
|
||
FooInterface getFoo() { | ||
return foo; | ||
} | ||
|
||
BarInterface getBar() { | ||
return bar; | ||
} | ||
} | ||
|
||
interface FooInterface { | ||
String ping(); | ||
} | ||
|
||
@ApplicationScoped | ||
@DefaultBean | ||
@Priority(10) | ||
static class FooImpl1 implements FooInterface { | ||
|
||
@Override | ||
public String ping() { | ||
return FooImpl1.class.getSimpleName(); | ||
} | ||
} | ||
|
||
@ApplicationScoped | ||
@DefaultBean | ||
@Priority(20) | ||
static class FooImpl2 implements FooInterface { | ||
|
||
@Override | ||
public String ping() { | ||
return FooImpl2.class.getSimpleName(); | ||
} | ||
} | ||
|
||
interface BarInterface { | ||
String ping(); | ||
} | ||
|
||
@ApplicationScoped | ||
@DefaultBean | ||
// no priority annotation | ||
static class BarImpl1 implements BarInterface { | ||
|
||
@Override | ||
public String ping() { | ||
return BarImpl1.class.getSimpleName(); | ||
} | ||
} | ||
|
||
@ApplicationScoped | ||
@DefaultBean | ||
@Priority(1) | ||
static class BarImpl2 implements BarInterface { | ||
|
||
@Override | ||
public String ping() { | ||
return BarImpl2.class.getSimpleName(); | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...test/java/io/quarkus/arc/test/defaultbean/ambiguous/DefaultBeanPriorityAmbiguousTest.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,66 @@ | ||
package io.quarkus.arc.test.defaultbean.ambiguous; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import jakarta.annotation.Priority; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.inject.spi.DeploymentException; | ||
import jakarta.inject.Inject; | ||
import jakarta.inject.Singleton; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.DefaultBean; | ||
import io.quarkus.arc.test.ArcTestContainer; | ||
|
||
public class DefaultBeanPriorityAmbiguousTest { | ||
|
||
@RegisterExtension | ||
public ArcTestContainer container = ArcTestContainer.builder() | ||
.beanClasses(MyBean.class, FooInterface.class, FooImpl1.class, FooImpl2.class) | ||
.shouldFail() | ||
.build(); | ||
|
||
@Test | ||
public void testAmbiguousResolution() { | ||
Throwable error = container.getFailure(); | ||
assertNotNull(error); | ||
assertTrue(error instanceof DeploymentException); | ||
assertTrue(error.getMessage().contains("AmbiguousResolutionException: Ambiguous dependencies")); | ||
} | ||
|
||
@Singleton | ||
static class MyBean { | ||
|
||
@Inject | ||
FooInterface foo; | ||
} | ||
|
||
interface FooInterface { | ||
String ping(); | ||
} | ||
|
||
@ApplicationScoped | ||
@DefaultBean | ||
@Priority(10) | ||
static class FooImpl1 implements FooInterface { | ||
|
||
@Override | ||
public String ping() { | ||
return FooImpl1.class.getSimpleName(); | ||
} | ||
} | ||
|
||
@ApplicationScoped | ||
@DefaultBean | ||
@Priority(10) | ||
static class FooImpl2 implements FooInterface { | ||
|
||
@Override | ||
public String ping() { | ||
return FooImpl2.class.getSimpleName(); | ||
} | ||
} | ||
} |