FileSystemDeleteWorker { protected void removeSpaceDirectory(final Space space) { try { Collection<Repository> repositories = this.repositoryService.getAllRepositories(space, true); repositories.forEach(repository -> this.removeRepository(repository)); SpaceConfigStorageImpl configStorage = (SpaceConfigStorageImpl) this.registry.get(space.getName()); final Path configPath = configStorage.getPath(); final File spacePath = getSpacePath(configPath.getFileSystem().getPath("/")); final Path configFSPath = configPath.getFileSystem().getPath("/"); this.ioService.deleteIfExists(configFSPath); this.registry.remove(space.getName()); this.delete(spacePath); this.removeSpaceFromConfigurationService(space); } catch (Exception e) { ifDebugEnabled(logger, () -> logger.error("A problem occurred when trying to delete " + space.getName() + " space", 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 testRemoveSpaceDirectory() throws IOException { JGitPathImpl configPath = mock(JGitPathImpl.class, RETURNS_DEEP_STUBS); Space space = mock(Space.class); Path deletePath = mock(Path.class, RETURNS_DEEP_STUBS); when(configPath.getFileSystem().getPath(anyString())).thenReturn(deletePath); SpaceConfigStorageImpl configStorage = mock(SpaceConfigStorageImpl.class); when(configStorage.getPath()).thenReturn(configPath); when(registry.get(any())).thenReturn(configStorage); doReturn(Collections.singletonList(mock(Repository.class))) .when(this.repoService) .getAllRepositories(eq(space), eq(true)); doReturn(configPath).when(ioService).get(any()); File spacePathFile = mock(File.class); doReturn(spacePathFile).when(worker).getSpacePath(any()); this.worker.removeSpaceDirectory(space); verify(this.worker, times(1)).removeRepository(any()); verify(ioService).deleteIfExists(deletePath); verify(this.worker).delete(spacePathFile); }