Methods Summary |
---|
private static void | assertContainsTypeVariable(java.lang.reflect.Type type)
assertTrue(type.toString() + " was expected to have a type variable, but it didn't",
containsTypeVariable(type));
|
private static void | assertLacksTypeVariable(java.lang.reflect.Type type)
assertFalse(type.toString() + " was expected to *not* have a type variable, but it did",
containsTypeVariable(type));
|
private static void | assertRawTypeEquals(android.hardware.camera2.utils.TypeReference typeRef, java.lang.Class rawClass)
assertEquals("Expected the raw type from " + typeRef + " to match the class " + rawClass,
rawClass, typeRef.getRawType());
|
private static void | assertTypeReferenceEquals(android.hardware.camera2.utils.TypeReference typeRef, java.lang.Class klass)
assertEquals("Expected the type from " + typeRef + " to match the class " + klass,
klass, typeRef.getType());
|
private static android.hardware.camera2.utils.TypeReference | createTypeRefWithTypeVar()This should always throw an IllegalArgumentException since the
type reference to {@code T} will contain a type variable (also {@code T}).
return new TypeReference<T>() {{ }};
|
public void | testComponentType()
// Not an array. component type should be null.
TypeReference<Integer> intToken = new TypeReference<Integer>() {{ }};
assertNull(intToken.getComponentType());
TypeReference<List<Integer>> listToken = new TypeReference<List<Integer>>() {{ }};
assertNull(listToken.getComponentType());
TypeReference<List<List<Integer>>> listListToken =
new TypeReference<List<List<Integer>>>() {{ }};
assertNull(listListToken.getComponentType());
// Check arrays. Component types should be what we expect.
TypeReference<int[]> intArrayToken = new TypeReference<int[]>() {{ }};
assertTypeReferenceEquals(intArrayToken.getComponentType(), int.class);
TypeReference<Integer[]> integerArrayToken = new TypeReference<Integer[]>() {{ }};
assertTypeReferenceEquals(integerArrayToken.getComponentType(), Integer.class);
assertEquals(new IntArrayToken1().getComponentType(),
new IntArrayToken2().getComponentType());
assertEquals(new IntListArrayToken1().getComponentType(),
new IntListArrayToken2().getComponentType());
// FIXME: Equality will fail: b/14590652
TypeReference<List<Integer>[]> listArrayToken = new TypeReference<List<Integer>[]>() {{ }};
assertEquals(listToken, listArrayToken.getComponentType());
|
public void | testContainsTypeVariables()
assertContainsTypeVariable(GenericClass.class);
assertContainsTypeVariable(SubGenericClass.class);
assertContainsTypeVariable(GenericInterface.class);
assertContainsTypeVariable(ImplementsGenericInterface.class);
assertContainsTypeVariable(Implements2GenericInterface.class);
assertContainsTypeVariable(GenericOuterClass.class);
assertContainsTypeVariable(GenericOuterClass.GenericInnerClass.class);
|
public void | testEquals()
// Not an array. component type should be null.
TypeReference<Integer> intToken = new TypeReference<Integer>() {{ }};
assertEquals(intToken, intToken);
assertEquals(intToken, new TypeReference<Integer>() {{ }});
assertEquals(intToken, new IntTokenOne());
assertEquals(intToken, new IntTokenTwo());
assertEquals(new IntTokenOne(), new IntTokenTwo());
assertEquals(new IntArrayToken1(), new IntArrayToken2());
assertEquals(new IntListToken1(), new IntListToken2());
assertEquals(new IntListArrayToken1(), new IntListArrayToken2());
|
public void | testLacksTypeVariables()
assertLacksTypeVariable(RegularClass.class);
assertLacksTypeVariable(SubClass.class);
assertLacksTypeVariable(SpecificClass.class);
assertLacksTypeVariable(RegularInterface.class);
assertLacksTypeVariable(ImplementsRegularInterface.class);
|
public void | testRawTypes()
TypeReference<Integer> intToken = new TypeReference<Integer>() {{ }};
assertRawTypeEquals(intToken, Integer.class);
TypeReference<List<Integer>> listToken = new TypeReference<List<Integer>>() {{ }};
assertRawTypeEquals(listToken, List.class);
TypeReference<List<List<Integer>>> listListToken =
new TypeReference<List<List<Integer>>>() {{ }};
assertRawTypeEquals(listListToken, List.class);
TypeReference<int[]> intArrayToken = new TypeReference<int[]>() {{ }};
assertRawTypeEquals(intArrayToken, int[].class);
TypeReference<Integer[]> integerArrayToken = new TypeReference<Integer[]>() {{ }};
assertRawTypeEquals(integerArrayToken, Integer[].class);
TypeReference<List<Integer>[]> listArrayToken = new TypeReference<List<Integer>[]>() {{ }};
assertRawTypeEquals(listArrayToken, List[].class);
|
public void | testTypeReferences()
TypeReference<Integer> typeRefInt = new TypeReference<Integer>() {{ }};
TypeReference<Integer> typeRefInt2 = new TypeReference<Integer>() {{ }};
assertEquals(typeRefInt, typeRefInt2);
assertEquals("The type ref's captured type should be the Integer class",
Integer.class, typeRefInt.getType());
TypeReference<Float> typeRefFloat = new TypeReference<Float>() {{ }};
assertFalse("Integer/Float type references must not be equal",
typeRefInt.equals(typeRefFloat));
assertEquals("The type ref's captured type should be the Float class",
Float.class, typeRefFloat.getType());
try {
TypeReference<Integer> typeRefTypeVar = createTypeRefWithTypeVar();
fail("Expected a type reference with type variables to fail");
// Unreachable. Make the warning about an unused variable go away.
assertFalse(typeRefTypeVar.equals(typeRefInt));
} catch (IllegalArgumentException e) {
// OK. Expected behavior
}
|