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

PropertyNodesVerifierElem

public class PropertyNodesVerifierElem extends Object
Utility class which verifies input VNode. This class first checks whether each propertyNode in the VNode is in the "ordered expected property list". If the node does not exist in the "ordered list", the class refers to "unorderd expected property set" and checks the node is expected somewhere.

Fields Summary
private final HashMap
mOrderedNodeMap
private final ArrayList
mUnorderedNodeList
Constructors Summary
public PropertyNodesVerifierElem(android.test.AndroidTestCase androidTestCase)

        mOrderedNodeMap = new HashMap<String, List<PropertyNode>>();
        mUnorderedNodeList = new ArrayList<PropertyNode>();
    
Methods Summary
public com.android.vcard.tests.testutils.PropertyNodesVerifierElemaddExpectedNode(java.lang.String propName, java.lang.String propValue)

        return addExpectedNode(propName, propValue, null, null, null, null, null);
    
public com.android.vcard.tests.testutils.PropertyNodesVerifierElemaddExpectedNode(java.lang.String propName, java.lang.String propValue, android.content.ContentValues contentValues)

        return addExpectedNode(propName, propValue, null, null, contentValues, null, null);
    
public com.android.vcard.tests.testutils.PropertyNodesVerifierElemaddExpectedNode(java.lang.String propName, java.util.List propValueList, android.content.ContentValues contentValues)

        return addExpectedNode(propName, null,
                propValueList, null, contentValues, null, null);
    
public com.android.vcard.tests.testutils.PropertyNodesVerifierElemaddExpectedNode(java.lang.String propName, java.lang.String propValue, java.util.List propValueList)

        return addExpectedNode(propName, propValue, propValueList, null, null, null, null);
    
public com.android.vcard.tests.testutils.PropertyNodesVerifierElemaddExpectedNode(java.lang.String propName, java.util.List propValueList)

        return addExpectedNode(propName, null, propValueList,
                null, null, null, null);
    
public com.android.vcard.tests.testutils.PropertyNodesVerifierElemaddExpectedNode(java.lang.String propName, java.lang.String propValue, com.android.vcard.tests.testutils.PropertyNodesVerifierElem$TypeSet paramMap_TYPE)

        return addExpectedNode(propName, propValue, null, null, null, paramMap_TYPE, null);
    
public com.android.vcard.tests.testutils.PropertyNodesVerifierElemaddExpectedNode(java.lang.String propName, java.util.List propValueList, com.android.vcard.tests.testutils.PropertyNodesVerifierElem$TypeSet paramMap_TYPE)

        final String propValue = concatinateListWithSemiColon(propValueList);
        return addExpectedNode(propName, propValue, propValueList, null, null,
                paramMap_TYPE, null);
    
public com.android.vcard.tests.testutils.PropertyNodesVerifierElemaddExpectedNode(java.lang.String propName, java.lang.String propValue, java.util.List propValueList, com.android.vcard.tests.testutils.PropertyNodesVerifierElem$TypeSet paramMap_TYPE)

        return addExpectedNode(propName, propValue, propValueList, null, null,
                paramMap_TYPE, null);
    
public com.android.vcard.tests.testutils.PropertyNodesVerifierElemaddExpectedNode(java.lang.String propName, java.lang.String propValue, android.content.ContentValues paramMap, com.android.vcard.tests.testutils.PropertyNodesVerifierElem$TypeSet paramMap_TYPE)

        return addExpectedNode(propName, propValue, null, null,
                paramMap, paramMap_TYPE, null);
    
public com.android.vcard.tests.testutils.PropertyNodesVerifierElemaddExpectedNode(java.lang.String propName, java.lang.String propValue, java.util.List propValueList, byte[] propValue_bytes, android.content.ContentValues paramMap, com.android.vcard.tests.testutils.PropertyNodesVerifierElem$TypeSet paramMap_TYPE, com.android.vcard.tests.testutils.PropertyNodesVerifierElem$GroupSet propGroupSet)

        if (propValue == null && propValueList != null) {
            propValue = concatinateListWithSemiColon(propValueList);
        }
        mUnorderedNodeList.add(new PropertyNode(propName, propValue,
                propValueList, propValue_bytes, paramMap, paramMap_TYPE, propGroupSet));
        return this;
    
public com.android.vcard.tests.testutils.PropertyNodesVerifierElemaddExpectedNodeWithOrder(java.lang.String propName, java.lang.String propValue, android.content.ContentValues paramMap, com.android.vcard.tests.testutils.PropertyNodesVerifierElem$TypeSet paramMap_TYPE)

        return addExpectedNodeWithOrder(propName, propValue, null, null,
                paramMap, paramMap_TYPE, null);
    
public com.android.vcard.tests.testutils.PropertyNodesVerifierElemaddExpectedNodeWithOrder(java.lang.String propName, java.lang.String propValue, java.util.List propValueList, com.android.vcard.tests.testutils.PropertyNodesVerifierElem$TypeSet paramMap_TYPE)

        return addExpectedNodeWithOrder(propName, propValue, propValueList, null, null,
                paramMap_TYPE, null);
    
public com.android.vcard.tests.testutils.PropertyNodesVerifierElemaddExpectedNodeWithOrder(java.lang.String propName, java.lang.String propValue, java.util.List propValueList, android.content.ContentValues paramMap)

        return addExpectedNodeWithOrder(propName, propValue, propValueList, null, paramMap,
                null, null);
    
public com.android.vcard.tests.testutils.PropertyNodesVerifierElemaddExpectedNodeWithOrder(java.lang.String propName, java.lang.String propValue, java.util.List propValueList, byte[] propValue_bytes, android.content.ContentValues paramMap, com.android.vcard.tests.testutils.PropertyNodesVerifierElem$TypeSet paramMap_TYPE, com.android.vcard.tests.testutils.PropertyNodesVerifierElem$GroupSet propGroupSet)

        if (propValue == null && propValueList != null) {
            propValue = concatinateListWithSemiColon(propValueList);
        }
        final PropertyNode propertyNode = new PropertyNode(propName,
                propValue, propValueList, propValue_bytes,
                paramMap, paramMap_TYPE, propGroupSet);
        List<PropertyNode> expectedNodeList = mOrderedNodeMap.get(propName);
        if (expectedNodeList == null) {
            expectedNodeList = new ArrayList<PropertyNode>();
            mOrderedNodeMap.put(propName, expectedNodeList);
        }
        expectedNodeList.add(propertyNode);
        return this;
    
public com.android.vcard.tests.testutils.PropertyNodesVerifierElemaddExpectedNodeWithOrder(java.lang.String propName, java.lang.String propValue)

        return addExpectedNodeWithOrder(propName, propValue, null, null, null, null, null);
    
public com.android.vcard.tests.testutils.PropertyNodesVerifierElemaddExpectedNodeWithOrder(java.lang.String propName, java.lang.String propValue, android.content.ContentValues contentValues)

        return addExpectedNodeWithOrder(propName, propValue, null,
                null, contentValues, null, null);
    
public com.android.vcard.tests.testutils.PropertyNodesVerifierElemaddExpectedNodeWithOrder(java.lang.String propName, java.util.List propValueList, android.content.ContentValues contentValues)

        return addExpectedNodeWithOrder(propName, null, propValueList,
                null, contentValues, null, null);
    
public com.android.vcard.tests.testutils.PropertyNodesVerifierElemaddExpectedNodeWithOrder(java.lang.String propName, java.lang.String propValue, java.util.List propValueList)

        return addExpectedNodeWithOrder(propName, propValue, propValueList, null,
                null, null, null);
    
public com.android.vcard.tests.testutils.PropertyNodesVerifierElemaddExpectedNodeWithOrder(java.lang.String propName, java.util.List propValueList)

        final String propValue = concatinateListWithSemiColon(propValueList);
        return addExpectedNodeWithOrder(propName, propValue.toString(), propValueList,
                null, null, null, null);
    
public com.android.vcard.tests.testutils.PropertyNodesVerifierElemaddExpectedNodeWithOrder(java.lang.String propName, java.lang.String propValue, com.android.vcard.tests.testutils.PropertyNodesVerifierElem$TypeSet paramMap_TYPE)

        return addExpectedNodeWithOrder(propName, propValue, null,
                null, null, paramMap_TYPE, null);
    
public com.android.vcard.tests.testutils.PropertyNodesVerifierElemaddExpectedNodeWithOrder(java.lang.String propName, java.util.List propValueList, com.android.vcard.tests.testutils.PropertyNodesVerifierElem$TypeSet paramMap_TYPE)

        return addExpectedNodeWithOrder(propName, null, propValueList, null, null,
                paramMap_TYPE, null);
    
public com.android.vcard.tests.testutils.PropertyNodesVerifierElemaddExpectedNodeWithOrder(java.lang.String propName, java.util.List propValueList, android.content.ContentValues paramMap, com.android.vcard.tests.testutils.PropertyNodesVerifierElem$TypeSet paramMap_TYPE)

        return addExpectedNodeWithOrder(propName, null, propValueList, null, paramMap,
                paramMap_TYPE, null);
    
private java.lang.StringconcatinateListWithSemiColon(java.util.List array)

        StringBuffer buffer = new StringBuffer();
        boolean first = true;
        for (String propValueElem : array) {
            if (first) {
                first = false;
            } else {
                buffer.append(';");
            }
            buffer.append(propValueElem);
        }

        return buffer.toString();
    
private voidfailWithExpectedNodeList(java.lang.String propName, PropertyNode actualNode, java.util.List expectedNodeList)

        StringBuilder builder = new StringBuilder();
        for (PropertyNode expectedNode : expectedNodeList) {
            builder.append("expected: ");
            builder.append(expectedNode.toString());
            builder.append("\n");
        }
        TestCase.fail("Property \"" + propName + "\" has wrong value.\n"
                + builder.toString()
                + "  actual: " + actualNode.toString());
    
private booleantryFoundExpectedNodeFromUnorderedList(PropertyNode actualNode, java.util.List expectedButDifferentValueList)

        final String propName = actualNode.propName;
        int unorderedListSize = mUnorderedNodeList.size();
        for (int i = 0; i < unorderedListSize; i++) {
            PropertyNode unorderedExpectedNode = mUnorderedNodeList.get(i);
            if (unorderedExpectedNode.propName.equals(propName)) {
                if (unorderedExpectedNode.equals(actualNode)) {
                    mUnorderedNodeList.remove(i);
                    return true;
                }
                expectedButDifferentValueList.add(unorderedExpectedNode);
            }
        }
        return false;
    
public voidverify(VNode vnode)

        for (PropertyNode actualNode : vnode.propList) {
            verifyNode(actualNode.propName, actualNode);
        }

        if (!mOrderedNodeMap.isEmpty() || !mUnorderedNodeList.isEmpty()) {
            final List<String> expectedProps = new ArrayList<String>();
            for (List<PropertyNode> nodes : mOrderedNodeMap.values()) {
                for (PropertyNode node : nodes) {
                    if (!expectedProps.contains(node.propName)) {
                        expectedProps.add(node.propName);
                    }
                }
            }
            for (PropertyNode node : mUnorderedNodeList) {
                if (!expectedProps.contains(node.propName)) {
                    expectedProps.add(node.propName);
                }
            }
            TestCase.fail("Expected property " + Arrays.toString(expectedProps.toArray())
                    + " was not found.");
        }
    
private voidverifyNode(java.lang.String propName, PropertyNode actualNode)

        final List<PropertyNode> expectedNodeList = mOrderedNodeMap.get(propName);
        final int size = (expectedNodeList != null ? expectedNodeList.size() : 0);
        if (size > 0) {
            for (int i = 0; i < size; i++) {
                final PropertyNode expectedNode = expectedNodeList.get(i);
                final List<PropertyNode> expectedButDifferentValueList =
                        new ArrayList<PropertyNode>();
                if (expectedNode.propName.equals(propName)) {
                    if (expectedNode.equals(actualNode)) {
                        expectedNodeList.remove(i);
                        if (expectedNodeList.size() == 0) {
                            mOrderedNodeMap.remove(propName);
                        }
                        return;
                    } else {
                        expectedButDifferentValueList.add(expectedNode);
                    }
                }

                // "actualNode" is not in ordered expected list.
                // Try looking over unordered expected list.
                if (tryFoundExpectedNodeFromUnorderedList(actualNode,
                        expectedButDifferentValueList)) {
                    return;
                }

                if (!expectedButDifferentValueList.isEmpty()) {
                    // Same propName exists but with different value(s).
                    failWithExpectedNodeList(propName, actualNode,
                            expectedButDifferentValueList);
                } else {
                    // There's no expected node with same propName.
                    TestCase.fail("Unexpected property \"" + propName + "\" exists.");
                }
            }
        } else {
            List<PropertyNode> expectedButDifferentValueList =
                new ArrayList<PropertyNode>();
            if (tryFoundExpectedNodeFromUnorderedList(actualNode, expectedButDifferentValueList)) {
                return;
            } else {
                if (!expectedButDifferentValueList.isEmpty()) {
                    // Same propName exists but with different value(s).
                    failWithExpectedNodeList(propName, actualNode,
                            expectedButDifferentValueList);
                } else {
                    // There's no expected node with same propName.
                    TestCase.fail("Unexpected property \"" + propName + "\" exists.");
                }
            }
        }