FileDocCategorySizeDatePackage
CameraUtilsTypeReferenceTest.javaAPI DocAndroid 5.1 API9123Thu Mar 12 22:22:30 GMT 2015com.android.mediaframeworktest.unit

CameraUtilsTypeReferenceTest

public class CameraUtilsTypeReferenceTest extends TestCase

Fields Summary
private static final String
TAG
private static final boolean
VERBOSE
Constructors Summary
Methods Summary
private static voidassertContainsTypeVariable(java.lang.reflect.Type type)

        assertTrue(type.toString() + " was expected to have a type variable, but it didn't",
                containsTypeVariable(type));
    
private static voidassertLacksTypeVariable(java.lang.reflect.Type type)

        assertFalse(type.toString() + " was expected to *not* have a type variable, but it did",
                containsTypeVariable(type));
    
private static voidassertRawTypeEquals(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 voidassertTypeReferenceEquals(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.TypeReferencecreateTypeRefWithTypeVar()
This should always throw an IllegalArgumentException since the type reference to {@code T} will contain a type variable (also {@code T}).

throws
IllegalArgumentException unconditionally

        return new TypeReference<T>() {{ }};
    
public voidtestComponentType()

        // 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 voidtestContainsTypeVariables()

        assertContainsTypeVariable(GenericClass.class);
        assertContainsTypeVariable(SubGenericClass.class);

        assertContainsTypeVariable(GenericInterface.class);
        assertContainsTypeVariable(ImplementsGenericInterface.class);
        assertContainsTypeVariable(Implements2GenericInterface.class);

        assertContainsTypeVariable(GenericOuterClass.class);
        assertContainsTypeVariable(GenericOuterClass.GenericInnerClass.class);
    
public voidtestEquals()

        // 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 voidtestLacksTypeVariables()

        assertLacksTypeVariable(RegularClass.class);
        assertLacksTypeVariable(SubClass.class);
        assertLacksTypeVariable(SpecificClass.class);

        assertLacksTypeVariable(RegularInterface.class);
        assertLacksTypeVariable(ImplementsRegularInterface.class);
    
public voidtestRawTypes()

        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 voidtestTypeReferences()

        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
        }