@SuppressWarnings("unchecked")
 private <AdapterType> AdapterType getAdapter(
     final Resource resource, final Class<AdapterType> type) {
   if (type == Page.class && isPrimaryType(resource, NameConstants.NT_PAGE)) {
     return (AdapterType) new MockPage(resource);
   }
   if (type == Template.class && isPrimaryType(resource, NameConstants.NT_TEMPLATE)) {
     return (AdapterType) new MockTemplate(resource);
   }
   if (type == Asset.class && DamUtil.isAsset(resource)) {
     return (AdapterType) new MockAsset(resource);
   }
   if (type == Rendition.class && DamUtil.isRendition(resource)) {
     return (AdapterType) new MockRendition(resource);
   }
   if (type == Tag.class && isPrimaryType(resource, TagConstants.NT_TAG)) {
     return (AdapterType) new MockTag(resource);
   }
   return null;
 }
  @Test
  public void testGetPayloadProperties_Asset() throws Exception {

    // set up jcr properties
    mockJcrProperties();

    Resource payloadRes = mock(Resource.class);
    Resource mdRes = mock(Resource.class);
    when(DamUtil.isAsset(payloadRes)).thenReturn(true);

    when(payloadRes.getChild(JcrConstants.JCR_CONTENT + "/" + DamConstants.METADATA_FOLDER))
        .thenReturn(mdRes);

    // mock valueMap
    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 {

    // set up jcr properties
    mockJcrProperties();

    Resource payloadRes = mock(Resource.class);
    Resource jcrRes = mock(Resource.class);
    when(DamUtil.isAsset(payloadRes)).thenReturn(false);

    Page payloadPage = mock(Page.class);
    when(payloadRes.adaptTo(Page.class)).thenReturn(payloadPage);
    when(payloadPage.getContentResource()).thenReturn(jcrRes);

    // mock valueMap
    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);
  }