### Question:
VirtualFileRepoCacheImpl implements VirtualFileRepoCache, Disposable { @Nullable @Override public GitRepository getRepoForDir(@NotNull VirtualFile dir) { Preconditions.checkArgument(dir.isDirectory(), "%s is not a dir", dir); try { return dirsCache.get(dir).repository; } catch (ExecutionException e) { log.warn("Cannot compute repo for dir: " + dir, e); return null; } } VirtualFileRepoCacheImpl(@NotNull Project project); @NonInjectable  VirtualFileRepoCacheImpl(@NotNull VirtualFileRepoCacheLocalGateway gateway); @Override void dispose(); @Nullable @Override GitRepository getRepoForRoot(@NotNull VirtualFile root); @Nullable @Override GitRepository getRepoForDir(@NotNull VirtualFile dir); @Nullable @Override GitRepository getRepoForPath(@NotNull FilePath path); @Override void updatedRepoList(ImmutableList<GitRepository> repositories);  }### Answer:
@Test void getRepoForDirShouldReturnNullIfEmpty() { assertThat(cache.getRepoForDir(createDir("dir"))).isNull(); }
@Test void getRepoForDirShouldReturnRepositoryForDirInRoot() { setupRepo(); MockVirtualFile dirInRoot = createDir(repositoryRoot, "dirInRoot"); assertThat(cache.getRepoForDir(dirInRoot)).isEqualTo(repositoryMock); }
@Test void getRepoForDirShouldReturnSameRepositoryForDirInRootIfCalledMoreThanOnce() { setupRepo(); MockVirtualFile dirInRoot = createDir(repositoryRoot, "dirInRoot"); GitRepository repo1 = cache.getRepoForDir(dirInRoot); GitRepository repo2 = cache.getRepoForDir(dirInRoot); assertThat(repo1).isEqualTo(repo2); }
@Test void getRepoForDirShouldReturnRepositoryForDirInDirInRootBottomUp() { setupRepo(); MockVirtualFile dirInRoot = createDir(repositoryRoot, "dirInRoot"); MockVirtualFile dirInDirInRoot = createDir(dirInRoot, "dirInDirInRoot"); assertThat(cache.getRepoForDir(dirInDirInRoot)).isEqualTo(repositoryMock); }
@Test void getRepoForDirShouldReturnRepositoryForDirInDirInRootTopDown() { setupRepo(); MockVirtualFile dirInRoot = createDir(repositoryRoot, "dirInRoot"); MockVirtualFile dirInDirInRoot = createDir(dirInRoot, "dirInDirInRoot"); assertSoftly(softly -> { softly.assertThat(cache.getRepoForDir(dirInRoot)) .isEqualTo(repositoryMock); softly.assertThat(cache.getRepoForDir(dirInDirInRoot)) .isEqualTo(repositoryMock); }); }