@Test void history() { final Repository repo = setMockNames(newCachingRepo()); final List<Commit> commits = ImmutableList.of( new Commit(new Revision(3), SYSTEM, "third", "", Markup.MARKDOWN), new Commit(new Revision(3), SYSTEM, "second", "", Markup.MARKDOWN), new Commit(new Revision(3), SYSTEM, "first", "", Markup.MARKDOWN)); doReturn(new RevisionRange(3, 1)).when(delegateRepo).normalizeNow(HEAD, INIT); doReturn(new RevisionRange(3, 1)).when(delegateRepo).normalizeNow(HEAD, new Revision(-3)); doReturn(new RevisionRange(3, 1)).when(delegateRepo).normalizeNow(new Revision(3), new Revision(-3)); doReturn(new RevisionRange(3, 1)).when(delegateRepo).normalizeNow(new Revision(3), INIT); when(delegateRepo.history(any(), any(), any(), anyInt())).thenReturn(completedFuture(commits)); assertThat(repo.history(HEAD, INIT, "/**", Integer.MAX_VALUE).join()).isEqualTo(commits); verify(delegateRepo).history(new Revision(3), INIT, "/**", 3); verifyNoMoreInteractions(delegateRepo); clearInvocations(delegateRepo); assertThat(repo.history(HEAD, new Revision(-3), "/**", 3).join()).isEqualTo(commits); assertThat(repo.history(HEAD, INIT, "/**", 4).join()).isEqualTo(commits); assertThat(repo.history(new Revision(3), new Revision(-3), "/**", 5).join()).isEqualTo(commits); assertThat(repo.history(new Revision(3), INIT, "/**", 6).join()).isEqualTo(commits); verify(delegateRepo, never()).history(any(), any(), any(), anyInt()); verifyNoMoreInteractions(delegateRepo); }
@Override public CompletableFuture<List<Commit>> history(Revision from, Revision to, String pathPattern, int maxCommits) { requireNonNull(from, "from"); requireNonNull(to, "to"); requireNonNull(pathPattern, "pathPattern"); if (maxCommits <= 0) { throw new IllegalArgumentException("maxCommits: " + maxCommits + " (expected: > 0)"); } final RevisionRange range = normalizeNow(from, to); final int actualMaxCommits = Math.min( maxCommits, Math.abs(range.from().major() - range.to().major()) + 1); return cache.get(new CacheableHistoryCall(repo, range.from(), range.to(), pathPattern, actualMaxCommits)); }
CachingRepository implements Repository { @Override public CompletableFuture<List<Commit>> history(Revision from, Revision to, String pathPattern, int maxCommits) { requireNonNull(from, "from"); requireNonNull(to, "to"); requireNonNull(pathPattern, "pathPattern"); if (maxCommits <= 0) { throw new IllegalArgumentException("maxCommits: " + maxCommits + " (expected: > 0)"); } final RevisionRange range = normalizeNow(from, to); final int actualMaxCommits = Math.min( maxCommits, Math.abs(range.from().major() - range.to().major()) + 1); return cache.get(new CacheableHistoryCall(repo, range.from(), range.to(), pathPattern, actualMaxCommits)); } }
CachingRepository implements Repository { @Override public CompletableFuture<List<Commit>> history(Revision from, Revision to, String pathPattern, int maxCommits) { requireNonNull(from, "from"); requireNonNull(to, "to"); requireNonNull(pathPattern, "pathPattern"); if (maxCommits <= 0) { throw new IllegalArgumentException("maxCommits: " + maxCommits + " (expected: > 0)"); } final RevisionRange range = normalizeNow(from, to); final int actualMaxCommits = Math.min( maxCommits, Math.abs(range.from().major() - range.to().major()) + 1); return cache.get(new CacheableHistoryCall(repo, range.from(), range.to(), pathPattern, actualMaxCommits)); } CachingRepository(Repository repo, RepositoryCache cache); }
CachingRepository implements Repository { @Override public CompletableFuture<List<Commit>> history(Revision from, Revision to, String pathPattern, int maxCommits) { requireNonNull(from, "from"); requireNonNull(to, "to"); requireNonNull(pathPattern, "pathPattern"); if (maxCommits <= 0) { throw new IllegalArgumentException("maxCommits: " + maxCommits + " (expected: > 0)"); } final RevisionRange range = normalizeNow(from, to); final int actualMaxCommits = Math.min( maxCommits, Math.abs(range.from().major() - range.to().major()) + 1); return cache.get(new CacheableHistoryCall(repo, range.from(), range.to(), pathPattern, actualMaxCommits)); } CachingRepository(Repository repo, RepositoryCache cache); @Override long creationTimeMillis(); @Override Author author(); @Override CompletableFuture<Entry<T>> getOrNull(Revision revision, Query<T> query); @Override CompletableFuture<Map<String, Entry<?>>> find(Revision revision, String pathPattern,
                                                         Map<FindOption<?>, ?> options); @Override CompletableFuture<List<Commit>> history(Revision from, Revision to,
                                                   String pathPattern, int maxCommits); @Override CompletableFuture<Change<?>> diff(Revision from, Revision to, Query<?> query); @Override CompletableFuture<Map<String, Change<?>>> diff(Revision from, Revision to, String pathPattern); @Override CompletableFuture<Revision> findLatestRevision(Revision lastKnownRevision, String pathPattern); @Override CompletableFuture<Revision> watch(Revision lastKnownRevision, String pathPattern); @Override Project parent(); @Override String name(); @Override Revision normalizeNow(Revision revision); @Override RevisionRange normalizeNow(Revision from, Revision to); @Override CompletableFuture<Map<String, Change<?>>> previewDiff(Revision baseRevision,
                                                                 Iterable<Change<?>> changes); @Override CompletableFuture<Revision> commit(Revision baseRevision, long commitTimeMillis,
                                              Author author, String summary, String detail, Markup markup,
                                              Iterable<Change<?>> changes); @Override CompletableFuture<MergedEntry<T>> mergeFiles(Revision revision, MergeQuery<T> query); @Override String toString(); }
CachingRepository implements Repository { @Override public CompletableFuture<List<Commit>> history(Revision from, Revision to, String pathPattern, int maxCommits) { requireNonNull(from, "from"); requireNonNull(to, "to"); requireNonNull(pathPattern, "pathPattern"); if (maxCommits <= 0) { throw new IllegalArgumentException("maxCommits: " + maxCommits + " (expected: > 0)"); } final RevisionRange range = normalizeNow(from, to); final int actualMaxCommits = Math.min( maxCommits, Math.abs(range.from().major() - range.to().major()) + 1); return cache.get(new CacheableHistoryCall(repo, range.from(), range.to(), pathPattern, actualMaxCommits)); } CachingRepository(Repository repo, RepositoryCache cache); @Override long creationTimeMillis(); @Override Author author(); @Override CompletableFuture<Entry<T>> getOrNull(Revision revision, Query<T> query); @Override CompletableFuture<Map<String, Entry<?>>> find(Revision revision, String pathPattern,
                                                         Map<FindOption<?>, ?> options); @Override CompletableFuture<List<Commit>> history(Revision from, Revision to,
                                                   String pathPattern, int maxCommits); @Override CompletableFuture<Change<?>> diff(Revision from, Revision to, Query<?> query); @Override CompletableFuture<Map<String, Change<?>>> diff(Revision from, Revision to, String pathPattern); @Override CompletableFuture<Revision> findLatestRevision(Revision lastKnownRevision, String pathPattern); @Override CompletableFuture<Revision> watch(Revision lastKnownRevision, String pathPattern); @Override Project parent(); @Override String name(); @Override Revision normalizeNow(Revision revision); @Override RevisionRange normalizeNow(Revision from, Revision to); @Override CompletableFuture<Map<String, Change<?>>> previewDiff(Revision baseRevision,
                                                                 Iterable<Change<?>> changes); @Override CompletableFuture<Revision> commit(Revision baseRevision, long commitTimeMillis,
                                              Author author, String summary, String detail, Markup markup,
                                              Iterable<Change<?>> changes); @Override CompletableFuture<MergedEntry<T>> mergeFiles(Revision revision, MergeQuery<T> query); @Override String toString();  }