Solved
Unit test componentData
Hello everyone
Does anyone knows how can I test (unit testing) this method in aem
public ComponentData getData() {
Resource investorListEventResource = this.request.getResource();
// Use ComponentUtils to verify if the DataLayer is enabled
if (ComponentUtils.isDataLayerEnabled(investorListEventResource)) {
return DataLayerBuilder.forComponent()
.withId(() -> investorListEventResource.getName() + "-" + getUniqueId())
.withTitle(() -> investorListEventResource.getPath())
.withDescription(() -> getAssociatedDocsDialogDescription())
.withLinkUrl(() -> currentPage.getPath() + "." + request.getRequestPathInfo().getExtension())
.build();
}
// return null if the Data Layer is not enabled
return null;
}
public ComponentData getData() {
Resource milestoneResource = this.resource;
SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
String dateFormatted = format1.format(getDate().getTime());
// Use ComponentUtils to verify if the DataLayer is enabled
if (ComponentUtils.isDataLayerEnabled(milestoneResource)) {
//if the data is empty or null the json won't generate the keys
return DataLayerBuilder.forComponent()
.withId(() -> milestoneResource.getName() )
.withType(() -> getType())
.withTitle(() -> getTitle())
.withDescription(() -> getCategory())
.withText(() -> dateFormatted)
.build();
}
// return null if the Data Layer is not enabled
return null;
}
Thanks in advance.