-
Notifications
You must be signed in to change notification settings - Fork 607
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix FieldsetComponent generating a null value
ValueMaps should never contain null values. They should not report a key as present if there is no corresponding value.
- Loading branch information
Showing
4 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
bundle/src/test/java/com/adobe/acs/commons/mcp/form/FieldsetTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.adobe.acs.commons.mcp.form; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
import io.wcm.testing.mock.aem.junit5.AemContext; | ||
import io.wcm.testing.mock.aem.junit5.AemContextExtension; | ||
import org.apache.sling.api.resource.Resource; | ||
import org.apache.sling.api.resource.ValueMap; | ||
import org.apache.sling.api.scripting.SlingScriptHelper; | ||
import org.apache.sling.testing.mock.sling.ResourceResolverType; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith({MockitoExtension.class, AemContextExtension.class}) | ||
class FieldsetTest { | ||
|
||
private final AemContext ctx = new AemContext(ResourceResolverType.JCR_MOCK); | ||
|
||
@Mock | ||
private FormField formField; | ||
|
||
@Mock | ||
private SlingScriptHelper slingScriptHelper; | ||
|
||
@BeforeEach | ||
public void setup() { | ||
ctx.currentResource(ctx.create().resource("/dummy/resource")); | ||
when(slingScriptHelper.getRequest()).thenReturn(ctx.request()); | ||
} | ||
|
||
@Test | ||
public void classNotSpecified() { | ||
final FieldsetComponent fieldsetComponent = new FieldsetComponent(); | ||
fieldsetComponent.setup("dummy", null, formField, slingScriptHelper); | ||
|
||
Resource resource = fieldsetComponent.buildComponentResource(); | ||
ValueMap map = resource.getValueMap(); | ||
|
||
System.out.println(map); | ||
assertFalse(map.containsKey("class")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters