|
23 | 23 | */
|
24 | 24 | package org.opengrok.indexer.history;
|
25 | 25 |
|
26 |
| -import org.apache.commons.lang3.tuple.Pair; |
| 26 | +import org.apache.commons.lang3.tuple.Triple; |
27 | 27 | import org.junit.jupiter.api.AfterEach;
|
28 | 28 | import org.junit.jupiter.api.BeforeAll;
|
29 | 29 | import org.junit.jupiter.api.BeforeEach;
|
|
37 | 37 | import org.opengrok.indexer.util.Executor;
|
38 | 38 | import org.opengrok.indexer.util.IOUtils;
|
39 | 39 | import org.opengrok.indexer.util.TestRepository;
|
| 40 | +import org.opengrok.indexer.web.Util; |
40 | 41 |
|
41 | 42 | import java.io.File;
|
42 | 43 | import java.io.IOException;
|
@@ -435,25 +436,40 @@ void testAnnotationNegative() throws Exception {
|
435 | 436 | assertNull(annotation);
|
436 | 437 | }
|
437 | 438 |
|
438 |
| - private static Stream<Pair<String, List<String>>> provideParametersForPositiveAnnotationTest() { |
439 |
| - return Stream.of(Pair.of("8:6a8c423f5624", List.of("7", "8")), |
440 |
| - Pair.of("7:db1394c05268", List.of("7"))); |
| 439 | + private static Stream<Triple<String, List<String>, List<String>>> provideParametersForPositiveAnnotationTest() { |
| 440 | + return Stream.of(Triple.of("8:6a8c423f5624", List.of("7", "8"), List.of("8:6a8c423f5624", "7:db1394c05268")), |
| 441 | + Triple.of("7:db1394c05268", List.of("7"), List.of("7:db1394c05268"))); |
441 | 442 | }
|
442 | 443 |
|
443 | 444 | @ParameterizedTest
|
444 | 445 | @MethodSource("provideParametersForPositiveAnnotationTest")
|
445 |
| - void testAnnotationPositive(Pair<String, List<String>> pair) throws Exception { |
| 446 | + void testAnnotationPositive(Triple<String, List<String>, List<String>> triple) throws Exception { |
446 | 447 | MercurialRepository hgRepo = (MercurialRepository) RepositoryFactory.getRepository(repositoryRoot);
|
447 | 448 | assertNotNull(hgRepo);
|
448 | 449 | File file = new File(repositoryRoot, "novel.txt");
|
449 | 450 | assertTrue(file.exists());
|
450 | 451 | // The annotate() method calls uses HistoryGuru's getHistory() method which requires the RepositoryLookup
|
451 | 452 | // to be initialized. Do so via setRepositories().
|
452 | 453 | RuntimeEnvironment.getInstance().setRepositories(repository.getSourceRoot());
|
453 |
| - Annotation annotation = hgRepo.annotate(file, pair.getKey()); |
| 454 | + Annotation annotation = hgRepo.annotate(file, triple.getLeft()); |
454 | 455 | assertNotNull(annotation);
|
| 456 | + List<String> displayRevisions = new ArrayList<>(annotation.getDisplayRevisions()); |
| 457 | + assertEquals(triple.getMiddle(), displayRevisions); |
455 | 458 | List<String> revisions = new ArrayList<>(annotation.getRevisions());
|
456 |
| - assertEquals(pair.getValue(), revisions); |
| 459 | + assertEquals(triple.getRight(), revisions); |
| 460 | + History history = HistoryGuru.getInstance().getHistory(file); |
| 461 | + assertNotNull(history); |
| 462 | + assertFalse(history.getHistoryEntries().isEmpty()); |
| 463 | + HistoryGuru.completeAnnotationWithHistory(annotation, history, hgRepo); |
| 464 | + List<HistoryEntry> relevantEntries = history.getHistoryEntries().stream(). |
| 465 | + filter(e -> annotation.getRevisions().contains(e.getRevision())). |
| 466 | + collect(Collectors.toList()); |
| 467 | + assertFalse(relevantEntries.isEmpty()); |
| 468 | + for (HistoryEntry entry : relevantEntries) { |
| 469 | + assertTrue(annotation.getRevisions().contains(entry.getRevision())); |
| 470 | + assertEquals(entry.getDescription(), annotation.getDesc(entry.getRevision())); |
| 471 | + assertTrue(annotation.getAuthors().contains(Util.getEmail(entry.getAuthor()))); |
| 472 | + } |
457 | 473 | }
|
458 | 474 |
|
459 | 475 | /**
|
|
0 commit comments