Skip to content

Commit 4b9e5e0

Browse files
committed
Add a test in blackbox-test-inject
1 parent 3406581 commit 4b9e5e0

File tree

4 files changed

+51
-7
lines changed

4 files changed

+51
-7
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.example.myapp.duplicate;
2+
3+
import jakarta.inject.Singleton;
4+
5+
@Singleton
6+
public class SameType {
7+
@Singleton
8+
public static class Inner {}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.example.myapp.duplicate.two;
2+
3+
import jakarta.inject.Singleton;
4+
5+
@Singleton
6+
public class SameType {
7+
@Singleton
8+
public static class Inner {}
9+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package org.example.myapp.duplicate;
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+
8+
9+
class SameTypeTest {
10+
11+
@Test
12+
void testDuplicateShortName() {
13+
try (BeanScope testScope = BeanScope.builder().build()) {
14+
15+
var sameType = testScope.get(SameType.class);
16+
var sameTypeInner = testScope.get(SameType.Inner.class);
17+
var sameType2 = testScope.get(org.example.myapp.duplicate.two.SameType.class);
18+
var sameType2Inner = testScope.get(org.example.myapp.duplicate.two.SameType.Inner.class);
19+
20+
assertThat(sameType).isNotNull();
21+
assertThat(sameTypeInner).isNotNull();
22+
assertThat(sameType2).isNotNull();
23+
assertThat(sameType2Inner).isNotNull();
24+
}
25+
}
26+
}

inject-generator/src/main/java/io/avaje/inject/generator/SimpleModuleWriter.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ final class SimpleModuleWriter {
6565
this.modulePackage = scopeInfo.modulePackage();
6666
this.shortName = scopeInfo.moduleShortName();
6767
this.fullName = scopeInfo.moduleFullName();
68-
Set<String> seen = new HashSet<>();
69-
duplicateTypes =
70-
ordering.ordered().stream()
71-
.map(MetaData::type)
72-
.filter(t -> !seen.add(ProcessorUtils.shortType(t)))
73-
.flatMap(t -> Stream.of(t, t + "$DI"))
74-
.collect(toSet());
68+
final Set<String> seen = new HashSet<>();
69+
this.duplicateTypes =
70+
ordering.ordered().stream()
71+
.map(MetaData::type)
72+
.filter(t -> !seen.add(ProcessorUtils.shortType(t)))
73+
.flatMap(t -> Stream.of(t, t + "$DI"))
74+
.collect(toSet());
7575
}
7676

7777
void write(ScopeInfo.Type scopeType) throws IOException {

0 commit comments

Comments
 (0)