@@ -60,20 +60,20 @@ class DefinitionsParser {
60
60
}
61
61
62
62
void parse (Class <?> source ) {
63
- parseElement (source );
64
- ReflectionUtils .doWithFields (source , this :: parseElement );
63
+ parseElement (source , null );
64
+ ReflectionUtils .doWithFields (source , ( element ) -> parseElement ( element , source ) );
65
65
}
66
66
67
- private void parseElement (AnnotatedElement element ) {
67
+ private void parseElement (AnnotatedElement element , Class <?> source ) {
68
68
MergedAnnotations annotations = MergedAnnotations .from (element , SearchStrategy .SUPERCLASS );
69
69
annotations .stream (MockBean .class ).map (MergedAnnotation ::synthesize )
70
- .forEach ((annotation ) -> parseMockBeanAnnotation (annotation , element ));
70
+ .forEach ((annotation ) -> parseMockBeanAnnotation (annotation , element , source ));
71
71
annotations .stream (SpyBean .class ).map (MergedAnnotation ::synthesize )
72
- .forEach ((annotation ) -> parseSpyBeanAnnotation (annotation , element ));
72
+ .forEach ((annotation ) -> parseSpyBeanAnnotation (annotation , element , source ));
73
73
}
74
74
75
- private void parseMockBeanAnnotation (MockBean annotation , AnnotatedElement element ) {
76
- Set <ResolvableType > typesToMock = getOrDeduceTypes (element , annotation .value ());
75
+ private void parseMockBeanAnnotation (MockBean annotation , AnnotatedElement element , Class <?> source ) {
76
+ Set <ResolvableType > typesToMock = getOrDeduceTypes (element , annotation .value (), source );
77
77
Assert .state (!typesToMock .isEmpty (), () -> "Unable to deduce type to mock from " + element );
78
78
if (StringUtils .hasLength (annotation .name ())) {
79
79
Assert .state (typesToMock .size () == 1 , "The name attribute can only be used when mocking a single class" );
@@ -86,8 +86,8 @@ private void parseMockBeanAnnotation(MockBean annotation, AnnotatedElement eleme
86
86
}
87
87
}
88
88
89
- private void parseSpyBeanAnnotation (SpyBean annotation , AnnotatedElement element ) {
90
- Set <ResolvableType > typesToSpy = getOrDeduceTypes (element , annotation .value ());
89
+ private void parseSpyBeanAnnotation (SpyBean annotation , AnnotatedElement element , Class <?> source ) {
90
+ Set <ResolvableType > typesToSpy = getOrDeduceTypes (element , annotation .value (), source );
91
91
Assert .state (!typesToSpy .isEmpty (), () -> "Unable to deduce type to spy from " + element );
92
92
if (StringUtils .hasLength (annotation .name ())) {
93
93
Assert .state (typesToSpy .size () == 1 , "The name attribute can only be used when spying a single class" );
@@ -108,13 +108,13 @@ private void addDefinition(AnnotatedElement element, Definition definition, Stri
108
108
}
109
109
}
110
110
111
- private Set <ResolvableType > getOrDeduceTypes (AnnotatedElement element , Class <?>[] value ) {
111
+ private Set <ResolvableType > getOrDeduceTypes (AnnotatedElement element , Class <?>[] value , Class <?> source ) {
112
112
Set <ResolvableType > types = new LinkedHashSet <>();
113
113
for (Class <?> clazz : value ) {
114
114
types .add (ResolvableType .forClass (clazz ));
115
115
}
116
116
if (types .isEmpty () && element instanceof Field ) {
117
- types .add (ResolvableType .forField ((Field ) element ));
117
+ types .add (ResolvableType .forField ((Field ) element , source ));
118
118
}
119
119
return types ;
120
120
}
0 commit comments