public Optional<File> get(InstalledPlugin plugin) {
    // Does not fail if another process tries to create the directory at the same time.
    Path jarInCache = jarInCache(plugin.key, plugin.hash);
    if (Files.isRegularFile(jarInCache)) {
      return Optional.of(jarInCache.toFile());
    }
    return download(plugin).map(Path::toFile);
  }
@Test
  void download_and_add_jar_to_cache_if_missing() throws Exception {
    FileAndMd5 tempJar = new FileAndMd5();
    stubDownload(tempJar);

    InstalledPlugin plugin = newInstalledPlugin("foo", tempJar.md5);
    File result = underTest.get(plugin).get();

    verifySameContent(result.toPath(), tempJar);

    sonarqube.verify(exactly(1), getRequestedFor(urlEqualTo("/api/plugins/download?plugin=foo")));

    // get from cache on second call
    result = underTest.get(plugin).get();
    verifySameContent(result.toPath(), tempJar);

    sonarqube.verify(exactly(1), getRequestedFor(urlEqualTo("/api/plugins/download?plugin=foo")));
  }