1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.lib;
12
13 import static org.junit.Assert.assertEquals;
14
15 import java.io.File;
16 import java.io.IOException;
17
18 import org.eclipse.jgit.errors.ConfigInvalidException;
19 import org.eclipse.jgit.junit.JGitTestUtil;
20 import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
21 import org.junit.Rule;
22 import org.junit.Test;
23 import org.junit.rules.TemporaryFolder;
24
25
26
27
28
29
30 public class CommitTemplateConfigTest {
31
32 @Rule
33 public TemporaryFolder tmp = new TemporaryFolder();
34
35 @Test
36 public void testCommitTemplatePathInHomeDirecory()
37 throws ConfigInvalidException, IOException {
38 Config config = new Config(null);
39 File tempFile = tmp.newFile("testCommitTemplate-");
40 File workTree = tmp.newFolder("dummy-worktree");
41 Repository repo = FileRepositoryBuilder.create(workTree);
42 String templateContent = "content of the template";
43 JGitTestUtil.write(tempFile, templateContent);
44
45 String homeDir = System.getProperty("user.home");
46 File tempFileInHomeDirectory = File.createTempFile("fileInHomeFolder",
47 ".tmp", new File(homeDir));
48 tempFileInHomeDirectory.deleteOnExit();
49 JGitTestUtil.write(tempFileInHomeDirectory, templateContent);
50 String expectedTemplatePath = "~/" + tempFileInHomeDirectory.getName();
51 config = ConfigTest
52 .parse("[commit]\n\ttemplate = " + expectedTemplatePath + "\n");
53 String templatePath = config.get(CommitConfig.KEY)
54 .getCommitTemplatePath();
55 assertEquals(expectedTemplatePath, templatePath);
56 assertEquals(templateContent,
57 config.get(CommitConfig.KEY).getCommitTemplateContent(repo));
58 }
59 }