AEM Mock : Coverage issue

Avatar

Avatar
Ignite 1
Level 2
narindera257447
Level 2

Likes

5 likes

Total Posts

16 posts

Correct reply

0 solutions
Top badges earned
Ignite 1
Give Back 3
Give Back
Boost 5
Boost 3
View profile

Avatar
Ignite 1
Level 2
narindera257447
Level 2

Likes

5 likes

Total Posts

16 posts

Correct reply

0 solutions
Top badges earned
Ignite 1
Give Back 3
Give Back
Boost 5
Boost 3
View profile
narindera257447
Level 2

18-08-2019

The below is the class / System under Test :

1816763_pastedImage_0.png

Test Case:   It is throwing null pointer at line 71

1816766_pastedImage_9.png

Coverage Output

1816765_pastedImage_6.png

Query:

What changes need to be done in the test case to cover the try catch section of the code. Please Suggest.

Replies

Avatar

Avatar
Give Back 5
Employee
SonDang
Employee

Likes

17 likes

Total Posts

43 posts

Correct reply

9 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back 10
Give Back
Boost 5
View profile

Avatar
Give Back 5
Employee
SonDang
Employee

Likes

17 likes

Total Posts

43 posts

Correct reply

9 solutions
Top badges earned
Give Back 5
Give Back 3
Give Back 10
Give Back
Boost 5
View profile
SonDang
Employee

19-08-2019

I am not sure if I understand your question completely. So, I am going to assume to want to understand the reason for the NullPointerException. From looking at the code, it appears that the object "resolver" is null because it has not been initialized in the method setUp(). Maybe adding the line below in the method setUp() will help.

resolver = context.mock(ResourceResolver.class);

Avatar

Avatar
Ignite 1
Level 2
narindera257447
Level 2

Likes

5 likes

Total Posts

16 posts

Correct reply

0 solutions
Top badges earned
Ignite 1
Give Back 3
Give Back
Boost 5
Boost 3
View profile

Avatar
Ignite 1
Level 2
narindera257447
Level 2

Likes

5 likes

Total Posts

16 posts

Correct reply

0 solutions
Top badges earned
Ignite 1
Give Back 3
Give Back
Boost 5
Boost 3
View profile
narindera257447
Level 2

19-08-2019

Thank you for your response and is a value add.

Also, It looks like this will work for Mockito but for AEM Mock , its context object is not recognizing the mock class.