Expand my Community achievements bar.

SOLVED

contentFragment Element getValue unit test unsupported operation

Avatar

Level 7

Hi,

 

any example to unit test 

 

contentElement.getValue().getValue(String[].class);

 

I am getting io.wcm unsupported operation exception, when trying to unit test this specific line of code. 

 

Thanks,

Sri

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Yeah I got this problem too, I fixed it by refactoring the code, and broke it up.

 

 

String[] cfNamesArray = contentFragment.map(cf -> cf.getElement("names")).map(ContentElement::getContent)
                .filter(StringUtils::isNotEmpty)
                .map(names -> names.split(","))
                .orElse(null);

 

 

View solution in original post

4 Replies

Avatar

Correct answer by
Community Advisor

Yeah I got this problem too, I fixed it by refactoring the code, and broke it up.

 

 

String[] cfNamesArray = contentFragment.map(cf -> cf.getElement("names")).map(ContentElement::getContent)
                .filter(StringUtils::isNotEmpty)
                .map(names -> names.split(","))
                .orElse(null);

 

 

Avatar

Community Advisor

Hello @sreenu539 - 

 

I see the same has been reported here https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/java-lang-unsupportedopera... 

 

Looks like these methods are not supported yet with the wcm.io mocking library & I see the issue is listed here https://github.com/wcm-io/io.wcm.testing.aem-mock/issues/15 still in progress.