-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix class scanning forcing classes as beans
Resolves #77.
- Loading branch information
Showing
6 changed files
with
177 additions
and
29 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
38 changes: 38 additions & 0 deletions
38
junit5/src/test/java/org/jboss/weld/junit5/auto/ProducerMethodParametersScanningTest.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,38 @@ | ||
package org.jboss.weld.junit5.auto; | ||
|
||
import org.jboss.weld.junit5.auto.beans.Engine; | ||
import org.jboss.weld.junit5.auto.beans.V6; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import javax.enterprise.context.Dependent; | ||
import javax.enterprise.inject.Produces; | ||
import javax.inject.Named; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
@EnableAutoWeld | ||
public class ProducerMethodParametersScanningTest { | ||
|
||
@Produces | ||
@Named("custom") | ||
@Dependent | ||
Engine getEngine(V6 v6) { | ||
return new Engine() { | ||
@Override | ||
public int getThrottle() { | ||
return v6.getThrottle(); | ||
} | ||
|
||
@Override | ||
public void setThrottle(int value) { | ||
v6.setThrottle(value); | ||
} | ||
}; | ||
} | ||
|
||
@Test | ||
public void test(@Named("custom") Engine engine) { | ||
assertNotNull(engine); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
junit5/src/test/java/org/jboss/weld/junit5/auto/ScannedClassesAreNotForcedBeansTest.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 org.jboss.weld.junit5.auto; | ||
|
||
|
||
import org.jboss.weld.junit5.auto.beans.InjectedV8; | ||
import org.jboss.weld.junit5.auto.beans.V8; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import javax.enterprise.inject.Produces; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
|
||
@EnableAutoWeld | ||
@AddBeanClasses(InjectedV8.class) | ||
public class ScannedClassesAreNotForcedBeansTest { | ||
|
||
/** | ||
* V8 is *not* a "bean" class, in that it has no bean defining annotation. To satisfy | ||
* a dependency on it, a producer method or a reference in an @AddBeanClasses annotation | ||
* is required. | ||
* <p> | ||
* This test ensures that as V8 is discovered via class scanning it is not automatically | ||
* added as a bean class. If it was added that way, the bean class and producer method would | ||
* create an ambiguous injection case for V8. | ||
* | ||
* NOTE: This case only tests for classes found as non-parameters (e.g. injected fields) | ||
*/ | ||
|
||
@Produces | ||
private V8 engine = new V8(); | ||
|
||
@Test | ||
@DisplayName("Test that V8 is not ambiguous to do incorrectly being identified as a bean class") | ||
void test(V8 engine) { | ||
assertNotNull(engine); | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
...rc/test/java/org/jboss/weld/junit5/auto/ScannedParameterClassesAreNotForcedBeansTest.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,40 @@ | ||
package org.jboss.weld.junit5.auto; | ||
|
||
|
||
import org.jboss.weld.junit5.auto.beans.ConstructedV8; | ||
import org.jboss.weld.junit5.auto.beans.V8; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import javax.enterprise.inject.Produces; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
|
||
@EnableAutoWeld | ||
@AddBeanClasses(ConstructedV8.class) | ||
public class ScannedParameterClassesAreNotForcedBeansTest { | ||
|
||
/** | ||
* V8 is *not* a "bean" class, in that it has no bean defining annotation. To satisfy | ||
* a dependency on it, a producer method or a reference in an @AddBeanClasses annotation | ||
* is required. | ||
* <p> | ||
* This test ensures that as V8 is discovered via class scanning it is not automatically | ||
* added as a bean class. If it was added that way, the bean class and producer method would | ||
* create an ambiguous injection case for V8. | ||
* | ||
* NOTE: This case only tests for classes found from parameters (e.g. constructor injection | ||
* parameters) | ||
*/ | ||
|
||
@Produces | ||
private V8 engine = new V8(); | ||
|
||
@Test | ||
@DisplayName("Test that V8 is not ambiguous to do incorrectly being identified as a bean class from parameter") | ||
void test(V8 engine) { | ||
assertNotNull(engine); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
junit5/src/test/java/org/jboss/weld/junit5/auto/beans/ConstructedV8.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,16 @@ | ||
package org.jboss.weld.junit5.auto.beans; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
|
||
@ApplicationScoped | ||
public class ConstructedV8 { | ||
|
||
private V8 engine; | ||
|
||
@Inject | ||
public ConstructedV8(V8 engine) { | ||
this.engine = engine; | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
junit5/src/test/java/org/jboss/weld/junit5/auto/beans/InjectedV8.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,12 @@ | ||
package org.jboss.weld.junit5.auto.beans; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
|
||
@ApplicationScoped | ||
public class InjectedV8 { | ||
|
||
@Inject | ||
private V8 engine; | ||
|
||
} |