From af31a97c82eb1a213fbc853daf9e9cab68bceccb Mon Sep 17 00:00:00 2001 From: Mathias Kinzler Date: Fri, 5 Nov 2010 12:26:56 +0100 Subject: [PATCH] CommitAndLogCommandTests: add a test for LogCommand.addRange() There were also some compiler warning due to empty catch blocks that were fixed. Change-Id: I165bcddcdfacd34f020d1b938a41954916eb106e Signed-off-by: Mathias Kinzler --- .../jgit/api/CommitAndLogCommandTests.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java index 9106cc2c0..3d7f77972 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitAndLogCommandTests.java @@ -53,6 +53,8 @@ import org.eclipse.jgit.api.errors.NoFilepatternException; import org.eclipse.jgit.api.errors.NoHeadException; import org.eclipse.jgit.api.errors.NoMessageException; import org.eclipse.jgit.api.errors.WrongRepositoryStateException; +import org.eclipse.jgit.errors.IncorrectObjectTypeException; +import org.eclipse.jgit.errors.MissingObjectException; import org.eclipse.jgit.errors.UnmergedPathException; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.ObjectId; @@ -105,6 +107,7 @@ public class CommitAndLogCommandTests extends RepositoryTestCase { git.commit().setAuthor(author).call(); fail("Didn't get the expected exception"); } catch (NoMessageException e) { + // expected } } @@ -122,6 +125,7 @@ public class CommitAndLogCommandTests extends RepositoryTestCase { commitCmd.setAuthor(author); fail("didn't catch the expected exception"); } catch (IllegalStateException e) { + // expected } LogCommand logCmd = git.log(); logCmd.call(); @@ -130,6 +134,7 @@ public class CommitAndLogCommandTests extends RepositoryTestCase { logCmd.call(); fail("didn't catch the expected exception"); } catch (IllegalStateException e) { + // expected } } @@ -191,4 +196,39 @@ public class CommitAndLogCommandTests extends RepositoryTestCase { assertEquals("db00fd65b218578127ea51f3dffac701f12f486a", tw.getObjectId(0).getName()); } + + public void testCommitRange() throws NoHeadException, NoMessageException, + UnmergedPathException, ConcurrentRefUpdateException, + JGitInternalException, WrongRepositoryStateException, + IncorrectObjectTypeException, MissingObjectException { + // do 4 commits and set the range to the second and fourth one + Git git = new Git(db); + git.commit().setMessage("first commit").call(); + RevCommit second = git.commit().setMessage("second commit") + .setCommitter(committer).call(); + git.commit().setMessage("third commit").setAuthor(author).call(); + RevCommit last = git.commit().setMessage("fourth commit").setAuthor( + author) + .setCommitter(committer).call(); + Iterable commits = git.log().addRange(second.getId(), + last.getId()).call(); + + // check that we have the third and fourth commit + PersonIdent defaultCommitter = new PersonIdent(db); + PersonIdent expectedAuthors[] = new PersonIdent[] { author, author }; + PersonIdent expectedCommitters[] = new PersonIdent[] { + defaultCommitter, committer }; + String expectedMessages[] = new String[] { "third commit", + "fourth commit" }; + int l = expectedAuthors.length - 1; + for (RevCommit c : commits) { + assertEquals(expectedAuthors[l].getName(), c.getAuthorIdent() + .getName()); + assertEquals(expectedCommitters[l].getName(), c.getCommitterIdent() + .getName()); + assertEquals(c.getFullMessage(), expectedMessages[l]); + l--; + } + assertEquals(l, -1); + } }