Expand my Community achievements bar.

GuideDatePicker junit test case throws exception for resource

Avatar

Level 4

Hello ,

I have extend the GuideDatePicker

 

package com.adobe.aemds.guide.common;
public class GuideDatePicker extends com.adobe.aemds.guide.common.GuideField {

 

I would want to write test case for below 

 

public class GuideDatePickerObject extends GuideDatePicker {

public GuideDatePickerObject() {

}

public String checkGenerateSOM() {
if (this.getResource())) {
return GuideUtils.generateSOM(getResource());
} else {
return StringUtils.EMPTY;
}
}
}

 

How to achieve it

 

Could some help me on this . As it is throwing null pointer exception always at this.getResource()

 

Test case :-

 

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.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import com.day.cq.wcm.api.Page;


@ExtendWith(AemContextExtension.class)
public class GuideDatePickerObjectTest {

public final AemContext context = new AemContext();

private GuideDatePickerObject guideDatePickerObject;

private Page page;
private Resource resource;
@BeforeEach
public void setUp() throws Exception {

page = context.create().page("/content/mypage");
resource = context.create().resource(page, "hello",
"sling:resourceType", "web-forms/components/helloworld");


context.request().setResource(resource);
}

@test
void testResourceSectionBasic() {
guideDatePickerObject= new GuideDatePickerObject();

String som= guideDatePickerObject.getSom();
System.out.println("som="+som);
Assertions.assertEquals( som,"uu" );

 

}


}

 

Regards,

Srinivas

 

 

 

0 Replies