Skip to content

Commit d66451c

Browse files
committed
#256 - Support the case of @factory @bean that needs to use fully qualified class name (short name clashes)
1 parent ddc5cbc commit d66451c

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.example.myapp.config;
2+
3+
import io.avaje.inject.Bean;
4+
import io.avaje.inject.Factory;
5+
6+
@Factory
7+
public class DupShortNameFactory {
8+
9+
@Bean
10+
MyDup one() {
11+
return new MyDup();
12+
}
13+
14+
/**
15+
* Requires fully qualified name as short name of MyDup clashes.
16+
*/
17+
@Bean
18+
org.example.myapp.config.MyDup two() {
19+
return new org.example.myapp.config.MyDup();
20+
}
21+
22+
public static class MyDup {
23+
24+
}
25+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package org.example.myapp.config;
2+
3+
public class MyDup {
4+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.example.myapp.config;
2+
3+
import io.avaje.inject.BeanScope;
4+
import org.junit.jupiter.api.Test;
5+
6+
import static org.assertj.core.api.Assertions.assertThat;
7+
import static org.junit.jupiter.api.Assertions.*;
8+
9+
class DupShortNameFactoryTest {
10+
11+
@Test
12+
void factoryBeanRequiringFullyQualifiedName() {
13+
try (BeanScope testScope = BeanScope.builder().build()) {
14+
// both have short name of MyDup
15+
var one = testScope.get(org.example.myapp.config.MyDup.class);
16+
var two = testScope.get(DupShortNameFactory.MyDup.class);
17+
18+
assertNotNull(one);
19+
assertNotNull(two);
20+
assertThat(one).isNotSameAs(two);
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)