aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/CommitTemplateConfigTest.java60
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java27
2 files changed, 61 insertions, 26 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/CommitTemplateConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/CommitTemplateConfigTest.java
new file mode 100644
index 0000000000..6dbe30af2d
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/CommitTemplateConfigTest.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2021 SAP SE 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.lib;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.eclipse.jgit.errors.ConfigInvalidException;
+import org.eclipse.jgit.junit.JGitTestUtil;
+import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+/*
+ * This test was moved from ConfigTest to allow skipping it when running the
+ * test using bazel which doesn't allow tests to create files in the home
+ * directory
+ */
+public class CommitTemplateConfigTest {
+
+ @Rule
+ public TemporaryFolder tmp = new TemporaryFolder();
+
+ @Test
+ public void testCommitTemplatePathInHomeDirecory()
+ throws ConfigInvalidException, IOException {
+ Config config = new Config(null);
+ File tempFile = tmp.newFile("testCommitTemplate-");
+ File workTree = tmp.newFolder("dummy-worktree");
+ Repository repo = FileRepositoryBuilder.create(workTree);
+ String templateContent = "content of the template";
+ JGitTestUtil.write(tempFile, templateContent);
+ // proper evaluation of the ~/ directory
+ String homeDir = System.getProperty("user.home");
+ File tempFileInHomeDirectory = File.createTempFile("fileInHomeFolder",
+ ".tmp", new File(homeDir));
+ tempFileInHomeDirectory.deleteOnExit();
+ JGitTestUtil.write(tempFileInHomeDirectory, templateContent);
+ String expectedTemplatePath = tempFileInHomeDirectory.getPath()
+ .replace(homeDir, "~");
+ config = ConfigTest
+ .parse("[commit]\n\ttemplate = " + expectedTemplatePath + "\n");
+ String templatePath = config.get(CommitConfig.KEY)
+ .getCommitTemplatePath();
+ assertEquals(expectedTemplatePath, templatePath);
+ assertEquals(templateContent,
+ config.get(CommitConfig.KEY).getCommitTemplateContent(repo));
+ }
+}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
index 9ee54d5b60..9b82c2afd6 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java
@@ -1177,7 +1177,7 @@ public class ConfigTest {
assertEquals(exp, c.getLong("s", null, "a", 0L));
}
- private static Config parse(String content)
+ static Config parse(String content)
throws ConfigInvalidException {
return parse(content, null);
}
@@ -1546,31 +1546,6 @@ public class ConfigTest {
"utf-8", commitEncoding);
}
- @Test
- public void testCommitTemplatePathInHomeDirecory()
- throws ConfigInvalidException, IOException {
- Config config = new Config(null);
- File tempFile = tmp.newFile("testCommitTemplate-");
- File workTree = tmp.newFolder("dummy-worktree");
- Repository repo = FileRepositoryBuilder.create(workTree);
- String templateContent = "content of the template";
- JGitTestUtil.write(tempFile, templateContent);
- // proper evaluation of the ~/ directory
- String homeDir = System.getProperty("user.home");
- File tempFileInHomeDirectory = File.createTempFile("fileInHomeFolder",
- ".tmp", new File(homeDir));
- tempFileInHomeDirectory.deleteOnExit();
- JGitTestUtil.write(tempFileInHomeDirectory, templateContent);
- String expectedTemplatePath = tempFileInHomeDirectory.getPath()
- .replace(homeDir, "~");
- config = parse("[commit]\n\ttemplate = " + expectedTemplatePath + "\n");
- String templatePath = config.get(CommitConfig.KEY)
- .getCommitTemplatePath();
- assertEquals(expectedTemplatePath, templatePath);
- assertEquals(templateContent,
- config.get(CommitConfig.KEY).getCommitTemplateContent(repo));
- }
-
@Test(expected = ConfigInvalidException.class)
public void testCommitTemplateWithInvalidEncoding()
throws ConfigInvalidException, IOException {