|
1 | 1 | package io.avaje.inject.test;
|
2 | 2 |
|
3 |
| -import io.avaje.inject.BeanScope; |
4 |
| -import io.avaje.inject.BeanScopeBuilder; |
5 |
| -import jakarta.inject.Inject; |
6 |
| -import jakarta.inject.Named; |
7 |
| -import jakarta.inject.Qualifier; |
8 |
| -import org.mockito.ArgumentCaptor; |
9 |
| -import org.mockito.Captor; |
10 |
| -import org.mockito.Mock; |
11 |
| -import org.mockito.Spy; |
12 |
| -import org.mockito.internal.configuration.plugins.Plugins; |
13 |
| -import org.mockito.internal.util.reflection.GenericMaster; |
14 |
| - |
15 | 3 | import java.lang.annotation.Annotation;
|
16 | 4 | import java.lang.reflect.Field;
|
17 | 5 | import java.lang.reflect.Modifier;
|
| 6 | +import java.lang.reflect.ParameterizedType; |
18 | 7 | import java.lang.reflect.Type;
|
19 | 8 | import java.util.ArrayList;
|
20 | 9 | import java.util.LinkedList;
|
21 | 10 | import java.util.List;
|
| 11 | +import java.util.Optional; |
| 12 | + |
| 13 | +import org.mockito.ArgumentCaptor; |
| 14 | +import org.mockito.Captor; |
| 15 | +import org.mockito.Mock; |
| 16 | +import org.mockito.Spy; |
| 17 | +import org.mockito.internal.configuration.plugins.Plugins; |
| 18 | +import org.mockito.internal.util.reflection.GenericMaster; |
| 19 | + |
| 20 | +import io.avaje.inject.BeanScope; |
| 21 | +import io.avaje.inject.BeanScopeBuilder; |
| 22 | +import jakarta.inject.Inject; |
| 23 | +import jakarta.inject.Named; |
| 24 | +import jakarta.inject.Qualifier; |
22 | 25 |
|
23 | 26 | final class MetaReader {
|
24 | 27 |
|
@@ -349,9 +352,28 @@ Object get(Object instance) {
|
349 | 352 | }
|
350 | 353 |
|
351 | 354 | void setFromScope(BeanScope beanScope, Object testInstance) throws IllegalAccessException {
|
352 |
| - if (!valueAlreadyProvided) { |
353 |
| - set(field, beanScope.get(type(), name), testInstance); |
| 355 | + if (valueAlreadyProvided) { |
| 356 | + return; |
| 357 | + } |
| 358 | + final var type = type(); |
| 359 | + |
| 360 | + if (type instanceof ParameterizedType) { |
| 361 | + final var parameterizedType = (ParameterizedType) type; |
| 362 | + final var rawType = parameterizedType.getRawType(); |
| 363 | + final var typeArguments = parameterizedType.getActualTypeArguments(); |
| 364 | + |
| 365 | + if (rawType.equals(List.class)) { |
| 366 | + set(field, beanScope.list(typeArguments[0]), testInstance); |
| 367 | + return; |
| 368 | + } |
| 369 | + |
| 370 | + if (rawType.equals(Optional.class)) { |
| 371 | + set(field, beanScope.getOptional(typeArguments[0], name), testInstance); |
| 372 | + return; |
| 373 | + } |
354 | 374 | }
|
| 375 | + |
| 376 | + set(field, beanScope.get(type, name), testInstance); |
355 | 377 | }
|
356 | 378 |
|
357 | 379 | void setFromPlugin(Object value, Object testInstance) throws IllegalAccessException {
|
|
0 commit comments