Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed minor bug in wildcard bound representation. Adapted toString.
- Loading branch information
Rafael Winterhalter
committed
May 28, 2015
1 parent
4484e36
commit b201098
Showing
6 changed files
with
127 additions
and
8 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
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
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
9 changes: 9 additions & 0 deletions
9
...dy-dep/src/test/java/net/bytebuddy/description/type/TypeDescriptionForLoadedTypeTest.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 |
---|---|---|
@@ -1,9 +1,18 @@ | ||
package net.bytebuddy.description.type; | ||
|
||
import net.bytebuddy.description.type.generic.GenericTypeDescription; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
public class TypeDescriptionForLoadedTypeTest extends AbstractTypeDescriptionTest { | ||
|
||
@Override | ||
protected TypeDescription describe(Class<?> type) { | ||
return new TypeDescription.ForLoadedType(type); | ||
} | ||
|
||
@Override | ||
protected GenericTypeDescription describe(Field field) { | ||
return GenericTypeDescription.Sort.describe(field.getGenericType()); | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
.../test/java/net/bytebuddy/description/type/generic/AbstractGenericTypeDescriptionTest.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,87 @@ | ||
package net.bytebuddy.description.type.generic; | ||
|
||
import org.junit.Test; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.List; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.CoreMatchers.nullValue; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
public abstract class AbstractGenericTypeDescriptionTest { | ||
|
||
private static final String FOO = "foo"; | ||
|
||
protected abstract GenericTypeDescription describe(Field field); | ||
|
||
@Test | ||
public void testSimpleParameterizedType() throws Exception { | ||
GenericTypeDescription genericTypeDescription = describe(SimpleParameterizedType.class.getDeclaredField(FOO)); | ||
assertThat(genericTypeDescription.getSort(), is(GenericTypeDescription.Sort.PARAMETERIZED)); | ||
assertThat(genericTypeDescription.getParameters().size(), is(1)); | ||
assertThat(genericTypeDescription.getParameters().getOnly().getSort(), is(GenericTypeDescription.Sort.RAW)); | ||
assertThat(genericTypeDescription.getParameters().getOnly().asRawType().represents(String.class), is(true)); | ||
assertThat(genericTypeDescription.getTypeName(), is(SimpleParameterizedType.class.getDeclaredField(FOO).getGenericType().toString())); | ||
assertThat(genericTypeDescription.getComponentType(), nullValue(GenericTypeDescription.class)); | ||
assertThat(genericTypeDescription.getOwnerType(), nullValue(GenericTypeDescription.class)); | ||
assertThat(genericTypeDescription.getVariableSource(), nullValue(TypeVariableSource.class)); | ||
assertThat(genericTypeDescription.getSymbol(), nullValue(String.class)); | ||
assertThat(genericTypeDescription.getLowerBounds().size(), is(0)); | ||
assertThat(genericTypeDescription.getUpperBounds().size(), is(0)); | ||
} | ||
|
||
@Test | ||
public void testUpperBoundWildcardParameterizedType() throws Exception { | ||
GenericTypeDescription genericTypeDescription = describe(UpperBoundWildcardParameterizedType.class.getDeclaredField(FOO)); | ||
assertThat(genericTypeDescription.getSort(), is(GenericTypeDescription.Sort.PARAMETERIZED)); | ||
assertThat(genericTypeDescription.getParameters().size(), is(1)); | ||
assertThat(genericTypeDescription.getParameters().getOnly().getSort(), is(GenericTypeDescription.Sort.WILDCARD)); | ||
assertThat(genericTypeDescription.getParameters().getOnly().asRawType().represents(String.class), is(true)); | ||
assertThat(genericTypeDescription.getParameters().getOnly().getUpperBounds().size(), is(1)); | ||
assertThat(genericTypeDescription.getParameters().getOnly().getUpperBounds().getOnly().getSort(), is(GenericTypeDescription.Sort.RAW)); | ||
assertThat(genericTypeDescription.getParameters().getOnly().getUpperBounds().getOnly().asRawType().represents(String.class), is(true)); | ||
assertThat(genericTypeDescription.getParameters().getOnly().getLowerBounds().size(), is(0)); | ||
assertThat(genericTypeDescription.getTypeName(), is(UpperBoundWildcardParameterizedType.class.getDeclaredField(FOO).getGenericType().toString())); | ||
assertThat(genericTypeDescription.getComponentType(), nullValue(GenericTypeDescription.class)); | ||
assertThat(genericTypeDescription.getOwnerType(), nullValue(GenericTypeDescription.class)); | ||
assertThat(genericTypeDescription.getVariableSource(), nullValue(TypeVariableSource.class)); | ||
assertThat(genericTypeDescription.getSymbol(), nullValue(String.class)); | ||
assertThat(genericTypeDescription.getLowerBounds().size(), is(0)); | ||
assertThat(genericTypeDescription.getUpperBounds().size(), is(0)); | ||
} | ||
|
||
@Test | ||
public void testLowerBoundWildcardParameterizedType() throws Exception { | ||
GenericTypeDescription genericTypeDescription = describe(LowerBoundWildcardParameterizedType.class.getDeclaredField(FOO)); | ||
assertThat(genericTypeDescription.getSort(), is(GenericTypeDescription.Sort.PARAMETERIZED)); | ||
assertThat(genericTypeDescription.getParameters().size(), is(1)); | ||
assertThat(genericTypeDescription.getParameters().getOnly().getSort(), is(GenericTypeDescription.Sort.WILDCARD)); | ||
assertThat(genericTypeDescription.getParameters().getOnly().asRawType().represents(Object.class), is(true)); | ||
assertThat(genericTypeDescription.getParameters().getOnly().getUpperBounds().size(), is(1)); | ||
assertThat(genericTypeDescription.getParameters().getOnly().getUpperBounds().getOnly().getSort(), is(GenericTypeDescription.Sort.RAW)); | ||
assertThat(genericTypeDescription.getParameters().getOnly().getUpperBounds().getOnly().asRawType().represents(Object.class), is(true)); | ||
assertThat(genericTypeDescription.getParameters().getOnly().getLowerBounds().size(), is(1)); | ||
assertThat(genericTypeDescription.getParameters().getOnly().getLowerBounds().getOnly().getSort(), is(GenericTypeDescription.Sort.RAW)); | ||
assertThat(genericTypeDescription.getParameters().getOnly().getLowerBounds().getOnly().asRawType().represents(String.class), is(true)); | ||
assertThat(genericTypeDescription.getTypeName(), is(LowerBoundWildcardParameterizedType.class.getDeclaredField(FOO).getGenericType().toString())); | ||
assertThat(genericTypeDescription.getComponentType(), nullValue(GenericTypeDescription.class)); | ||
assertThat(genericTypeDescription.getOwnerType(), nullValue(GenericTypeDescription.class)); | ||
assertThat(genericTypeDescription.getVariableSource(), nullValue(TypeVariableSource.class)); | ||
assertThat(genericTypeDescription.getSymbol(), nullValue(String.class)); | ||
assertThat(genericTypeDescription.getLowerBounds().size(), is(0)); | ||
assertThat(genericTypeDescription.getUpperBounds().size(), is(0)); | ||
} | ||
|
||
public static class SimpleParameterizedType { | ||
List<String> foo; | ||
} | ||
|
||
public static class UpperBoundWildcardParameterizedType { | ||
List<? extends String> foo; | ||
} | ||
|
||
public static class LowerBoundWildcardParameterizedType { | ||
List<? super String> foo; | ||
} | ||
} |
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