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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
package org.bukkit.configuration.file;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.Map;
import org.bukkit.configuration.MemoryConfigurationTest;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import static org.junit.Assert.*;
public abstract class FileConfigurationTest extends MemoryConfigurationTest {
@Rule
public TemporaryFolder testFolder = new TemporaryFolder();
@Override
public abstract FileConfiguration getConfig();
public abstract String getTestValuesString();
@Test
public void testSave_File() throws Exception {
FileConfiguration config = getConfig();
File file = testFolder.newFile("test.config");
for (Map.Entry<String, Object> entry : getTestValues().entrySet()) {
config.set(entry.getKey(), entry.getValue());
}
config.save(file);
assertTrue(file.isFile());
}
@Test
public void testSave_String() throws Exception {
FileConfiguration config = getConfig();
File file = testFolder.newFile("test.config");
for (Map.Entry<String, Object> entry : getTestValues().entrySet()) {
config.set(entry.getKey(), entry.getValue());
}
config.save(file.getAbsolutePath());
assertTrue(file.isFile());
}
@Test
public void testSaveToString() {
FileConfiguration config = getConfig();
for (Map.Entry<String, Object> entry : getTestValues().entrySet()) {
config.set(entry.getKey(), entry.getValue());
}
String result = config.saveToString();
String expected = getTestValuesString();
assertEquals(expected, result);
}
@Test
public void testLoad_File() throws Exception {
FileConfiguration config = getConfig();
File file = testFolder.newFile("test.config");
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
String saved = getTestValuesString();
Map<String, Object> values = getTestValues();
try {
writer.write(saved);
} finally {
writer.close();
}
config.load(file);
for (Map.Entry<String, Object> entry : values.entrySet()) {
assertEquals(entry.getValue(), config.get(entry.getKey()));
}
assertEquals(values.keySet(), config.getKeys(true));
}
@Test
public void testLoad_String() throws Exception {
FileConfiguration config = getConfig();
File file = testFolder.newFile("test.config");
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
String saved = getTestValuesString();
Map<String, Object> values = getTestValues();
try {
writer.write(saved);
} finally {
writer.close();
}
config.load(file.getAbsolutePath());
for (Map.Entry<String, Object> entry : values.entrySet()) {
assertEquals(entry.getValue(), config.get(entry.getKey()));
}
assertEquals(values.keySet(), config.getKeys(true));
}
@Test
public void testLoadFromString() throws Exception {
FileConfiguration config = getConfig();
Map<String, Object> values = getTestValues();
String saved = getTestValuesString();
config.loadFromString(saved);
for (Map.Entry<String, Object> entry : values.entrySet()) {
assertEquals(entry.getValue(), config.get(entry.getKey()));
}
assertEquals(values.keySet(), config.getKeys(true));
}
}
|