FileDocCategorySizeDatePackage
VerifierDeviceIdentityTest.javaAPI DocAndroid 5.1 API9153Thu Mar 12 22:22:12 GMT 2015android.content.pm

VerifierDeviceIdentityTest

public class VerifierDeviceIdentityTest extends android.test.AndroidTestCase

Fields Summary
private static final long
TEST_1
private static final String
TEST_1_ENCODED
private static final String
TEST_1_ENCODED_LOWERCASE
private static final long
TEST_2
private static final long
TEST_MAXVALUE
private static final String
TEST_MAXVALUE_ENCODED
private static final long
TEST_MINVALUE
private static final String
TEST_MINVALUE_ENCODED
private static final long
TEST_ZERO
private static final String
TEST_ZERO_ENCODED
private static final long
TEST_NEGONE
private static final String
TEST_NEGONE_ENCODED
private static final String
TEST_OVERFLOW_ENCODED
private static final String
TEST_SUBSTITUTION_CORRECTED
private static final String
TEST_SUBSTITUTION_UNCORRECTED
Constructors Summary
Methods Summary
public voidtestVerifierDeviceIdentity_Equals_Failure()

        VerifierDeviceIdentity id1 = new VerifierDeviceIdentity(TEST_1);
        VerifierDeviceIdentity id2 = new VerifierDeviceIdentity(TEST_2);

        assertFalse("The two VerifierDeviceIdentity instances should be unique", id1.equals(id2));
    
public voidtestVerifierDeviceIdentity_Equals_Success()


       
        VerifierDeviceIdentity id1 = new VerifierDeviceIdentity(TEST_1);
        VerifierDeviceIdentity id2 = new VerifierDeviceIdentity(TEST_1);

        assertTrue("The two VerifierDeviceIdentity instances should be equal", id1.equals(id2));
    
public voidtestVerifierDeviceIdentity_Generate_MinValue()

        VerifierDeviceIdentity id1 = new VerifierDeviceIdentity(TEST_MINVALUE);

        MockRandom random = new MockRandom();
        random.setNextLong(Long.MIN_VALUE);
        VerifierDeviceIdentity id2 = VerifierDeviceIdentity.generate(random);

        assertEquals("Identity created from Long.MIN_VALUE and one created from return from RNG"
                + " should be the same", id1, id2);
    
public voidtestVerifierDeviceIdentity_Generate_Random()

        VerifierDeviceIdentity id1 = new VerifierDeviceIdentity(TEST_1);

        MockRandom random = new MockRandom();
        random.setNextLong(TEST_1);
        VerifierDeviceIdentity id2 = VerifierDeviceIdentity.generate(random);

        assertEquals("Identity should end up being same when coming from RNG", id1, id2);
    
public voidtestVerifierDeviceIdentity_HashCode()

        VerifierDeviceIdentity id1 = new VerifierDeviceIdentity(TEST_1);

        assertEquals("The VerifierDeviceIdentity should have the same hashcode as its identity",
                (int) TEST_1, id1.hashCode());
    
public voidtestVerifierDeviceIdentity_Parcel_ReadNegative()

        VerifierDeviceIdentity id1 = new VerifierDeviceIdentity(TEST_MINVALUE);

        Parcel parcel = Parcel.obtain();
        parcel.writeLong(TEST_MINVALUE);
        parcel.setDataPosition(0);

        VerifierDeviceIdentity id2 = VerifierDeviceIdentity.CREATOR.createFromParcel(parcel);

        assertEquals("Parcel created should match expected value", id1, id2);
    
public voidtestVerifierDeviceIdentity_Parcel_Read_Pass()

        VerifierDeviceIdentity id1 = new VerifierDeviceIdentity(TEST_1);

        Parcel parcel = Parcel.obtain();
        id1.writeToParcel(parcel, 0);
        parcel.setDataPosition(0);

        VerifierDeviceIdentity id2 = VerifierDeviceIdentity.CREATOR.createFromParcel(parcel);

        assertEquals("Original identity and parceled identity should be the same", id1, id2);
    
public voidtestVerifierDeviceIdentity_Parse_1I_And_0O_Substitution()

        VerifierDeviceIdentity id1 = VerifierDeviceIdentity.parse(TEST_SUBSTITUTION_CORRECTED);

        VerifierDeviceIdentity id2 = VerifierDeviceIdentity.parse(TEST_SUBSTITUTION_UNCORRECTED);

        assertEquals("Substitution should replace 0 with O and 1 with I", id1, id2);

        assertEquals("Substituted identity should render to the same string",
                id1.toString(), id2.toString());
    
public voidtestVerifierDeviceIdentity_Parse_MaxValue()

        VerifierDeviceIdentity id1 = new VerifierDeviceIdentity(TEST_MAXVALUE);

        VerifierDeviceIdentity id2 = VerifierDeviceIdentity.parse(TEST_MAXVALUE_ENCODED);

        assertEquals("Original max value and parsed max value should be equal", id1, id2);
    
public voidtestVerifierDeviceIdentity_Parse_Normal()

        VerifierDeviceIdentity id1 = new VerifierDeviceIdentity(TEST_1);

        VerifierDeviceIdentity id2 = VerifierDeviceIdentity.parse(TEST_1_ENCODED);

        assertEquals("Parsed device identity should have the same value as original identity",
                id1, id2);
    
public voidtestVerifierDeviceIdentity_Parse_Overflow()

        try {
            VerifierDeviceIdentity.parse(TEST_OVERFLOW_ENCODED);
            fail("Parsing should fail when the value will overflow");
        } catch (IllegalArgumentException e) {
            // success
        }
    
public voidtestVerifierDeviceIdentity_Parse_SquashToUppercase()

        VerifierDeviceIdentity id1 = new VerifierDeviceIdentity(TEST_1);

        VerifierDeviceIdentity id2 = VerifierDeviceIdentity.parse(TEST_1_ENCODED_LOWERCASE);

        assertEquals("Lowercase should parse to be the same as uppercase", id1, id2);

        assertEquals("Substituted identity should render to the same string",
                id1.toString(), id2.toString());
    
public voidtestVerifierDeviceIdentity_Parse_TooLong()

        try {
            VerifierDeviceIdentity.parse("AAAA-AAAA-AAAA-AA");
            fail("Parsing should fail when device identifier is too long");
        } catch (IllegalArgumentException e) {
            // success
        }
    
public voidtestVerifierDeviceIdentity_Parse_TooShort()

        try {
            VerifierDeviceIdentity.parse("AAAA-AAAA-AAAA-");
            fail("Parsing should fail when device identifier is too short");
        } catch (IllegalArgumentException e) {
            // success
        }
    
public voidtestVerifierDeviceIdentity_Parse_WayTooShort()

        try {
            VerifierDeviceIdentity.parse("----------------");
            fail("Parsing should fail when device identifier is too short");
        } catch (IllegalArgumentException e) {
            // success
        }
    
public voidtestVerifierDeviceIdentity_ToString_Largest()

        VerifierDeviceIdentity id1 = new VerifierDeviceIdentity(TEST_MAXVALUE);

        assertEquals("The identity should encode correctly to the expected Base 32 string",
                TEST_MAXVALUE_ENCODED, id1.toString());
    
public voidtestVerifierDeviceIdentity_ToString_MinValue()

        VerifierDeviceIdentity id1 = new VerifierDeviceIdentity(TEST_MINVALUE);

        assertEquals("The identity should encode correctly to the expected Base 32 string",
                TEST_MINVALUE_ENCODED, id1.toString());
    
public voidtestVerifierDeviceIdentity_ToString_NegOne()

        VerifierDeviceIdentity id1 = new VerifierDeviceIdentity(TEST_NEGONE);

        assertEquals("The identity should encode correctly to the expected Base 32 string",
                TEST_NEGONE_ENCODED, id1.toString());
    
public voidtestVerifierDeviceIdentity_ToString_Success()

        VerifierDeviceIdentity id1 = new VerifierDeviceIdentity(TEST_1);

        assertEquals("The identity should encode correctly to the expected Base 32 string",
                TEST_1_ENCODED, id1.toString());
    
public voidtestVerifierDeviceIdentity_ToString_Zero()

        VerifierDeviceIdentity id1 = new VerifierDeviceIdentity(TEST_ZERO);

        assertEquals("The identity should encode correctly to the expected Base 32 string",
                TEST_ZERO_ENCODED, id1.toString());