### Question:
SendTemplatedEmailUtils { protected static final Map<String, String> getPayloadProperties(Resource payloadRes, SimpleDateFormat sdf) { Map<String, String> emailParams = new HashMap<String, String>(); if (payloadRes == null) { return emailParams; } if (DamUtil.isAsset(payloadRes)) { Resource mdRes = payloadRes.getChild(JcrConstants.JCR_CONTENT + "/" + DamConstants.METADATA_FOLDER); Map<String, String> assetMetadata = getJcrKeyValuePairs(mdRes, sdf); emailParams.putAll(assetMetadata); } else { Page payloadPage = payloadRes.adaptTo(Page.class); if (payloadPage != null) { Map<String, String> pageContent = getJcrKeyValuePairs(payloadPage.getContentResource(), sdf); emailParams.putAll(pageContent); } } return emailParams; } private  SendTemplatedEmailUtils();   }### Answer:
@Test public void testGetPayloadProperties_NullResource() throws Exception { Resource payloadRes = mock(Resource.class); Map<String, String> props = SendTemplatedEmailUtils.getPayloadProperties(payloadRes, sdf); assertEquals(0, props.size()); }
@Test public void testGetPayloadProperties_Asset() throws Exception { mockJcrProperties(); Resource payloadRes = mock(Resource.class); Resource mdRes = mock(Resource.class); when(payloadRes.getResourceType()).thenReturn("dam:Asset"); when(payloadRes.getChild(JcrConstants.JCR_CONTENT + "/" + DamConstants.METADATA_FOLDER)).thenReturn(mdRes); when(mdRes.getValueMap()).thenReturn(vmap); Map<String, String> props = SendTemplatedEmailUtils.getPayloadProperties(payloadRes, sdf); assertEquals(props.get(PN_CALENDAR), CALENDAR_TOSTRING); assertEquals(props.get(PN_TITLE), STR_TOSTRING); assertEquals(props.get(PN_LONG), LONG_TOSTRING); assertEquals(props.get(PN_STR_ARRAY), STR_ARRAY_TOSTRING); }
@Test public void testGetPayloadProperties_Page() throws Exception { mockJcrProperties(); Resource payloadRes = mock(Resource.class); Resource jcrRes = mock(Resource.class); Page payloadPage = mock(Page.class); when(payloadRes.adaptTo(Page.class)).thenReturn(payloadPage); when(payloadPage.getContentResource()).thenReturn(jcrRes); when(jcrRes.getValueMap()).thenReturn(vmap); Map<String, String> props = SendTemplatedEmailUtils.getPayloadProperties(payloadRes, sdf); assertEquals(props.get(PN_CALENDAR), CALENDAR_TOSTRING); assertEquals(props.get(PN_TITLE), STR_TOSTRING); assertEquals(props.get(PN_LONG), LONG_TOSTRING); assertEquals(props.get(PN_STR_ARRAY), STR_ARRAY_TOSTRING); }