@Test public void testPurgeCalendars_closed_appointmentInstance() throws Exception { mockStatic(CalendarFolder.class, Appointment.class); when(mockedEm.createQuery(anyString(), eq(AcmContainerEntity.class))).thenReturn(mockedQuery); when(mockedQuery.getResultList()).thenReturn(Arrays.asList(mockedContainerEntity)); when(mockedContainerEntity.getContainer()).thenReturn(mockedContainer); when(mockedContainer.getCalendarFolderId()).thenReturn("folderId"); when(CalendarFolder.bind(eq(mockedService), any(FolderId.class))).thenReturn(mockedFolder); when(mockedFolder.findAppointments(any(CalendarView.class))).thenReturn(mockedFindResults); ArrayList<Appointment> itemList = new ArrayList<>(); itemList.add(mockedAppointment); when(mockedFindResults.getItems()).thenReturn(itemList); when(mockedAppointment.getId()).thenReturn(mockedItemId); when(mockedItemId.getUniqueId()).thenReturn(UNIQUE_ITEM_ID); when(mockedAppointment.getIsRecurring()).thenReturn(false); when(mockedServiceConnector.connect(any(Long.class))).thenReturn(Optional.of(mockedService)); entityHandler.purgeCalendars(mockedServiceConnector, PurgeOptions.CLOSED, null); verify(mockedEm).createQuery( String.format("SELECT obj FROM %s obj WHERE obj.status IN :statuses AND obj.container.calendarFolderId IS NOT NULL", ENTITY_TYPE_FOR_QUERY), AcmContainerEntity.class); verify(mockedQuery).setParameter("statuses", closedStates); verify(mockedQuery).getResultList(); verify(mockedAuditPropertyEntityAdapter).setUserId(PROCESS_USER); verify(mockedOutlookDao).deleteAppointmentItem(mockedService, UNIQUE_ITEM_ID, false, DeleteMode.MoveToDeletedItems); verify(mockedFolder).delete(DeleteMode.MoveToDeletedItems); verify(mockedContainer).setCalendarFolderId(null); verify(mockedContainerEntityDao).save(mockedContainer); }
void purgeCalendars(ServiceConnector connector, PurgeOptions purgeOptions, Integer daysClosed) { switch (purgeOptions) { case RETAIN_INDEFINITELY: return; case CLOSED: case CLOSED_X_DAYS: List<AcmContainerEntity> purgeCandidates = getEntities(daysClosed); purgeCalendars(connector, purgeCandidates); break; } }
CalendarEntityHandler { void purgeCalendars(ServiceConnector connector, PurgeOptions purgeOptions, Integer daysClosed) { switch (purgeOptions) { case RETAIN_INDEFINITELY: return; case CLOSED: case CLOSED_X_DAYS: List<AcmContainerEntity> purgeCandidates = getEntities(daysClosed); purgeCalendars(connector, purgeCandidates); break; } } }
CalendarEntityHandler { void purgeCalendars(ServiceConnector connector, PurgeOptions purgeOptions, Integer daysClosed) { switch (purgeOptions) { case RETAIN_INDEFINITELY: return; case CLOSED: case CLOSED_X_DAYS: List<AcmContainerEntity> purgeCandidates = getEntities(daysClosed); purgeCalendars(connector, purgeCandidates); break; } } CalendarEntityHandler(); }
CalendarEntityHandler { void purgeCalendars(ServiceConnector connector, PurgeOptions purgeOptions, Integer daysClosed) { switch (purgeOptions) { case RETAIN_INDEFINITELY: return; case CLOSED: case CLOSED_X_DAYS: List<AcmContainerEntity> purgeCandidates = getEntities(daysClosed); purgeCalendars(connector, purgeCandidates); break; } } CalendarEntityHandler(); void setOutlookDao(OutlookDao outlookDao); void setContainerEntityDao(AcmContainerDao containerEntityDao); void setAuditPropertyEntityAdapter(AuditPropertyEntityAdapter auditPropertyEntityAdapter); void setClosedStates(String closedStates); void setEntityType(String entityType); void setEntityTypeForQuery(String entityTypeForQuery); void setEntityIdForQuery(String entityIdForQuery); void setPermissionEvaluator(PermissionEvaluator permissionEvaluator); void setReadPermission(Object readPermission); void setWritePermission(Object writePermission); void setDeletePermission(Object deletePermission); void setFolderCreatorDao(AcmOutlookFolderCreatorDao folderCreatorDao); String getEntityType(); }
CalendarEntityHandler { void purgeCalendars(ServiceConnector connector, PurgeOptions purgeOptions, Integer daysClosed) { switch (purgeOptions) { case RETAIN_INDEFINITELY: return; case CLOSED: case CLOSED_X_DAYS: List<AcmContainerEntity> purgeCandidates = getEntities(daysClosed); purgeCalendars(connector, purgeCandidates); break; } } CalendarEntityHandler(); void setOutlookDao(OutlookDao outlookDao); void setContainerEntityDao(AcmContainerDao containerEntityDao); void setAuditPropertyEntityAdapter(AuditPropertyEntityAdapter auditPropertyEntityAdapter); void setClosedStates(String closedStates); void setEntityType(String entityType); void setEntityTypeForQuery(String entityTypeForQuery); void setEntityIdForQuery(String entityIdForQuery); void setPermissionEvaluator(PermissionEvaluator permissionEvaluator); void setReadPermission(Object readPermission); void setWritePermission(Object writePermission); void setDeletePermission(Object deletePermission); void setFolderCreatorDao(AcmOutlookFolderCreatorDao folderCreatorDao); String getEntityType();  }