FileSystemDeleteWorker { protected void removeAllDeletedSpaces() { try { ifDebugEnabled(logger, () -> logger.debug("Removing all deleted spaces")); Collection<OrganizationalUnit> deletedSpaces = this.organizationalUnitService.getAllDeletedOrganizationalUnit(); ifDebugEnabled(logger, () -> logger.debug("Found {} spaces to be deleted", deletedSpaces.size())); deletedSpaces.forEach(ou -> this.removeSpaceDirectory(ou.getSpace())); if (deletedSpaces.size() > 0) { this.removeOrganizationalUnitEvent.fire(new RemoveOrganizationalUnitEvent()); } ifDebugEnabled(logger, () -> logger.debug("Deleted spaces had been removed")); } catch (Exception e) { ifDebugEnabled(logger, () -> logger.error("Error when trying to remove all deleted Spaces", e)); } } FileSystemDeleteWorker(); @Inject  FileSystemDeleteWorker(@Named("ioStrategy") final IOService ioService,
                                  final OrganizationalUnitService organizationalUnitService,
                                  final RepositoryService repositoryService,
                                  final @Named("systemFS") FileSystem systemFS,
                                  final SpaceConfigStorageRegistry registry,
                                  final Event<RemoveOrganizationalUnitEvent> removeOrganizationalUnitEvent,
                                  final ConfigurationService configurationService); @Schedule(hour = "*", minute = CRON_MINUTES, persistent = false) void doRemove(); static final String CRON_MINUTES; }
@Test public void testRemoveAllDeletedSpaces() { doAnswer(invocation -> null).when(worker).removeSpaceDirectory(any()); OrganizationalUnit ou1 = mock(OrganizationalUnit.class); doReturn(mock(Space.class)).when(ou1).getSpace(); OrganizationalUnit ou2 = mock(OrganizationalUnit.class); doReturn(mock(Space.class)).when(ou2).getSpace(); List<OrganizationalUnit> orgUnits = Arrays.asList(ou1, ou2); doReturn(orgUnits).when(this.ouService).getAllDeletedOrganizationalUnit(); this.worker.removeAllDeletedSpaces(); verify(this.worker, times(1)).removeSpaceDirectory(ou1.getSpace()); verify(this.worker, times(1)).removeSpaceDirectory(ou2.getSpace()); verify(this.removeOrganizationalUnitEvent, times(1)).fire(any()); }