1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.ini4j;
17
18 import org.ini4j.sample.Dwarf;
19 import org.ini4j.sample.Dwarfs;
20
21 import static org.junit.Assert.*;
22
23 import org.junit.Test;
24
25 import java.io.File;
26
27 import java.util.prefs.BackingStoreException;
28
29
30
31
32 public class IniFileTest
33 {
34
35
36
37
38
39
40 @SuppressWarnings("empty-statement")
41 @Test public void testErrors() throws Exception
42 {
43 File tmp = File.createTempFile("ini4j", ".ini");
44
45
46 IniFile f = new IniFile(tmp, IniFile.Mode.WO);
47
48 try
49 {
50 f.sync();
51 fail();
52 }
53 catch (BackingStoreException x)
54 {
55 ;
56 }
57
58
59 f = new IniFile(new File("/non existent path/to file"), IniFile.Mode.WO);
60 try
61 {
62 f.flush();
63 fail();
64 }
65 catch (BackingStoreException x)
66 {
67 ;
68 }
69
70
71 try
72 {
73 f = new IniFile(new File("/non existent path/to file"), IniFile.Mode.RO);
74 fail();
75 }
76 catch (BackingStoreException x)
77 {
78 ;
79 }
80
81
82 f = new IniFile(tmp, IniFile.Mode.RO);
83 try
84 {
85 f.sync();
86 f.flush();
87 }
88 catch (BackingStoreException x)
89 {
90 ;
91 }
92 }
93
94
95
96
97
98
99 @Test public void testFlush() throws Exception
100 {
101 File tmp = File.createTempFile("ini4j", ".ini");
102 IniFile f = new IniFile(tmp, IniFile.Mode.RW);
103
104 assertEquals(IniFile.Mode.RW, f.getMode());
105 assertEquals(tmp, f.getFile());
106 f.node(Dwarfs.PROP_DOC).put(Dwarf.PROP_WEIGHT, "65");
107 f.flush();
108 f = new IniFile(tmp);
109 assertEquals(f.node(Dwarfs.PROP_DOC).get(Dwarf.PROP_WEIGHT, null), "65");
110 tmp.delete();
111 }
112 }