@Override
    public Collection<PluginDescriptor> findPlugins() throws IOException {

        if (!Files.isDirectory(pluginsRootDir)) {
            throw new IOException(
                    "Plugins root directory [" + pluginsRootDir + "] does not exist!");
        }
        try (Stream<Path> stream = Files.list(pluginsRootDir)) {
            return stream.filter((Path path) -> Files.isDirectory(path))
                    .map(
                            FunctionUtils.uncheckedFunction(
                                    this::createPluginDescriptorForSubDirectory))
                    .collect(Collectors.toList());
        }
    }
@Test
    void createPluginDescriptorsForDirectory() throws Exception {
        File rootFolder = TempDirUtils.newFolder(tempFolder);
        PluginFinder descriptorsFactory = new DirectoryBasedPluginFinder(rootFolder.toPath());
        Collection<PluginDescriptor> actual = descriptorsFactory.findPlugins();

        assertThat(actual).isEmpty();

        List<File> subDirs =
                Stream.of("A", "B", "C")
                        .map(s -> new File(rootFolder, s))
                        .collect(Collectors.toList());

        for (File subDir : subDirs) {
            Preconditions.checkState(subDir.mkdirs());
        }

        assertThatThrownBy(descriptorsFactory::findPlugins)
                .isInstanceOf(RuntimeException.class)
                .hasCauseInstanceOf(IOException.class);

        for (File subDir : subDirs) {
            // we create a file and another subfolder to check that they are ignored
            Preconditions.checkState(new File(subDir, "ignore-test.zip").createNewFile());
            Preconditions.checkState(new File(subDir, "ignore-dir").mkdirs());
        }

        assertThatThrownBy(descriptorsFactory::findPlugins)
                .isInstanceOf(RuntimeException.class)
                .hasCauseInstanceOf(IOException.class);

        List<PluginDescriptor> expected = new ArrayList<>(3);

        for (int i = 0; i < subDirs.size(); ++i) {
            File subDir = subDirs.get(i);
            URL[] jarURLs = new URL[i + 1];

            for (int j = 0; j <= i; ++j) {
                File file = new File(subDir, "jar-file-" + j + ".jar");
                Preconditions.checkState(file.createNewFile());
                jarURLs[j] = file.toURI().toURL();
            }

            Arrays.sort(jarURLs, Comparator.comparing(URL::toString));
            expected.add(new PluginDescriptor(subDir.getName(), jarURLs, new String[0]));
        }

        actual = descriptorsFactory.findPlugins();

        assertThat(equalsIgnoreOrder(expected, new ArrayList<>(actual))).isTrue();
    }