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#3133 from mkouba/issue-3126-bean-constru…
…ctor Arc - fix constructor injection
- Loading branch information
Showing
5 changed files
with
138 additions
and
33 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
50 changes: 50 additions & 0 deletions
50
.../io/quarkus/arc/test/injection/constructornoinject/MultiInjectConstructorFailureTest.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,50 @@ | ||
package io.quarkus.arc.test.injection.constructornoinject; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import io.quarkus.arc.test.ArcTestContainer; | ||
import javax.enterprise.context.Dependent; | ||
import javax.enterprise.inject.spi.DefinitionException; | ||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
public class MultiInjectConstructorFailureTest { | ||
|
||
@Rule | ||
public ArcTestContainer container = ArcTestContainer.builder() | ||
.beanClasses(CombineHarvester.class, Head.class) | ||
.shouldFail() | ||
.build(); | ||
|
||
@Test | ||
public void testInjection() { | ||
Throwable error = container.getFailure(); | ||
assertNotNull(error); | ||
assertTrue(error instanceof DefinitionException); | ||
} | ||
|
||
@Dependent | ||
static class Head { | ||
|
||
} | ||
|
||
@Singleton | ||
static class CombineHarvester { | ||
|
||
Head head; | ||
|
||
@Inject | ||
public CombineHarvester() { | ||
this.head = null; | ||
} | ||
|
||
@Inject | ||
public CombineHarvester(Head head) { | ||
this.head = head; | ||
} | ||
|
||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...o/quarkus/arc/test/injection/constructornoinject/NoArgConstructorTakesPrecedenceTest.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,39 @@ | ||
package io.quarkus.arc.test.injection.constructornoinject; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.test.ArcTestContainer; | ||
import javax.inject.Singleton; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
public class NoArgConstructorTakesPrecedenceTest { | ||
|
||
@Rule | ||
public ArcTestContainer container = new ArcTestContainer(CombineHarvester.class); | ||
|
||
@Test | ||
public void testInjection() { | ||
assertEquals("OK", Arc.container().instance(CombineHarvester.class).get().getHead()); | ||
} | ||
|
||
@Singleton | ||
static class CombineHarvester { | ||
|
||
private String head; | ||
|
||
public CombineHarvester() { | ||
this.head = "OK"; | ||
} | ||
|
||
public CombineHarvester(String head) { | ||
this.head = head; | ||
} | ||
|
||
public String getHead() { | ||
return head; | ||
} | ||
|
||
} | ||
} |
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