|
18 | 18 | */
|
19 | 19 |
|
20 | 20 | /*
|
21 |
| - * Copyright (c) 2009, 2023, Oracle and/or its affiliates. All rights reserved. |
| 21 | + * Copyright (c) 2009, 2024, Oracle and/or its affiliates. All rights reserved. |
22 | 22 | * Portions Copyright (c) 2017, Chris Fraire <[email protected]>.
|
23 | 23 | */
|
24 | 24 | package org.opengrok.indexer.history;
|
25 | 25 |
|
| 26 | +import org.apache.commons.lang3.tuple.Pair; |
26 | 27 | import org.junit.jupiter.api.AfterEach;
|
27 | 28 | import org.junit.jupiter.api.BeforeEach;
|
28 | 29 | import org.junit.jupiter.api.Test;
|
29 | 30 | import org.junit.jupiter.params.ParameterizedTest;
|
| 31 | +import org.junit.jupiter.params.provider.MethodSource; |
30 | 32 | import org.junit.jupiter.params.provider.ValueSource;
|
31 | 33 | import org.opengrok.indexer.condition.EnabledForRepository;
|
32 | 34 | import org.opengrok.indexer.configuration.RuntimeEnvironment;
|
|
43 | 45 | import java.util.Collections;
|
44 | 46 | import java.util.List;
|
45 | 47 | import java.util.stream.Collectors;
|
| 48 | +import java.util.stream.Stream; |
46 | 49 |
|
47 | 50 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
| 51 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
48 | 52 | import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
49 | 53 | import static org.junit.jupiter.api.Assertions.assertNotNull;
|
50 | 54 | import static org.junit.jupiter.api.Assertions.assertNotSame;
|
| 55 | +import static org.junit.jupiter.api.Assertions.assertNull; |
51 | 56 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
52 | 57 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
53 | 58 | import static org.opengrok.indexer.condition.RepositoryInstalled.Type.MERCURIAL;
|
@@ -255,7 +260,7 @@ void testGetHistoryGet() throws Exception {
|
255 | 260 | * Test that it is possible to get contents of multiple revisions of a file.
|
256 | 261 | */
|
257 | 262 | @Test
|
258 |
| - void testgetHistoryGetForAll() throws Exception { |
| 263 | + void testGetHistoryGetForAll() throws Exception { |
259 | 264 | MercurialRepository mr = (MercurialRepository) RepositoryFactory.getRepository(repositoryRoot);
|
260 | 265 |
|
261 | 266 | for (String rev : REVISIONS_novel) {
|
@@ -406,4 +411,34 @@ void testMergeCommits(boolean isMergeCommitsEnabled) throws Exception {
|
406 | 411 | // Cleanup.
|
407 | 412 | env.setMergeCommitsEnabled(isMergeCommitsEnabledOrig);
|
408 | 413 | }
|
| 414 | + |
| 415 | + @Test |
| 416 | + void testAnnotationNegative() throws Exception { |
| 417 | + MercurialRepository hgRepo = (MercurialRepository) RepositoryFactory.getRepository(repositoryRoot); |
| 418 | + File file = new File(repositoryRoot, "nonexistent"); |
| 419 | + assertFalse(file.exists()); |
| 420 | + Annotation annotation = hgRepo.annotate(file, null); |
| 421 | + assertNull(annotation); |
| 422 | + } |
| 423 | + |
| 424 | + private static Stream<Pair<String, List<String>>> provideParametersForPositiveAnnotationTest() { |
| 425 | + return Stream.of(Pair.of("8:6a8c423f5624", List.of("7", "8")), |
| 426 | + Pair.of("7:db1394c05268", List.of("7"))); |
| 427 | + } |
| 428 | + |
| 429 | + @ParameterizedTest |
| 430 | + @MethodSource("provideParametersForPositiveAnnotationTest") |
| 431 | + void testAnnotationPositive(Pair<String, List<String>> pair) throws Exception { |
| 432 | + MercurialRepository hgRepo = (MercurialRepository) RepositoryFactory.getRepository(repositoryRoot); |
| 433 | + assertNotNull(hgRepo); |
| 434 | + File file = new File(repositoryRoot, "novel.txt"); |
| 435 | + assertTrue(file.exists()); |
| 436 | + // The annotate() method calls uses HistoryGuru's getHistory() method which requires the RepositoryLookup |
| 437 | + // to be initialized. Do so via setRepositories(). |
| 438 | + RuntimeEnvironment.getInstance().setRepositories(repository.getSourceRoot()); |
| 439 | + Annotation annotation = hgRepo.annotate(file, pair.getKey()); |
| 440 | + assertNotNull(annotation); |
| 441 | + List<String> revisions = new ArrayList<>(annotation.getRevisions()); |
| 442 | + assertEquals(pair.getValue(), revisions); |
| 443 | + } |
409 | 444 | }
|
0 commit comments