java.lang.UnsupportedOperationException in Junit test - content fragment - ContentElement.getValue() | Community
Skip to main content
Level 2
September 14, 2022
Solved

java.lang.UnsupportedOperationException in Junit test - content fragment - ContentElement.getValue()

  • September 14, 2022
  • 2 replies
  • 4304 views

I am trying to write a Junit for below piece of code and getting this error

java.lang.UnsupportedOperationException
at io.wcm.testing.mock.aem.MockContentFragment_ContentElement_Structured.getValue(MockContentFragment_ContentElement_Structured.java:173)

 

Code snippet

 

private String getAuthoredDate(ContentFragment contentFragment) {
SimpleDateFormat sdf = new SimpleDateFormat("MMM dd, yyyy");
ContentElement contentElement = contentFragment.getElement("authoredDate");
Calendar date = (Calendar) contentElement.getValue().getValue();
return sdf.format(date.getTime());
}

 

Any Idea how can I mock the ContentElement getvalue and FragmentData getvalue functions?

 

Thanks!

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 joerghoh

Looks like these methods are not supported yet with the wcm.io mocking library (see [1]). I would raise a ticket there and ask about plans to support these methods.

 

 

[1] https://github.com/wcm-io/io.wcm.testing.aem-mock/blob/develop/core/src/main/java/io/wcm/testing/mock/aem/MockContentFragment_ContentVariation_Structured.java

 

 

2 replies

joerghoh
Adobe Employee
joerghohAdobe EmployeeAccepted solution
Adobe Employee
September 14, 2022

Looks like these methods are not supported yet with the wcm.io mocking library (see [1]). I would raise a ticket there and ask about plans to support these methods.

 

 

[1] https://github.com/wcm-io/io.wcm.testing.aem-mock/blob/develop/core/src/main/java/io/wcm/testing/mock/aem/MockContentFragment_ContentVariation_Structured.java

 

 

Level 3
September 20, 2024

@joerghoh For Integers also its not supported. Can you help me understand how can I get it fixed for integer ?

 

Thanks in Advance! 

daniel-strmecki
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
September 20, 2024

Well, if it's not supported by AEM Mocks, you will need to mock them yourself. This is usually done with the Mockito library.

A good practice I use is to create mocks based on interfaces and then register them in the AEM context with a custom builder via:

this.aemContext.registerInjectActivateService(...)

 Since this doesn't look like a service, you need to use the old school mocking for your test.

 

Good luck,

Daniel