Commits
DerFrZocker authored and md_5 committed c7390d7129e
1 1 | package org.bukkit.configuration.file; |
2 2 | |
3 - | import static org.junit.Assert.*; |
3 + | import static org.junit.jupiter.api.Assertions.*; |
4 4 | import java.io.BufferedWriter; |
5 5 | import java.io.File; |
6 6 | import java.io.FileWriter; |
7 7 | import java.util.Arrays; |
8 8 | import java.util.List; |
9 9 | import java.util.Map; |
10 10 | import org.bukkit.configuration.MemoryConfigurationTest; |
11 - | import org.junit.Rule; |
12 - | import org.junit.Test; |
13 - | import org.junit.rules.TemporaryFolder; |
11 + | import org.junit.jupiter.api.Test; |
12 + | import org.junit.jupiter.api.io.TempDir; |
14 13 | |
15 14 | public abstract class FileConfigurationTest extends MemoryConfigurationTest { |
16 - | |
17 - | public TemporaryFolder testFolder = new TemporaryFolder(); |
15 + | |
16 + | public File testFolder; |
18 17 | |
19 18 | |
20 19 | public abstract FileConfiguration getConfig(); |
21 20 | |
22 21 | public abstract String getTestValuesString(); |
23 22 | |
24 23 | public abstract List<String> getTestCommentInput(); |
25 24 | |
26 25 | public abstract String getTestCommentResult(); |
27 26 | |
28 27 | public abstract List<String> getTestHeaderComments(); |
29 28 | |
30 29 | public abstract String getTestHeaderCommentsResult(); |
31 30 | |
32 31 | public abstract List<String> getTestKeyComments(); |
33 32 | |
34 33 | public abstract String getTestHeaderKeyCommentResult(); |
35 34 | |
36 35 | |
37 36 | public void testSave_File() throws Exception { |
38 37 | FileConfiguration config = getConfig(); |
39 - | File file = testFolder.newFile("test.config"); |
38 + | File file = new File(testFolder, "test.config"); |
39 + | file.createNewFile(); |
40 40 | |
41 41 | for (Map.Entry<String, Object> entry : getTestValues().entrySet()) { |
42 42 | config.set(entry.getKey(), entry.getValue()); |
43 43 | } |
44 44 | |
45 45 | config.save(file); |
46 46 | |
47 47 | assertTrue(file.isFile()); |
48 48 | } |
49 49 | |
50 50 | |
51 51 | public void testSave_String() throws Exception { |
52 52 | FileConfiguration config = getConfig(); |
53 - | File file = testFolder.newFile("test.config"); |
53 + | File file = new File(testFolder, "test.config"); |
54 + | file.createNewFile(); |
54 55 | |
55 56 | for (Map.Entry<String, Object> entry : getTestValues().entrySet()) { |
56 57 | config.set(entry.getKey(), entry.getValue()); |
57 58 | } |
58 59 | |
59 60 | config.save(file.getAbsolutePath()); |
60 61 | |
61 62 | assertTrue(file.isFile()); |
62 63 | } |
63 64 | |
71 72 | |
72 73 | String result = config.saveToString(); |
73 74 | String expected = getTestValuesString(); |
74 75 | |
75 76 | assertEquals(expected, result); |
76 77 | } |
77 78 | |
78 79 | |
79 80 | public void testLoad_File() throws Exception { |
80 81 | FileConfiguration config = getConfig(); |
81 - | File file = testFolder.newFile("test.config"); |
82 + | File file = new File(testFolder, "test.config"); |
83 + | file.createNewFile(); |
82 84 | BufferedWriter writer = new BufferedWriter(new FileWriter(file)); |
83 85 | String saved = getTestValuesString(); |
84 86 | Map<String, Object> values = getTestValues(); |
85 87 | |
86 88 | try { |
87 89 | writer.write(saved); |
88 90 | } finally { |
89 91 | writer.close(); |
90 92 | } |
91 93 | |
94 96 | for (Map.Entry<String, Object> entry : values.entrySet()) { |
95 97 | assertEquals(entry.getValue(), config.get(entry.getKey())); |
96 98 | } |
97 99 | |
98 100 | assertEquals(values.keySet(), config.getKeys(true)); |
99 101 | } |
100 102 | |
101 103 | |
102 104 | public void testLoad_String() throws Exception { |
103 105 | FileConfiguration config = getConfig(); |
104 - | File file = testFolder.newFile("test.config"); |
106 + | File file = new File(testFolder, "test.config"); |
107 + | file.createNewFile(); |
105 108 | BufferedWriter writer = new BufferedWriter(new FileWriter(file)); |
106 109 | String saved = getTestValuesString(); |
107 110 | Map<String, Object> values = getTestValues(); |
108 111 | |
109 112 | try { |
110 113 | writer.write(saved); |
111 114 | } finally { |
112 115 | writer.close(); |
113 116 | } |
114 117 | |