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
44 package org.eclipse.jgit.util;
45
46 import static org.junit.Assert.assertFalse;
47 import static org.junit.Assert.assertTrue;
48
49 import java.io.File;
50 import java.io.IOException;
51 import java.nio.file.Files;
52 import java.nio.file.Path;
53
54 import org.eclipse.jgit.junit.MockSystemReader;
55 import org.eclipse.jgit.lib.ConfigConstants;
56 import org.eclipse.jgit.storage.file.FileBasedConfig;
57 import org.junit.After;
58 import org.junit.Before;
59 import org.junit.Test;
60
61 public class FS_POSIXTest {
62 private FileBasedConfig jgitConfig;
63
64 private FileBasedConfig systemConfig;
65
66 private FileBasedConfig userConfig;
67
68 private Path tmp;
69
70 @Before
71 public void setUp() throws Exception {
72 tmp = Files.createTempDirectory("jgit_test_");
73
74 MockSystemReader mockSystemReader = new MockSystemReader();
75 SystemReader.setInstance(mockSystemReader);
76
77
78
79
80
81 FS.getFileStoreAttributes(tmp.getParent());
82
83 jgitConfig = new FileBasedConfig(new File(tmp.toFile(), "jgitconfig"),
84 FS.DETECTED);
85 systemConfig = new FileBasedConfig(jgitConfig,
86 new File(tmp.toFile(), "systemgitconfig"), FS.DETECTED);
87 userConfig = new FileBasedConfig(systemConfig,
88 new File(tmp.toFile(), "usergitconfig"), FS.DETECTED);
89
90
91
92
93 userConfig.setBoolean(ConfigConstants.CONFIG_GC_SECTION, null,
94 ConfigConstants.CONFIG_KEY_AUTODETACH, false);
95 userConfig.save();
96 mockSystemReader.setJGitConfig(jgitConfig);
97 mockSystemReader.setSystemGitConfig(systemConfig);
98 mockSystemReader.setUserGitConfig(userConfig);
99 }
100
101 @After
102 public void tearDown() throws IOException {
103 SystemReader.setInstance(null);
104 FileUtils.delete(tmp.toFile(), FileUtils.RECURSIVE | FileUtils.RETRY);
105 }
106
107 @Test
108 public void supportsAtomicCreateNewFile_shouldReturnSupportedAsDefault() {
109 assertTrue(new FS_POSIX().supportsAtomicCreateNewFile());
110 }
111
112 @Test
113 public void supportsAtomicCreateNewFile_shouldReturnTrueIfFlagIsSetInUserConfig() {
114 setAtomicCreateCreationFlag(userConfig, "true");
115 assertTrue(new FS_POSIX().supportsAtomicCreateNewFile());
116 }
117
118 @Test
119 public void supportsAtomicCreateNewFile_shouldReturnTrueIfFlagIsSetInSystemConfig() {
120 setAtomicCreateCreationFlag(systemConfig, "true");
121 assertTrue(new FS_POSIX().supportsAtomicCreateNewFile());
122 }
123
124 @Test
125 public void supportsAtomicCreateNewFile_shouldReturnFalseIfFlagUnsetInUserConfig() {
126 setAtomicCreateCreationFlag(userConfig, "false");
127 assertFalse(new FS_POSIX().supportsAtomicCreateNewFile());
128 }
129
130 @Test
131 public void supportsAtomicCreateNewFile_shouldReturnFalseIfFlagUnsetInSystemConfig() {
132 setAtomicCreateCreationFlag(systemConfig, "false");
133 assertFalse(new FS_POSIX().supportsAtomicCreateNewFile());
134 }
135
136 private void setAtomicCreateCreationFlag(FileBasedConfig config,
137 String value) {
138 config.setString(ConfigConstants.CONFIG_CORE_SECTION, null,
139 ConfigConstants.CONFIG_KEY_SUPPORTSATOMICFILECREATION, value);
140 }
141 }