SObjectNode addNode(final SObjectNode node) {
        final String givenObjectType = node.getObjectType();

        if (objectType != null && !objectType.equals(givenObjectType)) {
            throw new IllegalArgumentException(
                    "SObjectTree can hold only records of the same type, previously given: " + objectType
                                               + ", and now trying to add: "
                                               + givenObjectType);
        }
        objectType = givenObjectType;

        records.add(node);

        return node;
    }
@Test
    public void shouldSetReferences() {
        final SObjectTree tree = new SObjectTree();

        final SObjectNode account1 = new SObjectNode(tree, simpleAccount);
        account1.addChild("Contacts", smith);
        account1.addChild("Contacts", evans);
        tree.addNode(account1);

        final SObjectNode account2 = new SObjectNode(tree, simpleAccount2);
        tree.addNode(account2);

        final SObjectNode simpleAccountFromTree = tree.records.get(0);
        assertEquals("ref1", simpleAccountFromTree.getObject().getAttributes().getReferenceId());

        final Iterator<SObjectNode> simpleAccountNodes = simpleAccountFromTree.getChildNodes().iterator();
        assertEquals("ref2", simpleAccountNodes.next().getObject().getAttributes().getReferenceId());
        assertEquals("ref3", simpleAccountNodes.next().getObject().getAttributes().getReferenceId());

        assertEquals("ref4", account2.getObject().getAttributes().getReferenceId());
    }