Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WELD-1132 TypeVariableResolverTest.testVariableArray() test is failing on JDK7 #197

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,5 +1,6 @@
package org.jboss.weld.util.reflection;

import java.lang.reflect.Array;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
Expand Down Expand Up @@ -37,7 +38,13 @@ public Type resolveVariablesInType(Type type) {
return resolveTypeVariable(typeVariable);
} else if (type instanceof GenericArrayType) {
GenericArrayType genericArrayType = (GenericArrayType) type;
return new GenericArrayTypeImpl(resolveVariablesInType(genericArrayType.getGenericComponentType()));
Type resolvedComponentType = resolveVariablesInType(genericArrayType.getGenericComponentType());
if (resolvedComponentType instanceof Class) {
Class componentClass = (Class) resolvedComponentType;
return Array.newInstance(componentClass, 0).getClass();
} else {
return new GenericArrayTypeImpl(resolvedComponentType);
}
} else {
return type;
}
Expand Down
Expand Up @@ -23,5 +23,7 @@ public class A<E1, E2> {

private E1[] variableArray;

private E1[][] twoDimensionalVariableArray;

private Foo<E1>[] foo1Array;
}
@@ -1,13 +1,13 @@
package org.jboss.weld.tests.unit.reflection.inheritance;

import org.jboss.weld.util.reflection.TypeVariableResolver;
import org.junit.Test;
import org.testng.Assert;
import org.testng.annotations.Test;

import javax.enterprise.util.TypeLiteral;
import java.lang.reflect.Field;
import java.lang.reflect.Type;

import static junit.framework.Assert.assertEquals;

/**
* @author <a href="mailto:marko.luksa@gmail.com">Marko Luksa</a>
Expand Down Expand Up @@ -56,7 +56,12 @@ public void testStringFooArray() throws Exception {

@Test
public void testVariableArray() throws Exception {
assertTypeEquals(new TypeLiteral<Integer[]>() {}, BOfIntegerString.class, A.class.getDeclaredField("variableArray"));
assertTypeEquals(Integer[].class, BOfIntegerString.class, A.class.getDeclaredField("variableArray"));
}

@Test
public void testTwoDimensionalVariableArray() throws Exception {
assertTypeEquals(Integer[][].class, BOfIntegerString.class, A.class.getDeclaredField("twoDimensionalVariableArray"));
}

@Test
Expand All @@ -75,9 +80,12 @@ public void testSuperSuperSuperClass() throws Exception {
}

private void assertTypeEquals(TypeLiteral<?> expectedTypeLiteral, Class beanClass, Field field) {
Type expectedType = expectedTypeLiteral.getType();
assertTypeEquals(expectedTypeLiteral.getType(), beanClass, field);
}

private void assertTypeEquals(Type expectedType, Class beanClass, Field field) {
Type type = new TypeVariableResolver(beanClass).resolveVariablesInType(field.getGenericType());
assertEquals(expectedType, type);
Assert.assertEquals(type, expectedType);
}

}