-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 #42 from mkouba/issue-38
Arc - support initializer injection on superclasses
- Loading branch information
Showing
11 changed files
with
279 additions
and
94 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
128 changes: 73 additions & 55 deletions
128
ext/arc/processor/src/main/java/org/jboss/protean/arc/processor/BeanGenerator.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
import org.jboss.jandex.Type; | ||
|
||
/** | ||
* Represents an injection point. | ||
* | ||
* @author Martin Kouba | ||
*/ | ||
|
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
99 changes: 99 additions & 0 deletions
99
...rc/test/java/org/jboss/protean/arc/test/injection/superclass/SuperclassInjectionTest.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,99 @@ | ||
package org.jboss.protean.arc.test.injection.superclass; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.UUID; | ||
|
||
import javax.annotation.PostConstruct; | ||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.enterprise.context.Dependent; | ||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
|
||
import org.jboss.protean.arc.Arc; | ||
import org.jboss.protean.arc.test.ArcTestContainer; | ||
import org.jboss.protean.arc.test.injection.superclass.foo.FooHarvester; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
public class SuperclassInjectionTest { | ||
|
||
@Rule | ||
public ArcTestContainer container = new ArcTestContainer(Head.class, CombineHarvester.class, SuperCombineHarvester.class); | ||
|
||
@Test | ||
public void testSuperclassSamePackage() { | ||
CombineHarvester combineHarvester = Arc.container().instance(CombineHarvester.class).get(); | ||
assertNotNull(combineHarvester.getHead1()); | ||
assertNotNull(combineHarvester.getHead2()); | ||
assertNotEquals(combineHarvester.getHead1().id, combineHarvester.getHead2().id); | ||
} | ||
|
||
@Test | ||
public void testSuperclassDifferentPackage() { | ||
SuperCombineHarvester combineHarvester = Arc.container().instance(SuperCombineHarvester.class).get(); | ||
assertNotNull(combineHarvester.getHead1()); | ||
assertNotNull(combineHarvester.getHead2()); | ||
assertNotNull(combineHarvester.getHead3()); | ||
assertNotNull(combineHarvester.getHead4()); | ||
assertNotNull(combineHarvester.head5); | ||
Set<String> ids = new HashSet<>(); | ||
ids.add(combineHarvester.getHead1().id); | ||
ids.add(combineHarvester.getHead2().id); | ||
ids.add(combineHarvester.getHead3().id); | ||
ids.add(combineHarvester.getHead4().id); | ||
ids.add(combineHarvester.head5.id); | ||
assertEquals("Wrong number of ids: " + ids, 5, ids.size()); | ||
} | ||
|
||
@Dependent | ||
public static class Head { | ||
|
||
String id; | ||
|
||
@PostConstruct | ||
void init() { | ||
this.id = UUID.randomUUID().toString(); | ||
} | ||
|
||
} | ||
|
||
@Singleton | ||
static class SuperCombineHarvester extends FooHarvester { | ||
|
||
@Inject | ||
Head head5; | ||
|
||
} | ||
|
||
@ApplicationScoped | ||
static class CombineHarvester extends SuperHarvester { | ||
|
||
} | ||
|
||
public static class SuperHarvester { | ||
|
||
private Head head1; | ||
|
||
@Inject | ||
Head head2; | ||
|
||
@Inject | ||
void setHead(Head head) { | ||
this.head1 = head; | ||
} | ||
|
||
public Head getHead1() { | ||
return head1; | ||
} | ||
|
||
public Head getHead2() { | ||
return head2; | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.