1 19 20 package org.netbeans.core.startup.preferences; 21 22 import java.io.IOException ; 23 import java.util.Properties ; 24 import org.netbeans.junit.NbTestCase; 25 26 30 public class TestFileStorage extends NbPreferencesTest.TestBasicSetup { 31 protected NbPreferences.FileStorage instance; 32 33 34 public TestFileStorage(String testName) { 35 super(testName); 36 } 37 38 protected void setUp() throws Exception { 39 super.setUp(); 40 instance = getInstance(); 41 } 42 43 protected NbPreferences.FileStorage getInstance() { 44 return PropertiesStorage.instance("/FileStorageTest/" + getName()); } 46 47 public void testBasic() throws IOException { 48 noFileRepresentationAssertion(); 50 51 Properties p = instance.load(); 53 p.put("key", "value"); noFileRepresentationAssertion(); 55 56 instance.save(p); 58 noFileRepresentationAssertion(); 59 60 instance.markModified(); 62 noFileRepresentationAssertion(); 63 64 if (!instance.isReadOnly()) { 65 instance.save(p); 67 fileRepresentationAssertion(); 68 } else { 69 try { 70 instance.save(p); 72 fail(); 73 } catch (IOException ex) {} 74 noFileRepresentationAssertion(); 75 } 76 } 77 78 void noFileRepresentationAssertion() throws IOException { 79 assertFalse(instance.existsNode()); 80 } 81 82 void fileRepresentationAssertion() throws IOException { 83 assertTrue(instance.existsNode()); 84 } 85 } 86 | Popular Tags |