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.

SquashMessageFormatterTest.java 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (C) 2012, IBM Corporation and others. 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.merge;
  11. import static org.junit.Assert.assertEquals;
  12. import java.util.Arrays;
  13. import org.eclipse.jgit.api.Git;
  14. import org.eclipse.jgit.lib.Ref;
  15. import org.eclipse.jgit.revwalk.RevCommit;
  16. import org.eclipse.jgit.test.resources.SampleDataRepositoryTestCase;
  17. import org.eclipse.jgit.util.GitDateFormatter;
  18. import org.eclipse.jgit.util.GitDateFormatter.Format;
  19. import org.junit.Before;
  20. import org.junit.Test;
  21. /**
  22. * Test construction of squash message by {@link SquashMessageFormatterTest}.
  23. */
  24. public class SquashMessageFormatterTest extends SampleDataRepositoryTestCase {
  25. private GitDateFormatter dateFormatter;
  26. private SquashMessageFormatter msgFormatter;
  27. private RevCommit revCommit;
  28. @Override
  29. @Before
  30. public void setUp() throws Exception {
  31. super.setUp();
  32. dateFormatter = new GitDateFormatter(Format.DEFAULT);
  33. msgFormatter = new SquashMessageFormatter();
  34. }
  35. @Test
  36. public void testCommit() throws Exception {
  37. try (Git git = new Git(db)) {
  38. revCommit = git.commit().setMessage("squash_me").call();
  39. Ref master = db.exactRef("refs/heads/master");
  40. String message = msgFormatter.format(Arrays.asList(revCommit), master);
  41. assertEquals(
  42. "Squashed commit of the following:\n\ncommit "
  43. + revCommit.getName() + "\nAuthor: "
  44. + revCommit.getAuthorIdent().getName() + " <"
  45. + revCommit.getAuthorIdent().getEmailAddress()
  46. + ">\nDate: " + dateFormatter.formatDate(author)
  47. + "\n\n\tsquash_me\n", message);
  48. }
  49. }
  50. }