Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Content fragment mock giving "java.lang.UnsupportedOperationException"

ravi_joshi
Level 3
Level 3

Hi,

 

Facing one issue while calling "getTemplate" method of content fragment mock. Please let me know your thoughts on the same.

 

issue details:

java.lang.UnsupportedOperationException
at io.wcm.testing.mock.aem.MockContentFragment.getTemplate(MockContentFragment.java:232)

 

Junit code snippet:

contentFragment = contentFragmentResource.adaptTo(ContentFragment.class);
lenient().when(contentFragment.getTemplate().getTitle()).thenReturn("testing");

Thanks,

Ravi Joshi

1 Accepted Solution
Vijayalakshmi_S
Correct answer by
Community Advisor
Community Advisor

Hi @ravi_joshi,

It is not supported, Exception is thrown from the respective method. 

 

Vijayalakshmi_S_0-1632431999022.png

 

View solution in original post

3 Replies
Vijayalakshmi_S
Correct answer by
Community Advisor
Community Advisor

Hi @ravi_joshi,

It is not supported, Exception is thrown from the respective method. 

 

Vijayalakshmi_S_0-1632431999022.png

 

View solution in original post

ravi_joshi
Level 3
Level 3

Hi @Vijayalakshmi_S ,

 

Thank you. That was a very helpful explanation. But could you suggest how we can mock "getTemplate()" in the same reference. Or there are any other way to get template or content fragment model title to replace this method invocation.

 

Thanks,

Ravi Joshi

Vijayalakshmi_S
Community Advisor
Community Advisor

From the API documentation of com.adobe.cq.dam.cfm.* package, no other alternative way to retrieve the Content Fragment Model/CF's template Title.