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

JUnit Mock Test Case for Node Property

SantoshSai
Level 5
Level 5

Hi All,

Need a help to write a test case to check node property

Below is the method which is adding a property to the node

public Map addStyleProperty( List<String> assetStyles,Resource childToutNode){

Resource childPageResource = childToutNode.getParent();

childPageResource

String toutStyle = assetStyles.stream().collect(Collectors.joining(","));

//log.error("toutStyle {}", toutStyle);

//adding style property to the resource*/

try{

ModifiableValueMap properties = childPageResource.adaptTo(ModifiableValueMap.class);

properties.put("dummyStyle", toutStyle); //write

resourceResolver.commit();

return properties;

}

catch(Exception e){

log.error("Unable to add the style property to the resource {} with exception {}", childPageResource,e);

}

}

for this need to write a test case, please help me if any modification required in above let me know.

Below is the code for reference

   @Test

    public void testShopStylesException() throws  Exception, LoginException {

        Set<String> listStyles;

        Resource resource = resourceResolver.getResource(seasonPagePath);

        Page seasonPage = resource.adaptTo(Page.class);

        when(currentPage.getAbsoluteParent(2)).thenReturn(seasonPage);

        when(shopLookupService.fetchShopCodes(anyString(),anyString(),anyString())).thenThrow(IOException.class);

        //smartTile.activate();

        listStyles = smartTile.getShopStyleCodeList();

        assertTrue(listStyles.isEmpty());

    }

Thanks in Advance, Appreciate your help

0 Replies