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

ContentElement getValue is not mocked properly in io.wcm.testing (UnsupportedOperationException)

Avatar

Level 1

Hi Community, 

 

I'm currently creating a Unit Test that uses the Object Content Element, coming from the content fragment.getElements().

 

I'm currently using Junit5 to create my Unit Tests and the io.wcm.testing framework. 

 

I was checking the mocked class for the ContentElement that is inside that package, and I found that this method getValue() is always throwing this exception:

class MockContentFragment_ContentElement_Structured extends MockContentFragment_Versionable implements ContentElement {
public FragmentData getValue() {
throw new UnsupportedOperationException();
}
}

So, when I try to do the following behaviour, I always get this exception: 

while(contentElement.hasNext()) {
ContentElement contentElementObject = contentElement.next();
FragmentData value = contentElementObject.getValue(); <---- Exception (So test failed)
String fieldName = contentElementObject.getName();
String fieldValue = getValueFromBranch(fullBranch, fieldName);
value.setValue(fieldValue);
contentElementObject.setValue(value);
}

Do you know if there is any way I can fake the getValue() output to continue with fake data within the test?

This is the Content Element class:

@ProviderType
public interface ContentElement extends Adaptable, Versionable {
Iterator<ContentVariation> getVariations();

@Nullable
ContentVariation getVariation(String var1);

ContentVariation createVariation(VariationTemplate var1) throws ContentFragmentException;

void removeVariation(ContentVariation var1) throws ContentFragmentException;

ContentVariation getResolvedVariation(String var1);

String getName();

String getTitle();

FragmentData getValue();

void setValue(FragmentData var1) throws ContentFragmentException;

String getContent();

String getContentType();

void setContent(String var1, String var2) throws ContentFragmentException;
}

 

0 Replies