|
32 | 32 | import org.opengrok.indexer.util.TestRepository;
|
33 | 33 |
|
34 | 34 | import java.io.File;
|
| 35 | +import java.nio.file.Paths; |
35 | 36 | import java.util.ArrayList;
|
36 | 37 | import java.util.List;
|
37 | 38 |
|
38 | 39 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
| 40 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
39 | 41 | import static org.junit.jupiter.api.Assertions.assertNotNull;
|
40 | 42 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
41 | 43 | import static org.mockito.ArgumentMatchers.any;
|
| 44 | +import static org.mockito.ArgumentMatchers.anyString; |
| 45 | +import static org.mockito.ArgumentMatchers.isNull; |
42 | 46 | import static org.mockito.Mockito.times;
|
43 | 47 |
|
44 | 48 | public class RepositoryWithPerPartesHistoryTest {
|
@@ -98,4 +102,29 @@ void testChangesets() throws HistoryException {
|
98 | 102 | tillRevisions.add(null);
|
99 | 103 | assertEquals(tillRevisions, stringArgumentCaptor2.getAllValues());
|
100 | 104 | }
|
| 105 | + |
| 106 | + /** |
| 107 | + * Test a (perceived) corner case to simulate there is exactly one "incoming" changeset |
| 108 | + * for a repository with per partes history handling. This changeset has to be stored in history cache. |
| 109 | + * @throws Exception on error |
| 110 | + */ |
| 111 | + @Test |
| 112 | + void testPseudoIncomingChangeset() throws Exception { |
| 113 | + FileHistoryCache cache = new FileHistoryCache(); |
| 114 | + GitRepository gitSpyRepository = Mockito.spy(gitRepository); |
| 115 | + Mockito.when(gitSpyRepository.getPerPartesCount()).thenReturn(3); |
| 116 | + List<HistoryEntry> historyEntries = gitRepository.getHistory(new File(gitRepository.getDirectoryName())). |
| 117 | + getHistoryEntries(); |
| 118 | + assertFalse(historyEntries.isEmpty()); |
| 119 | + |
| 120 | + gitSpyRepository.createCache(cache, historyEntries.get(1).getRevision()); |
| 121 | + Mockito.verify(gitSpyRepository, times(1)). |
| 122 | + getHistory(any(), anyString(), isNull()); |
| 123 | + assertEquals(historyEntries.get(0).getRevision(), cache.getLatestCachedRevision(gitSpyRepository)); |
| 124 | + History cachedHistory = cache.get(Paths.get(gitRepository.getDirectoryName(), "moved2", "renamed2.c").toFile(), |
| 125 | + gitSpyRepository, false); |
| 126 | + assertNotNull(cachedHistory); |
| 127 | + assertEquals(1, cachedHistory.getHistoryEntries().size()); |
| 128 | + assertEquals(historyEntries.get(0).getRevision(), cachedHistory.getHistoryEntries().get(0).getRevision()); |
| 129 | + } |
101 | 130 | }
|
0 commit comments