1 package org
.spearce
.jgit
.lib
;
4 import java
.io
.IOException
;
7 * Test reading of git config
9 public class RepositoryConfigTest
extends RepositoryTestCase
{
11 * Read config item with no value from a section without a subsection.
15 public void test001_ReadBareKey() throws IOException
{
16 final File path
= writeTrashFile("config_001", "[foo]\nbar\n");
17 RepositoryConfig repositoryConfig
= new RepositoryConfig(null, path
);
18 System
.out
.println(repositoryConfig
.getString("foo", null, "bar"));
19 assertEquals(true, repositoryConfig
.getBoolean("foo", null, "bar", false));
20 assertEquals("", repositoryConfig
.getString("foo", null, "bar"));
24 * Read various data from a subsection.
28 public void test002_ReadWithSubsection() throws IOException
{
29 final File path
= writeTrashFile("config_002", "[foo \"zip\"]\nbar\n[foo \"zap\"]\nbar=false\nn=3\n");
30 RepositoryConfig repositoryConfig
= new RepositoryConfig(null, path
);
31 assertEquals(true, repositoryConfig
.getBoolean("foo", "zip", "bar", false));
32 assertEquals("", repositoryConfig
.getString("foo","zip", "bar"));
33 assertEquals(false, repositoryConfig
.getBoolean("foo", "zap", "bar", true));
34 assertEquals("false", repositoryConfig
.getString("foo", "zap", "bar"));
35 assertEquals(3, repositoryConfig
.getInt("foo", "zap", "n", 4));
36 assertEquals(4, repositoryConfig
.getInt("foo", "zap","m", 4));
39 public void test003_PutRemote() throws IOException
{
40 File cfgFile
= writeTrashFile("config_003", "");
41 RepositoryConfig repositoryConfig
= new RepositoryConfig(null, cfgFile
);
42 repositoryConfig
.putString("sec", "ext", "name", "value");
43 repositoryConfig
.putString("sec", "ext", "name2", "value2");
44 repositoryConfig
.save();
45 checkFile(cfgFile
, "[sec \"ext\"]\n\tname = value\n\tname2 = value2\n");
48 public void test004_PutSimple() throws IOException
{
49 File cfgFile
= writeTrashFile("config_004", "");
50 RepositoryConfig repositoryConfig
= new RepositoryConfig(null, cfgFile
);
51 repositoryConfig
.putString("my", null, "somename", "false");
52 repositoryConfig
.save();
53 checkFile(cfgFile
, "[my]\n\tsomename = false\n");