@Override
  @SuppressWarnings("unchecked")
  public CalendarEventModel apply(Map<String, Object> event, TransformerContext context) {
    if (!"singleInstance"
        .equals(event.get("type"))) { // support single instances for now;recurring events later
      return null;
    }
    String calendarId = context.getProperty(CALENDAR_ID);

    String title = (String) event.getOrDefault("subject", "");
    String location = TransformerHelper.getOrDefault("location", "displayName", event, "");

    // Notes is itemBody resource type defined as: { "content": "string",  "contentType": "String"}
    String notes = TransformerHelper.getOrDefault("body", "content", event, "");

    List<Map<String, Object>> rawAttendees =
        (List<Map<String, Object>>) event.getOrDefault("attendees", emptyList());
    List<CalendarAttendeeModel> attendees = new ArrayList<>();
    for (Object rawAttendee : rawAttendees) {
      CalendarAttendeeModel attendee = context.transform(CalendarAttendeeModel.class, rawAttendee);
      if (attendee != null) {
        attendees.add(attendee);
      }
    }

    CalendarEventModel.CalendarEventTime startTime =
        context.transform(CalendarEventModel.CalendarEventTime.class, event.get("start"));
    if (startTime == null) {
      context.problem("Could not parse start time. Skipping event.");
      return null;
    }

    CalendarEventModel.CalendarEventTime endTime =
        context.transform(CalendarEventModel.CalendarEventTime.class, event.get("end"));
    if (endTime == null) {
      context.problem("Could not parse end time. Skipping event.");
      return null;
    }

    return new CalendarEventModel(
        calendarId, title, notes, attendees, location, startTime, endTime, null);
  }
@SuppressWarnings("unchecked")
  @Test
  public void testTransform() throws IOException {
    context.setProperty(CALENDAR_ID, "123");
    Map<String, Object> rawEvent = mapper.readValue(SAMPLE_CALENDAR_EVENT, Map.class);

    CalendarEventModel event = transformer.apply(rawEvent, context);

    assertEquals("123", event.getCalendarId());

    assertEquals("Some Place", event.getLocation());
    assertEquals("Test Appointment 1", event.getTitle());
    assertTrue(event.getNotes().length() > 5);
    assertEquals(1, event.getAttendees().size());

    CalendarAttendeeModel attendee = event.getAttendees().get(0);
    assertEquals("Test Test1", attendee.getDisplayName());
    assertEquals("foo@foo.com", attendee.getEmail());
    assertFalse(attendee.getOptional());

    assertEquals(18, event.getStartTime().getDateTime().getHour());
    assertEquals(0, event.getStartTime().getDateTime().getMinute());

    assertEquals(18, event.getEndTime().getDateTime().getHour());
    assertEquals(30, event.getEndTime().getDateTime().getMinute());
  }