public List<String> deleteUnusedFileDistributionReferences(FileDirectory fileDirectory, Duration keepFileReferencesDuration) {
        Set<String> fileReferencesInUse = getFileReferencesInUse();
        log.log(Level.FINE, () -> "File references in use : " + fileReferencesInUse);
        Instant instant = clock.instant().minus(keepFileReferencesDuration);
        log.log(Level.FINE, () -> "Remove unused file references last modified before " + instant);

        List<String> fileReferencesToDelete = sortedUnusedFileReferences(fileDirectory.getRoot(), fileReferencesInUse, instant);
        // Do max 20 at a time
        var toDelete = fileReferencesToDelete.subList(0, Math.min(fileReferencesToDelete.size(), 20));
        if (toDelete.size() > 0) {
            log.log(Level.FINE, () -> "Will delete file references not in use: " + toDelete);
            toDelete.forEach(fileReference -> fileDirectory.delete(new FileReference(fileReference), this::isFileReferenceInUse));
            log.log(Level.FINE, () -> "Deleted " + toDelete.size() + " file references not in use");
        }
        return toDelete;
    }
@Test
    public void deleteUnusedFileReferences() {
        File fileReferencesDir = new File(configserverConfig.fileReferencesDir());
        Duration keepFileReferencesDuration = Duration.ofSeconds(4);

        // Add file reference that is not in use and should be deleted (older than 'keepFileReferencesDuration')
        File filereferenceDirOldest = createFileReferenceOnDisk(new File(fileReferencesDir, "bar"));
        clock.advance(Duration.ofSeconds(1));

        // Add file references that are not in use should be deleted (baz0 and baz1)
        IntStream.range(0, 2).forEach(i -> {
            createFileReferenceOnDisk(new File(fileReferencesDir, "baz" + i));
            clock.advance(Duration.ofSeconds(1));
        });
        clock.advance(keepFileReferencesDuration);

        // Add file reference that is not in use, but should not be deleted (newer than 'keepFileReferencesDuration')
        File filereferenceDirNewest = createFileReferenceOnDisk(new File(fileReferencesDir, "foo"));

        applicationRepository = new ApplicationRepository.Builder()
                .withTenantRepository(tenantRepository)
                .withOrchestrator(orchestrator)
                .withClock(clock)
                .build();

        // TODO: Deploy an app with a bundle or file that will be a file reference, too much missing in test setup to get this working now
        // PrepareParams prepareParams = new PrepareParams.Builder().applicationId(applicationId()).ignoreValidationErrors(true).build();
        // deployApp(new File("src/test/apps/app"), prepareParams);

        List<String> deleted = applicationRepository.deleteUnusedFileDistributionReferences(fileDirectory, keepFileReferencesDuration);
        List<String> expected = List.of("bar", "baz0", "baz1");
        assertEquals(expected.stream().sorted().toList(), deleted.stream().sorted().toList());
        // bar, baz0 and baz1 will be deleted and foo is not old enough to be considered
        assertFalse(filereferenceDirOldest.exists());
        assertFalse(new File(fileReferencesDir, "baz0").exists());
        assertFalse(new File(fileReferencesDir, "baz1").exists());
        assertTrue(filereferenceDirNewest.exists());
    }