-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ArC: improve runtime representation of array bean types
Previously, we always used `GenericArrayType` to represent array bean types at runtime. This is unexpected for people, and also for at least one TCK test that expects a `java.lang.Class` representation of `String[]`. This commit makes sure that arrays of primitive types and simple class types are represented using an array-typed `java.lang.Class` object.
- Loading branch information
Showing
2 changed files
with
93 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...t-projects/arc/tests/src/test/java/io/quarkus/arc/test/bean/types/ArrayBeanTypesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package io.quarkus.arc.test.bean.types; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.lang.reflect.Type; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import javax.enterprise.context.Dependent; | ||
import javax.enterprise.inject.Produces; | ||
import javax.enterprise.inject.spi.Bean; | ||
import javax.enterprise.util.TypeLiteral; | ||
import javax.inject.Named; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.InjectableBean; | ||
import io.quarkus.arc.test.ArcTestContainer; | ||
|
||
public class ArrayBeanTypesTest { | ||
@RegisterExtension | ||
ArcTestContainer container = new ArcTestContainer(Producer.class); | ||
|
||
@Test | ||
public <T> void test() { | ||
InjectableBean<Object> intArray = Arc.container().instance("intArray").getBean(); | ||
assertBeanTypes(intArray, Object.class, int[][].class); | ||
|
||
InjectableBean<Object> stringArray = Arc.container().instance("stringArray").getBean(); | ||
assertBeanTypes(stringArray, Object.class, String[].class); | ||
|
||
InjectableBean<Object> listArray = Arc.container().instance("listArray").getBean(); | ||
assertBeanTypes(listArray, Object.class, new TypeLiteral<List<String>[]>() { | ||
}.getType()); | ||
} | ||
|
||
private void assertBeanTypes(Bean<?> bean, Type... expectedTypes) { | ||
Set<Type> types = bean.getTypes(); | ||
|
||
assertEquals(expectedTypes.length, types.size()); | ||
for (Type expectedType : expectedTypes) { | ||
assertTrue(types.contains(expectedType)); | ||
} | ||
} | ||
|
||
@Dependent | ||
static class Producer<T extends Number> { | ||
@Produces | ||
@Dependent | ||
@Named("intArray") | ||
int[][] intArray() { | ||
return new int[0][0]; | ||
} | ||
|
||
@Produces | ||
@Dependent | ||
@Named("stringArray") | ||
String[] stringArray() { | ||
return new String[0]; | ||
} | ||
|
||
@Produces | ||
@Dependent | ||
@Named("listArray") | ||
List<String>[] listArray() { | ||
return (List<String>[]) new List<?>[0]; | ||
} | ||
} | ||
} |