FileDocCategorySizeDatePackage
LineVerifierElem.javaAPI DocAndroid 5.1 API3596Thu Mar 12 22:22:54 GMT 2015com.android.vcard.tests.testutils

LineVerifierElem

public class LineVerifierElem extends Object

Fields Summary
private final List
mExpectedLineList
private final int
mVCardType
Constructors Summary
public LineVerifierElem(android.test.AndroidTestCase androidTestCase, int vcardType)


         
        mVCardType = vcardType;
    
Methods Summary
public com.android.vcard.tests.testutils.LineVerifierElemaddExpected(java.lang.String line)

        if (!TextUtils.isEmpty(line)) {
            mExpectedLineList.add(line);
        }
        return this;
    
public voidverify(java.lang.String vcard)

        final String[] lineArray = vcard.split("\\r?\\n");
        final int length = lineArray.length;
        boolean beginExists = false;
        boolean endExists = false;
        boolean versionExists = false;

        for (int i = 0; i < length; i++) {
            final String line = lineArray[i];
            if (TextUtils.isEmpty(line)) {
                continue;
            }

            if ("BEGIN:VCARD".equalsIgnoreCase(line)) {
                if (beginExists) {
                    TestCase.fail("Multiple \"BEGIN:VCARD\" line found");
                } else {
                    beginExists = true;
                    continue;
                }
            } else if ("END:VCARD".equalsIgnoreCase(line)) {
                if (endExists) {
                    TestCase.fail("Multiple \"END:VCARD\" line found");
                } else {
                    endExists = true;
                    continue;
                }
            } else if ((VCardConfig.isVersion21(mVCardType) ? "VERSION:2.1" :
                (VCardConfig.isVersion30(mVCardType) ? "VERSION:3.0" :
                    "VERSION:4.0")).equalsIgnoreCase(line)) {
                if (versionExists) {
                    TestCase.fail("Multiple VERSION line + found");
                } else {
                    versionExists = true;
                    continue;
                }
            }

            if (!beginExists) {
                TestCase.fail("Property other than BEGIN came before BEGIN property: " + line);
            } else if (endExists) {
                TestCase.fail("Property other than END came after END property: " + line);
            }

            final int index = mExpectedLineList.indexOf(line);
            if (index >= 0) {
                mExpectedLineList.remove(index);
            } else {
                TestCase.fail("Unexpected line: " + line);
            }
        }

        if (!mExpectedLineList.isEmpty()) {
            StringBuffer buffer = new StringBuffer();
            for (String expectedLine : mExpectedLineList) {
                buffer.append(expectedLine);
                buffer.append("\n");
            }

            TestCase.fail("Expected line(s) not found:" + buffer.toString());
        }