aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SquashMessageFormatterTest.java
blob: 87674ebc46f42e248686955f32b82a65b20ecc25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
 * Copyright (C) 2012, IBM Corporation and others. and others
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Distribution License v. 1.0 which is available at
 * https://www.eclipse.org/org/documents/edl-v10.php.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */
package org.eclipse.jgit.merge;

import static org.junit.Assert.assertEquals;

import java.util.Arrays;

import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.test.resources.SampleDataRepositoryTestCase;
import org.eclipse.jgit.util.GitDateFormatter;
import org.eclipse.jgit.util.GitDateFormatter.Format;
import org.junit.Before;
import org.junit.Test;

/**
 * Test construction of squash message by {@link SquashMessageFormatterTest}.
 */
public class SquashMessageFormatterTest extends SampleDataRepositoryTestCase {
	private GitDateFormatter dateFormatter;
	private SquashMessageFormatter msgFormatter;
	private RevCommit revCommit;

	@Override
	@Before
	public void setUp() throws Exception {
		super.setUp();
		dateFormatter = new GitDateFormatter(Format.DEFAULT);
		msgFormatter = new SquashMessageFormatter();
	}

	@Test
	public void testCommit() throws Exception {
		try (Git git = new Git(db)) {
			revCommit = git.commit().setMessage("squash_me").call();

			Ref master = db.exactRef("refs/heads/master");
			String message = msgFormatter.format(Arrays.asList(revCommit), master);
			assertEquals(
					"Squashed commit of the following:\n\ncommit "
							+ revCommit.getName() + "\nAuthor: "
							+ revCommit.getAuthorIdent().getName() + " <"
							+ revCommit.getAuthorIdent().getEmailAddress()
							+ ">\nDate:   " + dateFormatter.formatDate(author)
							+ "\n\n\tsquash_me\n", message);
		}
	}
}