Hi All,
I am facing NullPointerException on ButtonModelTest. ButtonModel class is created based on delegation pattern, which implements Button(core component class).
1 .Button Model class
2. ButtonModelTest
I am facing error at line 45, at the time of get the properties, even my json file is correct.
Please help me find the solutions for junit test case for delegation pattern model classes.
Thanks in Advance.
Solved! Go to Solution.
Views
Replies
Total Likes
You have to follow this to make it work
https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/junit-test-cases-for-sling...
I cannot see the more than one adaptables in your model code, thats why I asked if you are following above or not
Most of the cases of NullPointerException occur for the bad resource. In your test class check line no 39, you are getting the correct resource.
line39 is correct, its not null.
Actually, it's not about NULL. To see if the resource is correct or not check the next line. buttonModel is null or not.
Yeah, its return NULL, that's why am not able to get any properties.
Did you try adapting model with SlingHttpServletRequest?
buttonModel = context.request().adapt(ButtonModel.class);
Please check
@arunpatidar Tried this approach but its not works for me. Still NullPointerException at time of get the property of Button core class.
Is there any other way to do junit on sling delegation pattern?
Thanks.
Hi
Can you share your model and test class?
Above screenshots shared model and test classes .
You have to follow this to make it work
https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/junit-test-cases-for-sling...
I cannot see the more than one adaptables in your model code, thats why I asked if you are following above or not
hi @N_haq - was your issue resolved, i am also getting similar issue
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies