File tree Expand file tree Collapse file tree 5 files changed +51
-11
lines changed
main/java/io/avaje/inject/test
test/java/org/example/inherit Expand file tree Collapse file tree 5 files changed +51
-11
lines changed Original file line number Diff line number Diff line change 12
12
/**
13
13
* Holds the global BeanScope used for all tests.
14
14
*/
15
- final class GlobalTestScope implements ExtensionContext .Store .CloseableResource {
15
+ final class GlobalTestScope implements ExtensionContext .Store .CloseableResource {
16
16
17
17
private static final System .Logger log = AppLog .getLogger ("io.avaje.inject" );
18
18
Original file line number Diff line number Diff line change 17
17
import java .lang .reflect .Modifier ;
18
18
import java .lang .reflect .Type ;
19
19
import java .util .ArrayList ;
20
+ import java .util .LinkedList ;
20
21
import java .util .List ;
21
22
22
23
final class MetaReader {
@@ -38,10 +39,23 @@ final class MetaReader {
38
39
39
40
MetaReader (Class <?> testClass , Plugin plugin ) {
40
41
this .plugin = plugin ;
41
- this .methodFinder = new SetupMethods (testClass );
42
- for (Field field : testClass .getDeclaredFields ()) {
43
- readField (field );
42
+ final var hierarchy = typeHierarchy (testClass );
43
+ this .methodFinder = new SetupMethods (hierarchy );
44
+ for (Class <?> aTestClass : hierarchy ) {
45
+ for (Field field : aTestClass .getDeclaredFields ()) {
46
+ readField (field );
47
+ }
48
+ }
49
+ }
50
+
51
+ private static LinkedList <Class <?>> typeHierarchy (Class <?> testClass ) {
52
+ var hierarchy = new LinkedList <Class <?>>();
53
+ var analyzedClass = testClass ;
54
+ while (analyzedClass != null && !analyzedClass .equals (Object .class )) {
55
+ hierarchy .addFirst (analyzedClass );
56
+ analyzedClass = analyzedClass .getSuperclass ();
44
57
}
58
+ return hierarchy ;
45
59
}
46
60
47
61
boolean hasClassInjection () {
Original file line number Diff line number Diff line change @@ -14,13 +14,7 @@ final class SetupMethods {
14
14
private final List <Method > staticMethods = new ArrayList <>();
15
15
private final List <Method > instanceMethods = new ArrayList <>();
16
16
17
- SetupMethods (Class <?> testClass ) {
18
- var analyzedClass = testClass ;
19
- var hierarchy = new LinkedList <Class <?>>();
20
- while (analyzedClass != null && !analyzedClass .equals (Object .class )) {
21
- hierarchy .addFirst (analyzedClass );
22
- analyzedClass = analyzedClass .getSuperclass ();
23
- }
17
+ SetupMethods (LinkedList <Class <?>> hierarchy ) {
24
18
for (Class <?> aClass : hierarchy ) {
25
19
for (Method method : aClass .getDeclaredMethods ()) {
26
20
if (method .getDeclaredAnnotation (Setup .class ) != null ) {
Original file line number Diff line number Diff line change
1
+ package org .example .inherit ;
2
+
3
+ import jakarta .inject .Inject ;
4
+ import org .example .coffee .core .Steamer ;
5
+
6
+ public abstract class MyOneAbstract {
7
+
8
+ @ Inject
9
+ Steamer steamer ;
10
+ }
Original file line number Diff line number Diff line change
1
+ package org .example .inherit ;
2
+
3
+ import io .avaje .inject .test .InjectExtension ;
4
+ import jakarta .inject .Inject ;
5
+ import org .example .inherit .notpublic .PubExposed ;
6
+ import org .junit .jupiter .api .Test ;
7
+ import org .junit .jupiter .api .extension .ExtendWith ;
8
+
9
+ import static org .assertj .core .api .Assertions .assertThat ;
10
+
11
+ @ ExtendWith (InjectExtension .class )
12
+ public class MyOneTest extends MyOneAbstract {
13
+
14
+ @ Inject
15
+ PubExposed something ;
16
+
17
+ @ Test
18
+ void test_expect_inheritedFieldIsInjected () {
19
+ assertThat (something ).isNotNull ();
20
+ assertThat (steamer ).isNotNull ();
21
+ }
22
+ }
You can’t perform that action at this time.
0 commit comments