1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.util;
12
13 import static org.junit.Assert.assertFalse;
14 import static org.junit.Assert.assertTrue;
15
16 import java.io.File;
17 import java.io.IOException;
18 import java.nio.file.Files;
19 import java.nio.file.Path;
20
21 import org.eclipse.jgit.junit.MockSystemReader;
22 import org.eclipse.jgit.lib.ConfigConstants;
23 import org.eclipse.jgit.storage.file.FileBasedConfig;
24 import org.junit.After;
25 import org.junit.Before;
26 import org.junit.Test;
27
28 public class FS_POSIXTest {
29 private FileBasedConfig jgitConfig;
30
31 private FileBasedConfig systemConfig;
32
33 private FileBasedConfig userConfig;
34
35 private Path tmp;
36
37 @Before
38 public void setUp() throws Exception {
39 tmp = Files.createTempDirectory("jgit_test_");
40
41 MockSystemReader mockSystemReader = new MockSystemReader();
42 SystemReader.setInstance(mockSystemReader);
43
44
45
46
47
48 FS.getFileStoreAttributes(tmp.getParent());
49
50 jgitConfig = new FileBasedConfig(new File(tmp.toFile(), "jgitconfig"),
51 FS.DETECTED);
52 systemConfig = new FileBasedConfig(jgitConfig,
53 new File(tmp.toFile(), "systemgitconfig"), FS.DETECTED);
54 userConfig = new FileBasedConfig(systemConfig,
55 new File(tmp.toFile(), "usergitconfig"), FS.DETECTED);
56
57
58
59
60 userConfig.setBoolean(ConfigConstants.CONFIG_GC_SECTION, null,
61 ConfigConstants.CONFIG_KEY_AUTODETACH, false);
62 userConfig.save();
63 mockSystemReader.setJGitConfig(jgitConfig);
64 mockSystemReader.setSystemGitConfig(systemConfig);
65 mockSystemReader.setUserGitConfig(userConfig);
66 }
67
68 @After
69 public void tearDown() throws IOException {
70 SystemReader.setInstance(null);
71 FileUtils.delete(tmp.toFile(), FileUtils.RECURSIVE | FileUtils.RETRY);
72 }
73
74 @Test
75 public void supportsAtomicCreateNewFile_shouldReturnSupportedAsDefault() {
76 assertTrue(new FS_POSIX().supportsAtomicCreateNewFile());
77 }
78
79 @Test
80 public void supportsAtomicCreateNewFile_shouldReturnTrueIfFlagIsSetInUserConfig() {
81 setAtomicCreateCreationFlag(userConfig, "true");
82 assertTrue(new FS_POSIX().supportsAtomicCreateNewFile());
83 }
84
85 @Test
86 public void supportsAtomicCreateNewFile_shouldReturnTrueIfFlagIsSetInSystemConfig() {
87 setAtomicCreateCreationFlag(systemConfig, "true");
88 assertTrue(new FS_POSIX().supportsAtomicCreateNewFile());
89 }
90
91 @Test
92 public void supportsAtomicCreateNewFile_shouldReturnFalseIfFlagUnsetInUserConfig() {
93 setAtomicCreateCreationFlag(userConfig, "false");
94 assertFalse(new FS_POSIX().supportsAtomicCreateNewFile());
95 }
96
97 @Test
98 public void supportsAtomicCreateNewFile_shouldReturnFalseIfFlagUnsetInSystemConfig() {
99 setAtomicCreateCreationFlag(systemConfig, "false");
100 assertFalse(new FS_POSIX().supportsAtomicCreateNewFile());
101 }
102
103 private void setAtomicCreateCreationFlag(FileBasedConfig config,
104 String value) {
105 config.setString(ConfigConstants.CONFIG_CORE_SECTION, null,
106 ConfigConstants.CONFIG_KEY_SUPPORTSATOMICFILECREATION, value);
107 }
108 }