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.

AbstractPlotRendererTest.java 2.9KB

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