You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RevCommitListTest.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright (C) 2012, Matthias Sohn <matthias.sohn@sap.com> and others
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the Eclipse Distribution License v. 1.0 which is available at
  6. * https://www.eclipse.org/org/documents/edl-v10.php.
  7. *
  8. * SPDX-License-Identifier: BSD-3-Clause
  9. */
  10. package org.eclipse.jgit.revwalk;
  11. import static org.junit.Assert.assertEquals;
  12. import static org.junit.Assert.assertNotNull;
  13. import static org.junit.Assert.assertNull;
  14. import org.eclipse.jgit.api.Git;
  15. import org.eclipse.jgit.junit.RepositoryTestCase;
  16. import org.eclipse.jgit.lib.Constants;
  17. import org.eclipse.jgit.lib.ObjectId;
  18. import org.junit.Test;
  19. public class RevCommitListTest extends RepositoryTestCase {
  20. private RevCommitList<RevCommit> list;
  21. public void setup(int count) throws Exception {
  22. try (Git git = new Git(db);
  23. RevWalk w = new RevWalk(db);) {
  24. for (int i = 0; i < count; i++)
  25. git.commit().setCommitter(committer).setAuthor(author)
  26. .setMessage("commit " + i).call();
  27. list = new RevCommitList<>();
  28. w.markStart(w.lookupCommit(db.resolve(Constants.HEAD)));
  29. list.source(w);
  30. }
  31. }
  32. @Test
  33. public void testFillToHighMark2() throws Exception {
  34. setup(3);
  35. list.fillTo(1);
  36. assertEquals(2, list.size());
  37. assertEquals("commit 2", list.get(0).getFullMessage());
  38. assertEquals("commit 1", list.get(1).getFullMessage());
  39. assertNull("commit 0 shouldn't be loaded", list.get(2));
  40. }
  41. @Test
  42. public void testFillToHighMarkAll() throws Exception {
  43. setup(3);
  44. list.fillTo(2);
  45. assertEquals(3, list.size());
  46. assertEquals("commit 2", list.get(0).getFullMessage());
  47. assertEquals("commit 0", list.get(2).getFullMessage());
  48. }
  49. @Test
  50. public void testFillToHighMark4() throws Exception {
  51. setup(3);
  52. list.fillTo(3);
  53. assertEquals(3, list.size());
  54. assertEquals("commit 2", list.get(0).getFullMessage());
  55. assertEquals("commit 0", list.get(2).getFullMessage());
  56. assertNull("commit 3 can't be loaded", list.get(3));
  57. }
  58. @Test
  59. public void testFillToHighMarkMulitpleBlocks() throws Exception {
  60. setup(258);
  61. list.fillTo(257);
  62. assertEquals(258, list.size());
  63. }
  64. @Test
  65. public void testFillToCommit() throws Exception {
  66. setup(3);
  67. try (RevWalk w = new RevWalk(db)) {
  68. w.markStart(w.lookupCommit(db.resolve(Constants.HEAD)));
  69. w.next();
  70. RevCommit c = w.next();
  71. assertNotNull("should have found 2. commit", c);
  72. list.fillTo(c, 5);
  73. assertEquals(2, list.size());
  74. assertEquals("commit 1", list.get(1).getFullMessage());
  75. assertNull(list.get(3));
  76. }
  77. }
  78. @Test
  79. public void testFillToUnknownCommit() throws Exception {
  80. setup(258);
  81. RevCommit c = new RevCommit(
  82. ObjectId.fromString("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
  83. list.fillTo(c, 300);
  84. assertEquals("loading to unknown commit should load all commits", 258,
  85. list.size());
  86. }
  87. @Test
  88. public void testFillToNullCommit() throws Exception {
  89. setup(3);
  90. list.fillTo(null, 1);
  91. assertNull(list.get(0));
  92. }
  93. }