Skip to content

Commit 43fce85

Browse files
committed
#433 followup - Add test and update style on BeanReader
1 parent dfeea2b commit 43fce85

File tree

3 files changed

+26
-23
lines changed

3 files changed

+26
-23
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.example.myapp.conditional;
2+
3+
import io.avaje.inject.Component;
4+
import io.avaje.inject.RequiresProperty;
5+
import org.example.myapp.aspect.MyAround;
6+
7+
@Component
8+
@RequiresProperty(value = "factory")
9+
public class WithAspectConditional {
10+
11+
@MyAround
12+
void test(String str) {
13+
// does nothing
14+
}
15+
}

blackbox-test-inject/src/test/java/org/example/myapp/conditional/ConditionalTests.java

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class ConditionalTests {
2121

2222
@BeforeEach
2323
void clearConfig() {
24-
2524
Config.eventBuilder("")
2625
.remove("secondary")
2726
.remove("factory")
@@ -32,15 +31,14 @@ void clearConfig() {
3231
}
3332

3433
@Test
35-
void basic() throws IOException {
34+
void basic() {
3635
// just wire everything with no test scope, mocks etc
3736
final BeanScope beanScope = BeanScope.builder().build();
3837
assertTrue(beanScope.getOptional(Bird.class).isEmpty());
3938
}
4039

4140
@Test
42-
void jay() throws IOException {
43-
41+
void jay() {
4442
Config.setProperty("factory", "bird");
4543

4644
final BeanScope beanScope = BeanScope.builder().build();
@@ -51,8 +49,7 @@ void jay() throws IOException {
5149
}
5250

5351
@Test
54-
void birdWatch() throws IOException {
55-
52+
void birdWatch() {
5653
Config.setProperty("factory", "bird");
5754
Config.setProperty("watcher", "bird");
5855

@@ -62,8 +59,7 @@ void birdWatch() throws IOException {
6259
}
6360

6461
@Test
65-
void missingBeans() throws IOException {
66-
62+
void missingBeans() {
6763
Config.setProperty("watcher", "bird");
6864

6965
final BeanScope beanScope = BeanScope.builder().build();
@@ -72,34 +68,33 @@ void missingBeans() throws IOException {
7268
}
7369

7470
@Test
75-
void noFactory() throws IOException {
76-
71+
void noFactory() {
7772
Config.setProperty("kiwi", "somethin");
7873
Config.setProperty("watcher", "bird");
7974

8075
final BeanScope beanScope = BeanScope.builder().build();
8176

77+
assertTrue(beanScope.getOptional(WithAspectConditional.class).isEmpty());
8278
assertTrue(beanScope.getOptional(BirdFactory.class).isEmpty());
8379
assertTrue(beanScope.getOptional(BlueJay.class).isEmpty());
8480
assertTrue(beanScope.getOptional(BirdWatcher.class).isPresent());
8581
assertEquals("Kiwi", beanScope.get(Bird.class).toString());
8682
}
8783

8884
@Test
89-
void factoryKiwiOverride() throws IOException {
90-
85+
void factoryKiwiOverride() {
9186
Config.setProperty("kiwi", "somethin");
9287
Config.setProperty("factory", "bird");
9388
Config.setProperty("watcher", "bird");
9489

9590
final BeanScope beanScope = BeanScope.builder().build();
9691
assertTrue(beanScope.getOptional(BirdWatcher.class).isPresent());
92+
assertTrue(beanScope.getOptional(WithAspectConditional.class).isPresent());
9793
assertEquals("Kiwi", beanScope.get(Bird.class).toString());
9894
}
9995

10096
@Test
101-
void factorySecondaryOverride() throws IOException {
102-
97+
void factorySecondaryOverride() {
10398
Config.setProperty("secondary", "somethin");
10499
Config.setProperty("factory", "bird");
105100
Config.setProperty("watcher", "bird");
@@ -110,16 +105,14 @@ void factorySecondaryOverride() throws IOException {
110105
}
111106

112107
@Test
113-
void qualifierTest() throws IOException {
114-
108+
void qualifierTest() {
115109
final BeanScope beanScope =
116110
BeanScope.builder().bean("finch", Bird.class, new StrawberryFinch()).build();
117111
assertTrue(beanScope.getOptional(QualifiedBirdWatcher.class).isPresent());
118112
}
119113

120114
@Test
121-
void metaMetaAnnotationTest() throws IOException {
122-
115+
void metaMetaAnnotationTest() {
123116
Config.setProperty("finch-time", "somethin");
124117
Config.setProperty("factory", "bird");
125118
Config.setProperty("watcher", "bird");

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,14 @@ final class BeanReader {
6161
this.importedComponent = importedComponent && (constructor != null && constructor.isPublic());
6262

6363
var proxyPrism = ProxyPrism.getInstanceOn(beanType);
64-
6564
if (proxyPrism != null) {
6665
this.proxy = true;
6766
var proxyMirror = proxyPrism.value();
68-
6967
if (!"Void".equals(proxyMirror.toString())) {
70-
7168
conditions.readAll(APContext.asTypeElement(proxyMirror));
7269
}
7370
} else {
74-
7571
conditions.readAll(beanType);
76-
7772
this.proxy = false;
7873
}
7974
}

0 commit comments

Comments
 (0)