Search code examples
unit-testingjunititeratorjackrabbitsling

How to mock sling PropertyIterator?


I have following code to test:

  static Set<String> methodToTest(Node crxProductNode, OfflineNodeAction nodeAction, Set<String> allowedAttributes) throws RepositoryException {
        Set<String> changedPropertiesKeys = new HashSet<String>();
        final PropertyIterator crxProductNodeProperties = crxProductNode.getProperties();
        while (crxProductNodeProperties.hasNext()) {
            final String crxNodePropertyName = crxProductNodeProperties.nextProperty().getName();
            if(nodeAction.getProperties(crxNodePropertyName)==null && allowedAttributes.contains(crxNodePropertyName)){
                changedPropertiesKeys.add(crxNodePropertyName);
            }
        }
        return changedPropertiesKeys;
    }

Please advise me how to test following code.

I have problem with Iterator mocking. I don't understand how to mock it.


Solution

  • For this exists class

    org.apache.sling.commons.testing.jcr.MockNode
    

    and

    MockNodeIterator