1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.revplot;
11
12 import static org.junit.Assert.assertEquals;
13
14 import java.util.LinkedList;
15 import java.util.List;
16
17 import org.eclipse.jgit.api.Git;
18 import org.eclipse.jgit.api.MergeCommand.FastForwardMode;
19 import org.eclipse.jgit.api.MergeResult;
20 import org.eclipse.jgit.api.errors.GitAPIException;
21 import org.eclipse.jgit.junit.RepositoryTestCase;
22 import org.eclipse.jgit.lib.ObjectId;
23 import org.eclipse.jgit.lib.Ref;
24 import org.junit.Before;
25 import org.junit.Test;
26
27 public class AbstractPlotRendererTest extends RepositoryTestCase {
28
29 private Git git;
30 private TestPlotRenderer plotRenderer;
31
32 @Override
33 @Before
34 public void setUp() throws Exception {
35 super.setUp();
36 git = new Git(db);
37 plotRenderer = new TestPlotRenderer();
38 }
39
40 @Test
41 public void testDrawTextAlignment() throws Exception {
42 git.commit().setMessage("initial commit").call();
43 git.branchCreate().setName("topic").call();
44 git.checkout().setName("topic").call();
45 git.commit().setMessage("commit 1 on topic").call();
46 git.commit().setMessage("commit 2 on topic").call();
47 git.checkout().setName("master").call();
48 git.commit().setMessage("commit on master").call();
49 MergeResult mergeCall = merge(db.resolve("topic"));
50 ObjectId start = mergeCall.getNewHead();
51 try (PlotWalk walk = new PlotWalk(db)) {
52 walk.markStart(walk.parseCommit(start));
53 PlotCommitList<PlotLane> commitList = new PlotCommitList<>();
54 commitList.source(walk);
55 commitList.fillTo(1000);
56
57 for (int i = 0; i < commitList.size(); i++)
58 plotRenderer.paintCommit(commitList.get(i), 30);
59
60 List<Integer> indentations = plotRenderer.indentations;
61 assertEquals(indentations.get(2), indentations.get(3));
62 }
63 }
64
65 private MergeResult merge(ObjectId includeId) throws GitAPIException {
66 return git.merge().setFastForward(FastForwardMode.NO_FF)
67 .include(includeId).call();
68 }
69
70 private static class TestPlotRenderer extends
71 AbstractPlotRenderer<PlotLane, Object> {
72
73 List<Integer> indentations = new LinkedList<>();
74
75 @Override
76 protected int drawLabel(int x, int y, Ref ref) {
77 return 0;
78 }
79
80 @Override
81 protected Object laneColor(PlotLane myLane) {
82 return null;
83 }
84
85 @Override
86 protected void drawLine(Object color, int x1, int y1, int x2, int y2,
87 int width) {
88
89 }
90
91 @Override
92 protected void drawCommitDot(int x, int y, int w, int h) {
93
94 }
95
96 @Override
97 protected void drawBoundaryDot(int x, int y, int w, int h) {
98
99 }
100
101 @Override
102 protected void drawText(String msg, int x, int y) {
103 indentations.add(Integer.valueOf(x));
104 }
105 }
106
107 }