Skip to content

Commit

Permalink
Fix AbstractResourceImpl generating a null value
Browse files Browse the repository at this point in the history
ValueMaps should never contain null values. They should not report a key
as present if there is no corresponding value.
  • Loading branch information
csaboka committed Feb 22, 2024
1 parent 33af5a4 commit 2cd914d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,12 @@ public AbstractResourceImpl(String path, String resourceType, String resourceSup
properties = new HashMap<>();
}

properties.put(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY, resourceType);
properties.put(JcrResourceConstants.SLING_RESOURCE_SUPER_TYPE_PROPERTY, resourceSuperType);
if (resourceType != null) {
properties.put(JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY, resourceType);
}
if (resourceSuperType != null) {
properties.put(JcrResourceConstants.SLING_RESOURCE_SUPER_TYPE_PROPERTY, resourceSuperType);
}

this.properties = new ValueMapDecorator(properties);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.adobe.acs.commons.mcp.form;

import org.apache.sling.api.resource.ResourceResolver;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

class AbstractResourceImplTest {

@Test
void doesNotAddNullValues() {
AbstractResourceImpl nullResourceType = new AbstractResourceImpl("/fake", null, "some/fake/type", null);
assertFalse(nullResourceType.getValueMap().containsKey(ResourceResolver.PROPERTY_RESOURCE_TYPE));

AbstractResourceImpl nullSuperType = new AbstractResourceImpl("/fake", "some/fake/type", null, null);
assertFalse(nullSuperType.getValueMap().containsKey("sling:resourceSuperType"));
}
}

0 comments on commit 2cd914d

Please sign in to comment.