コード例 #1
0
 public void testNode() throws BackingStoreException {
   assertNull(storage.toFolder());
   assertNull(storage.toPropertiesFile());
   pref.flush();
   assertNull(storage.toFolder());
   assertNull(storage.toPropertiesFile());
   pref.put("key", "value");
 }
コード例 #2
0
  public void testRemove() throws BackingStoreException {
    assertNull(storage.toFolder());
    assertNull(storage.toPropertiesFile());

    pref.put("key", "value");
    pref.flush();
    assertNotNull(storage.toPropertiesFile());
    pref.remove("key");
    assertTrue(pref.properties.isEmpty());
    pref.flush();
    assertNull(storage.toPropertiesFile());
  }
コード例 #3
0
  private void deleteStorageEntry(String key) throws IOException {
    String currentText = storage.toPropertiesFile().asText();
    int index = currentText.indexOf(key);

    String before = currentText.substring(0, index);
    String after = currentText.substring(index + key.length() + 1);
    String newText = before.concat(after);

    OutputStream storageOutputStream = storage.toPropertiesFile().getOutputStream();
    storageOutputStream.write(newText.getBytes("ISO-8859-1"));
    storageOutputStream.close();
  }
コード例 #4
0
 private void overrideStorageEntryWithNewValue(String oldValue, String newValue)
     throws IOException {
   String newText = constructNewEntryText(oldValue, newValue);
   OutputStream storageOutputStream = storage.toPropertiesFile().getOutputStream();
   storageOutputStream.write(newText.getBytes("ISO-8859-1"));
   storageOutputStream.close();
 }
コード例 #5
0
 public void testNode5() throws BackingStoreException {
   Preferences child = pref.node("a");
   child.put("key", "value");
   child.flush();
   assertNotNull(storage.toFolder());
   assertNull(storage.toPropertiesFile());
 }
コード例 #6
0
  public void testRemoveParentNode() throws BackingStoreException {
    assertNull(storage.toFolder());
    assertNull(storage.toPropertiesFile());

    Preferences subnode = pref.node("subnode");
    assertNull(storage.toFolder());
    assertNull(storage.toPropertiesFile());
    subnode.put("key", "value");
    subnode.flush();
    assertNotNull(storage.toFolder());
    assertNull(storage.toPropertiesFile());
    subnode.removeNode();
    pref.flush();
    assertNull(storage.toPropertiesFile());
    assertNull(storage.toFolder());
    assertFalse(storage.existsNode());
  }
コード例 #7
0
  @RandomlyFails // FSException: Invalid lock (from flush)
  public void testRemoveNode() throws BackingStoreException {
    assertNull(storage.toFolder());
    assertNull(storage.toPropertiesFile());

    pref.put("key", "value");
    pref.node("subnode").put("key", "value");
    pref.flush();
    assertNotNull(storage.toPropertiesFile());
    assertNotNull(storage.toFolder());
    pref.removeNode();
    pref.flush();
    assertNull(storage.toPropertiesFile());
    assertNull(storage.toFolder());
    assertFalse(storage.existsNode());
    pref.sync();
  }
コード例 #8
0
 private String constructNewEntryText(String oldValue, String newValue) throws IOException {
   String currentText = storage.toPropertiesFile().asText();
   String newText = currentText.replace(oldValue, newValue);
   return newText;
 }
コード例 #9
0
 private void overrideStorageEntryWithNewData(String newData) throws IOException {
   OutputStream storageOutputStream = storage.toPropertiesFile(true).getOutputStream();
   storageOutputStream.write(newData.getBytes("ISO-8859-1"));
   storageOutputStream.close();
 }
コード例 #10
0
 public void testNode3() throws BackingStoreException {
   testNode();
   pref.flushTask.waitFinished();
   assertNotNull(storage.toPropertiesFile());
 }
コード例 #11
0
 public void testNode2() throws BackingStoreException {
   testNode();
   pref.flush();
   assertNotNull(storage.toPropertiesFile());
 }