How to write Unit Tests for Extended Core Components' Java Models
I extended the Text Core Component's Java Class with a simple "moreText" variable.
But I am still using some of the Core Component's methods in the HTL so I need them in my Java Class.
How can I Unit Test the Extended Core Component's methods that require the ResourceSuperType?
package com.adobe.aem.guides.wknd.core.models;
import com.adobe.cq.export.json.ComponentExporter;
import com.adobe.cq.export.json.ExporterConstants;
import com.adobe.cq.wcm.core.components.models.Text;
import lombok.Getter;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.models.annotations.Default;
import org.apache.sling.models.annotations.DefaultInjectionStrategy;
import org.apache.sling.models.annotations.Exporter;
import org.apache.sling.models.annotations.Model;
import org.apache.sling.models.annotations.Via;
import org.apache.sling.models.annotations.injectorspecific.Self;
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue;
import org.apache.sling.models.annotations.via.ResourceSuperType;
@Model(
adaptables = SlingHttpServletRequest.class,
adapters = {ComponentExporter.class},
resourceType = ExtendedCoreComponentModel.RESOURCE_TYPE,
defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL
)
@Exporter(
name = ExporterConstants.SLING_MODEL_EXPORTER_NAME,
extensions = ExporterConstants.SLING_MODEL_EXTENSION
)
public class ExtendedCoreComponentModel implements Text {
static final String RESOURCE_TYPE = "wknd/components/extendedcorecomponent";
@Self
@2434638(type = ResourceSuperType.class)
protected Text text;
@14766979
@ValueMapValue
@1497330(values = "Hello World.")
private String moreText;
@9944223
public String getText() {
return text.getText();
}
@9944223
public boolean isRichText() {
return text.isRichText();
}
}