Skip to content

Commit 2ce3d70

Browse files
committed
#39 - Support @factory methods returning void
1 parent 07a5b9d commit 2ce3d70

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
<dependency>
5757
<groupId>io.dinject</groupId>
5858
<artifactId>dinject-generator</artifactId>
59-
<version>1.18-SNAPSHOT</version>
59+
<version>1.18</version>
6060
<scope>test</scope>
6161
</dependency>
6262

src/test/java/org/example/coffee/factory/MyFactory.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
@Factory
1010
public class MyFactory {
1111

12+
String methods = "";
13+
1214
@Bean
1315
CFact buildCFact() {
1416
return new CFact();
@@ -30,4 +32,18 @@ Otherthing greenOther() {
3032
Otherthing yellowOther() {
3133
return () -> "yellow";
3234
}
35+
36+
@Bean
37+
void useCFact(CFact cfact) {
38+
methods +="|useCFact";
39+
}
40+
41+
@Bean
42+
void anotherCFact(CFact cfact) {
43+
methods +="|anotherCFact";
44+
}
45+
46+
String methodsCalled(){
47+
return methods;
48+
}
3349
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.example.coffee.factory;
2+
3+
import io.dinject.BeanContext;
4+
import io.dinject.BootContext;
5+
import org.junit.Test;
6+
7+
import static org.assertj.core.api.Assertions.assertThat;
8+
9+
public class MyFactoryTest {
10+
11+
@Test
12+
public void methodsCalled() {
13+
try (BeanContext context = new BootContext().load()) {
14+
final MyFactory myFactory = context.getBean(MyFactory.class);
15+
assertThat(myFactory.methodsCalled()).contains("|useCFact", "|anotherCFact");
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)