Skip to content

Commit 5751e36

Browse files
authored
Add test module blackbox-multi-scope (#797)
This is for testing out the multi-scope cases in a separate test module.
1 parent 13eaf2c commit 5751e36

File tree

17 files changed

+259
-0
lines changed

17 files changed

+259
-0
lines changed

blackbox-multi-scope/pom.xml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>io.avaje</groupId>
8+
<artifactId>avaje-inject-parent</artifactId>
9+
<version>11.5-RC1</version>
10+
</parent>
11+
12+
<artifactId>blackbox-multi-scope</artifactId>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>io.avaje</groupId>
17+
<artifactId>avaje-inject</artifactId>
18+
<version>${project.version}</version>
19+
</dependency>
20+
21+
<dependency>
22+
<groupId>io.avaje</groupId>
23+
<artifactId>avaje-inject-test</artifactId>
24+
<version>${project.version}</version>
25+
<scope>test</scope>
26+
</dependency>
27+
28+
<dependency>
29+
<groupId>io.avaje</groupId>
30+
<artifactId>junit</artifactId>
31+
<version>1.5</version>
32+
<scope>test</scope>
33+
</dependency>
34+
35+
</dependencies>
36+
37+
<build>
38+
<plugins>
39+
<plugin>
40+
<groupId>org.apache.maven.plugins</groupId>
41+
<artifactId>maven-compiler-plugin</artifactId>
42+
<configuration>
43+
<annotationProcessorPaths>
44+
<path>
45+
<groupId>io.avaje</groupId>
46+
<artifactId>avaje-inject-generator</artifactId>
47+
<version>${project.version}</version>
48+
</path>
49+
</annotationProcessorPaths>
50+
</configuration>
51+
</plugin>
52+
53+
<plugin>
54+
<groupId>io.avaje</groupId>
55+
<artifactId>avaje-inject-maven-plugin</artifactId>
56+
<version>${project.version}</version>
57+
<executions>
58+
<execution>
59+
<?m2e execute?>
60+
<phase>process-sources</phase>
61+
<goals>
62+
<goal>provides</goal>
63+
</goals>
64+
</execution>
65+
</executions>
66+
</plugin>
67+
</plugins>
68+
</build>
69+
</project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.multi.crosscut;
2+
3+
import org.multi.moda.BeanInModA;
4+
import org.multi.modb.BeanInModB;
5+
import org.multi.scope.CrossCutScope;
6+
7+
@CrossCutScope
8+
public class BeanCross{
9+
public BeanCross(final BeanInModA beanInModA, final BeanInModB beanInModB) {
10+
11+
}
12+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.multi.crosscut;
2+
3+
import org.multi.moda.BeanInModA;
4+
import org.multi.modb.BeanInModB;
5+
import org.multi.modc.modb.BeanInModC;
6+
import org.multi.scope.CrossCutScope;
7+
8+
@CrossCutScope
9+
public class BeanCross2 {
10+
public BeanCross2(final BeanInModA beanInModA, final BeanInModC beanInModC) {
11+
12+
}
13+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.multi.crosscut;
2+
3+
import org.multi.modc.modb.COther;
4+
import org.multi.scope.CrossCutScope;
5+
6+
@CrossCutScope
7+
public class BeanCross3 {
8+
public BeanCross3(final COther other) {
9+
10+
}
11+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.multi.main;
2+
3+
import io.avaje.inject.BeanScope;
4+
import org.multi.crosscut.BeanCross;
5+
import org.multi.crosscut.BeanCross2;
6+
import org.multi.crosscut.BeanCross3;
7+
import org.multi.crosscut.CrossCutModule;
8+
import org.multi.moda.BeanInModA;
9+
import org.multi.moda.ModAModule;
10+
import org.multi.modb.BeanInModB;
11+
import org.multi.modb.ModBModule;
12+
import org.multi.modc.modb.ModCModule;
13+
14+
public class CrossCutMain {
15+
16+
public static void main(String[] args) {
17+
try (BeanScope beanScope = buildScope()) {
18+
beanScope.get(BeanInModB.class);
19+
beanScope.get(BeanInModA.class);
20+
beanScope.get(BeanCross.class);
21+
beanScope.get(BeanCross2.class);
22+
beanScope.get(BeanCross3.class);
23+
}
24+
}
25+
26+
public static BeanScope buildScope() {
27+
return BeanScope.builder()
28+
.modules(new ModAModule(), new ModCModule(), new ModBModule(), new CrossCutModule())
29+
.build();
30+
}
31+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.multi.moda;
2+
3+
import org.multi.scope.ModAScope;
4+
5+
@ModAScope
6+
public class BeanInModA {
7+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.multi.modb;
2+
3+
import org.multi.modc.modb.COther;
4+
import org.multi.scope.ModBScope;
5+
6+
@ModBScope
7+
public class BOther {
8+
9+
private final COther cOther;
10+
11+
public BOther(COther cOther) {
12+
this.cOther = cOther;
13+
}
14+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.multi.modb;
2+
3+
import org.multi.scope.ModBScope;
4+
5+
@ModBScope
6+
public class BeanInModB {
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.multi.modc.modb;
2+
3+
import org.multi.scope.ModCScope;
4+
5+
@ModCScope
6+
public class BeanInModC {
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.multi.modc.modb;
2+
3+
import org.multi.scope.ModCScope;
4+
5+
@ModCScope
6+
public class COther {
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.multi.scope;
2+
3+
import io.avaje.inject.InjectModule;
4+
import jakarta.inject.Scope;
5+
import org.multi.modb.BeanInModB;
6+
7+
@Scope
8+
@InjectModule(requires = {ModAScope.class, ModBScope.class}, strictWiring = true)
9+
public @interface CrossCutScope {
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.multi.scope;
2+
3+
import io.avaje.inject.InjectModule;
4+
import jakarta.inject.Scope;
5+
6+
@Scope
7+
@InjectModule(strictWiring = true)
8+
public @interface ModAScope {
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.multi.scope;
2+
3+
import io.avaje.inject.InjectModule;
4+
import jakarta.inject.Scope;
5+
6+
@Scope
7+
@InjectModule(requires = ModCScope.class, strictWiring = true)
8+
public @interface ModBScope {
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.multi.scope;
2+
3+
import io.avaje.inject.InjectModule;
4+
import jakarta.inject.Scope;
5+
6+
@Scope
7+
@InjectModule(strictWiring = true)
8+
public @interface ModCScope {
9+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.multi.crosscut;
2+
3+
4+
import io.avaje.inject.BeanScope;
5+
import org.junit.jupiter.api.Test;
6+
import org.multi.modb.BeanInModB;
7+
8+
import static org.assertj.core.api.Assertions.assertThat;
9+
10+
class BeanCrossTest {
11+
12+
@Test
13+
void bootstrap() {
14+
15+
try (BeanScope beanScope = BeanScope.builder()
16+
// .modules(new CrossCutModule())
17+
.build()) {
18+
19+
// var beanInModB = beanScope.get(BeanInModB.class);
20+
// assertThat(beanInModB).isNotNull();
21+
}
22+
23+
}
24+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.multi.main;
2+
3+
import io.avaje.inject.BeanScope;
4+
import org.junit.jupiter.api.Test;
5+
import org.multi.crosscut.BeanCross;
6+
import org.multi.moda.BeanInModA;
7+
import org.multi.modb.BeanInModB;
8+
9+
class CrossCutMainTest {
10+
11+
@Test
12+
void buildScope() {
13+
try (BeanScope beanScope = CrossCutMain.buildScope()) {
14+
beanScope.get(BeanInModB.class);
15+
beanScope.get(BeanInModA.class);
16+
beanScope.get(BeanCross.class);
17+
}
18+
}
19+
}

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
<module>blackbox-other</module>
5454
<module>blackbox-aspect</module>
5555
<module>blackbox-test-inject</module>
56+
<module>blackbox-multi-scope</module>
5657
</modules>
5758
</profile>
5859
</profiles>

0 commit comments

Comments
 (0)