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 package org.eclipse.jgit.lib;
44
45 import static org.junit.Assert.assertEquals;
46 import static org.junit.Assert.assertFalse;
47 import static org.junit.Assert.assertNull;
48 import static org.junit.Assert.assertTrue;
49 import static org.junit.Assert.fail;
50
51 import org.eclipse.jgit.errors.ConfigInvalidException;
52 import org.junit.Test;
53
54 public class GpgConfigTest {
55
56 private static Config parse(String content) throws ConfigInvalidException {
57 final Config c = new Config(null);
58 c.fromText(content);
59 return c;
60 }
61
62 @Test
63 public void isSignCommits_defaultIsFalse() throws Exception {
64 Config c = parse("");
65
66 assertFalse(new GpgConfig(c).isSignCommits());
67 }
68
69 @Test
70 public void isSignCommits_false() throws Exception {
71 Config c = parse(""
72 + "[gpg]\n"
73 + " format = x509\n"
74 + "[commit]\n"
75 + " gpgSign = false\n"
76 );
77
78 assertFalse(new GpgConfig(c).isSignCommits());
79 }
80
81 @Test
82 public void isSignCommits_true() throws Exception {
83 Config c = parse(""
84 + "[commit]\n"
85 + " gpgSign = true\n"
86 );
87
88 assertTrue(new GpgConfig(c).isSignCommits());
89 }
90
91 @Test
92 public void testGetKeyFormat_defaultsToOpenpgp() throws Exception {
93 Config c = parse("");
94
95 assertEquals(GpgConfig.GpgFormat.OPENPGP,
96 new GpgConfig(c).getKeyFormat());
97 }
98
99 @Test(expected = IllegalArgumentException.class)
100 public void testGetKeyFormat_failsForInvalidValue() throws Exception {
101 Config c = parse(""
102 + "[gpg]\n"
103 + " format = invalid\n"
104 );
105
106 new GpgConfig(c).getKeyFormat();
107 fail("Call should not have succeeded!");
108 }
109
110 @Test
111 public void testGetKeyFormat_openpgp() throws Exception {
112 Config c = parse(""
113 + "[gpg]\n"
114 + " format = openpgp\n"
115 );
116
117 assertEquals(GpgConfig.GpgFormat.OPENPGP,
118 new GpgConfig(c).getKeyFormat());
119 }
120
121 @Test
122 public void testGetKeyFormat_x509() throws Exception {
123 Config c = parse(""
124 + "[gpg]\n"
125 + " format = x509\n"
126 );
127
128 assertEquals(GpgConfig.GpgFormat.X509, new GpgConfig(c).getKeyFormat());
129 }
130
131 @Test
132 public void testGetSigningKey() throws Exception {
133 Config c = parse(""
134 + "[user]\n"
135 + " signingKey = 0x2345\n"
136 );
137
138 assertEquals("0x2345", new GpgConfig(c).getSigningKey());
139 }
140
141 @Test
142 public void testGetSigningKey_defaultToNull() throws Exception {
143 Config c = parse("");
144
145 assertNull(new GpgConfig(c).getSigningKey());
146 }
147 }