exception on creating test case for CQ5 component-raising from getResource() method | Community
Skip to main content
snigdha1234
October 16, 2015
Solved

exception on creating test case for CQ5 component-raising from getResource() method

  • October 16, 2015
  • 2 replies
  • 705 views

Hi,

while i am trying to get current node value by mocking node class and ResourceResolver class I am getting nullPointerException over there.Exception is raising from getResource() method.

 

Here is my actual class code

public class Myclass extends WCMUse {

public void activate() throws Exception {

Node currentNode = getResource().adaptTo(Node.class);

.

.

..........bla bla

}

}

 

Here is my Test class

    
    @Mock
    Node node;
    @Mock 
    ResourceResolver resourceResolver;
    

    @Test
        
        Resource res=resourceResolver.getResource("/");
        EasyMock.expect(res.adaptTo((Class<Node>) EasyMock.anyObject())).andReturn(node);

 

In that underlined part I am getting null pointer Exception.

Please suggest me the exact approach.
        
       

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by smacdonald2008

See this community article that talks about using Sling API to get resources:

https://helpx.adobe.com/experience-manager/using/using-sling-apis.html

2 replies

snigdha1234
October 16, 2015

Hi Thanks for your reply 

But I am facing that nullPointerException issue while creating Unit testcases for the component plz help me on that

smacdonald2008
smacdonald2008Accepted solution
Level 10
October 16, 2015

See this community article that talks about using Sling API to get resources:

https://helpx.adobe.com/experience-manager/using/using-sling-apis.html