Skip to content

Commit 9d86925

Browse files
Vladimir Kotalahornace
authored andcommitted
add tests for getHistory()
1 parent 137b872 commit 9d86925

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import java.util.Arrays;
3939
import java.util.Collections;
4040
import java.util.List;
41+
import java.util.stream.Collectors;
4142

4243
import static org.junit.jupiter.api.Assertions.assertEquals;
4344
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -313,4 +314,57 @@ public void testGetHistoryWithNoSuchRevision() throws Exception {
313314
String constructedRevision = (number + 1) + ":" + hash;
314315
assertThrows(HistoryException.class, () -> mr.getHistory(root, constructedRevision));
315316
}
317+
318+
// TODO: also for (renamed) file
319+
@Test
320+
void testGetHistorySinceTillNullNull() throws Exception {
321+
File root = new File(repository.getSourceRoot(), "mercurial");
322+
MercurialRepository hgRepo = (MercurialRepository) RepositoryFactory.getRepository(root);
323+
History history = hgRepo.getHistory(root, null, null);
324+
assertNotNull(history);
325+
assertNotNull(history.getHistoryEntries());
326+
assertEquals(10, history.getHistoryEntries().size());
327+
List<String> revisions = history.getHistoryEntries().stream().map(HistoryEntry::getRevision).
328+
collect(Collectors.toList());
329+
assertEquals(List.of(REVISIONS), revisions);
330+
}
331+
332+
@Test
333+
void testGetHistorySinceTillNullRev() throws Exception {
334+
File root = new File(repository.getSourceRoot(), "mercurial");
335+
MercurialRepository hgRepo = (MercurialRepository) RepositoryFactory.getRepository(root);
336+
History history = hgRepo.getHistory(root, null, REVISIONS[4]);
337+
assertNotNull(history);
338+
assertNotNull(history.getHistoryEntries());
339+
assertEquals(6, history.getHistoryEntries().size());
340+
List<String> revisions = history.getHistoryEntries().stream().map(HistoryEntry::getRevision).
341+
collect(Collectors.toList());
342+
assertEquals(List.of(Arrays.copyOfRange(REVISIONS, 4, REVISIONS.length)), revisions);
343+
}
344+
345+
@Test
346+
void testGetHistorySinceTillRevNull() throws Exception {
347+
File root = new File(repository.getSourceRoot(), "mercurial");
348+
MercurialRepository hgRepo = (MercurialRepository) RepositoryFactory.getRepository(root);
349+
History history = hgRepo.getHistory(root, REVISIONS[3], null);
350+
assertNotNull(history);
351+
assertNotNull(history.getHistoryEntries());
352+
assertEquals(3, history.getHistoryEntries().size());
353+
List<String> revisions = history.getHistoryEntries().stream().map(HistoryEntry::getRevision).
354+
collect(Collectors.toList());
355+
assertEquals(List.of(Arrays.copyOfRange(REVISIONS, 0, 3)), revisions);
356+
}
357+
358+
@Test
359+
void testGetHistorySinceTillRevRev() throws Exception {
360+
File root = new File(repository.getSourceRoot(), "mercurial");
361+
MercurialRepository hgRepo = (MercurialRepository) RepositoryFactory.getRepository(root);
362+
History history = hgRepo.getHistory(root, REVISIONS[7], REVISIONS[2]);
363+
assertNotNull(history);
364+
assertNotNull(history.getHistoryEntries());
365+
assertEquals(5, history.getHistoryEntries().size());
366+
List<String> revisions = history.getHistoryEntries().stream().map(HistoryEntry::getRevision).
367+
collect(Collectors.toList());
368+
assertEquals(List.of(Arrays.copyOfRange(REVISIONS, 2, 7)), revisions);
369+
}
316370
}

0 commit comments

Comments
 (0)