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