1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.lib;
11
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertThrows;
14
15 import java.io.IOException;
16
17 import org.eclipse.jgit.api.errors.InvalidConfigurationException;
18 import org.eclipse.jgit.junit.RepositoryTestCase;
19 import org.eclipse.jgit.storage.file.FileBasedConfig;
20 import org.junit.Test;
21
22 public class AbbrevConfigTest extends RepositoryTestCase {
23
24 @Test
25 public void testDefault() throws Exception {
26 assertEquals(7, testCoreAbbrev(null));
27 }
28
29 @Test
30 public void testAuto() throws Exception {
31 assertEquals(7, testCoreAbbrev("auto"));
32 }
33
34 @Test
35 public void testNo() throws Exception {
36 assertEquals(40, testCoreAbbrev("no"));
37 }
38
39 @Test
40 public void testValidMin() throws Exception {
41 assertEquals(4, testCoreAbbrev("4"));
42 }
43
44 @Test
45 public void testValid() throws Exception {
46 assertEquals(22, testCoreAbbrev("22"));
47 }
48
49 @Test
50 public void testValidMax() throws Exception {
51 assertEquals(40, testCoreAbbrev("40"));
52 }
53
54 @Test
55 public void testInvalid() {
56 assertThrows(InvalidConfigurationException.class,
57 () -> testCoreAbbrev("foo"));
58 }
59
60 @Test
61 public void testInvalid2() {
62 assertThrows(InvalidConfigurationException.class,
63 () -> testCoreAbbrev("2k"));
64 }
65
66 @Test
67 public void testInvalidNegative() {
68 assertThrows(InvalidConfigurationException.class,
69 () -> testCoreAbbrev("-1000"));
70 }
71
72 @Test
73 public void testInvalidBelowRange() {
74 assertThrows(InvalidConfigurationException.class,
75 () -> testCoreAbbrev("3"));
76 }
77
78 @Test
79 public void testInvalidBelowRange2() {
80 assertThrows(InvalidConfigurationException.class,
81 () -> testCoreAbbrev("-1"));
82 }
83
84 @Test
85 public void testInvalidAboveRange() {
86 assertThrows(InvalidConfigurationException.class,
87 () -> testCoreAbbrev("41"));
88 }
89
90 @Test
91 public void testInvalidAboveRange2() {
92 assertThrows(InvalidConfigurationException.class,
93 () -> testCoreAbbrev("100000"));
94 }
95
96 @Test
97 public void testToStringNo()
98 throws InvalidConfigurationException, IOException {
99 assertEquals("40", setCoreAbbrev("no").toString());
100 }
101
102 @Test
103 public void testToString()
104 throws InvalidConfigurationException, IOException {
105 assertEquals("7", setCoreAbbrev("auto").toString());
106 }
107
108 @Test
109 public void testToString12()
110 throws InvalidConfigurationException, IOException {
111 assertEquals("12", setCoreAbbrev("12").toString());
112 }
113
114 private int testCoreAbbrev(String value)
115 throws InvalidConfigurationException, IOException {
116 return setCoreAbbrev(value).get();
117 }
118
119 private AbbrevConfig setCoreAbbrev(String value)
120 throws IOException, InvalidConfigurationException {
121 FileBasedConfig config = db.getConfig();
122 config.setString(ConfigConstants.CONFIG_CORE_SECTION, null,
123 ConfigConstants.CONFIG_KEY_ABBREV, value);
124 config.save();
125 return AbbrevConfig.parseFromConfig(db);
126 }
127
128 }