Content fragment mock giving "java.lang.UnsupportedOperationException" | Community
Skip to main content
Ravi_Joshi
September 23, 2021
Solved

Content fragment mock giving "java.lang.UnsupportedOperationException"

  • September 23, 2021
  • 1 reply
  • 2791 views

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

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 Vijayalakshmi_S

Hi @ravi_joshi,

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

 

 

1 reply

Vijayalakshmi_S
Vijayalakshmi_SAccepted solution
September 23, 2021

Hi @ravi_joshi,

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

 

 

Ravi_Joshi
September 24, 2021

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
September 24, 2021

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.