| | |
| | | */
|
| | | package com.gitblit.tests;
|
| | |
|
| | | import junit.framework.TestCase;
|
| | | import static org.junit.Assert.assertEquals;
|
| | | import static org.junit.Assert.assertTrue;
|
| | |
|
| | | import java.util.List;
|
| | |
|
| | | import org.eclipse.jgit.lib.Repository;
|
| | | import org.eclipse.jgit.revwalk.RevCommit;
|
| | | import org.junit.Test;
|
| | |
|
| | | import com.gitblit.models.AnnotatedLine;
|
| | | import com.gitblit.utils.DiffUtils;
|
| | | import com.gitblit.utils.DiffUtils.DiffOutputType;
|
| | | import com.gitblit.utils.JGitUtils;
|
| | |
|
| | | public class DiffUtilsTest extends TestCase {
|
| | | public class DiffUtilsTest {
|
| | |
|
| | | @Test
|
| | | public void testDiffOutputTypes() throws Exception {
|
| | | assertEquals(DiffOutputType.PLAIN, DiffOutputType.forName("plain"));
|
| | | assertEquals(DiffOutputType.GITWEB, DiffOutputType.forName("gitweb"));
|
| | | assertEquals(DiffOutputType.GITBLIT, DiffOutputType.forName("gitblit"));
|
| | | assertEquals(null, DiffOutputType.forName(null));
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testParentCommitDiff() throws Exception {
|
| | | Repository repository = GitBlitSuite.getHelloworldRepository();
|
| | | RevCommit commit = JGitUtils.getCommit(repository,
|
| | |
| | | assertTrue(diff.indexOf(expected) > -1);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testArbitraryCommitDiff() throws Exception {
|
| | | Repository repository = GitBlitSuite.getHelloworldRepository();
|
| | | RevCommit baseCommit = JGitUtils.getCommit(repository,
|
| | |
| | | assertTrue(diff.indexOf(expected) > -1);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testPlainFileDiff() throws Exception {
|
| | | Repository repository = GitBlitSuite.getHelloworldRepository();
|
| | | RevCommit commit = JGitUtils.getCommit(repository,
|
| | |
| | | assertTrue(diff.indexOf(expected) > -1);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testFilePatch() throws Exception {
|
| | | Repository repository = GitBlitSuite.getHelloworldRepository();
|
| | | RevCommit commit = JGitUtils.getCommit(repository,
|
| | |
| | | assertTrue(patch.indexOf(expected) > -1);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testArbitraryFilePatch() throws Exception {
|
| | | Repository repository = GitBlitSuite.getHelloworldRepository();
|
| | | RevCommit baseCommit = JGitUtils.getCommit(repository,
|
| | |
| | | assertTrue(patch.indexOf(expected) > -1);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testArbitraryCommitPatch() throws Exception {
|
| | | Repository repository = GitBlitSuite.getHelloworldRepository();
|
| | | RevCommit baseCommit = JGitUtils.getCommit(repository,
|
| | |
| | | String expected = "- system.out.println(\"Hello World\");\n+ System.out.println(\"Hello World\"";
|
| | | assertTrue(patch.indexOf(expected) > -1);
|
| | | }
|
| | |
|
| | | @Test
|
| | | public void testBlame() throws Exception {
|
| | | Repository repository = GitBlitSuite.getHelloworldRepository();
|
| | | List<AnnotatedLine> lines = DiffUtils.blame(repository, "java.java",
|
| | | "1d0c2933a4ae69c362f76797d42d6bd182d05176");
|
| | | repository.close();
|
| | | assertTrue(lines.size() > 0);
|
| | | assertEquals("c6d31dccf5cc75e8e46299fc62d38f60ec6d41e0", lines.get(0).commitId);
|
| | | }
|
| | | }
|