Skip to content

Commit 8dc1fbc

Browse files
Vladimir Kotalahornace
authored andcommitted
add test for renamed file
1 parent 6e4cba9 commit 8dc1fbc

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

opengrok-indexer/src/test/java/org/opengrok/indexer/history/MercurialRepositoryTest.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.junit.jupiter.api.BeforeEach;
2828
import org.junit.jupiter.api.Test;
2929
import org.opengrok.indexer.condition.EnabledForRepository;
30+
import org.opengrok.indexer.configuration.RuntimeEnvironment;
3031
import org.opengrok.indexer.util.Executor;
3132
import org.opengrok.indexer.util.TestRepository;
3233

@@ -44,6 +45,7 @@
4445
import static org.junit.jupiter.api.Assertions.assertNotNull;
4546
import static org.junit.jupiter.api.Assertions.assertNotSame;
4647
import static org.junit.jupiter.api.Assertions.assertThrows;
48+
import static org.junit.jupiter.api.Assertions.assertTrue;
4749
import static org.opengrok.indexer.condition.RepositoryInstalled.Type.MERCURIAL;
4850

4951
/**
@@ -314,7 +316,6 @@ public void testGetHistoryWithNoSuchRevision() throws Exception {
314316
assertThrows(HistoryException.class, () -> mr.getHistory(root, constructedRevision));
315317
}
316318

317-
// TODO: also for (renamed) file
318319
@Test
319320
void testGetHistorySinceTillNullNull() throws Exception {
320321
File root = new File(repository.getSourceRoot(), "mercurial");
@@ -366,4 +367,20 @@ void testGetHistorySinceTillRevRev() throws Exception {
366367
collect(Collectors.toList());
367368
assertEquals(List.of(Arrays.copyOfRange(REVISIONS, 2, 7)), revisions);
368369
}
370+
371+
@Test
372+
void testGetHistoryRenamedFileTillRev() throws Exception {
373+
RuntimeEnvironment.getInstance().setHandleHistoryOfRenamedFiles(true);
374+
File root = new File(repository.getSourceRoot(), "mercurial");
375+
File file = new File(root, "novel.txt");
376+
assertTrue(file.exists() && file.isFile());
377+
MercurialRepository hgRepo = (MercurialRepository) RepositoryFactory.getRepository(root);
378+
History history = hgRepo.getHistory(file, null, "7:db1394c05268");
379+
assertNotNull(history);
380+
assertNotNull(history.getHistoryEntries());
381+
assertEquals(5, history.getHistoryEntries().size());
382+
List<String> revisions = history.getHistoryEntries().stream().map(HistoryEntry::getRevision).
383+
collect(Collectors.toList());
384+
assertEquals(List.of(Arrays.copyOfRange(REVISIONS, 2, 7)), revisions);
385+
}
369386
}

0 commit comments

Comments
 (0)