Issue
I have a scenario where I have to set a property of a mocked object as follows:
SlingHttpRequest slingHttpRequest= mock(SlingHttpRequest);
slingHttpRequest.setAttribute("search", someObject);
When I try to print this attribute I get null
. How do I set this property?
Solution
You don't normally set properties on your mocked objects; instead, you do some specific thing when it's invoked.
when(slingHttpRequest.getAttribute("search")).thenReturn(someObject);
Answered By - Makoto
Answer Checked By - David Marino (JavaFixing Volunteer)