@Override /* ConfigStore */ public synchronized boolean exists(String name) { try { return ! read(name).isEmpty(); } catch (IOException e) { return false; } }
@Override /* ConfigStore */ public synchronized boolean exists(String name) { try { return ! read(name).isEmpty(); } catch (IOException e) { return false; } }
@Override /* ConfigStore */ public synchronized boolean exists(String name) { try { return ! read(name).isEmpty(); } catch (IOException e) { return false; } }
@Override /* ConfigStore */ public synchronized String write(String name, String expectedContents, String newContents) throws IOException { // This is a no-op. if (isEquals(expectedContents, newContents)) return null; String currentContents = read(name); if (expectedContents != null && ! isEquals(currentContents, expectedContents)) return currentContents; update(name, newContents); return null; }
@Override /* ConfigStore */ public synchronized String write(String name, String expectedContents, String newContents) throws IOException { // This is a no-op. if (isEquals(expectedContents, newContents)) return null; String currentContents = read(name); if (expectedContents != null && ! isEquals(currentContents, expectedContents)) return currentContents; update(name, newContents); return null; }
@Override /* ConfigStore */ public synchronized String write(String name, String expectedContents, String newContents) throws IOException { // This is a no-op. if (isEquals(expectedContents, newContents)) return null; String currentContents = read(name); if (expectedContents != null && ! isEquals(currentContents, expectedContents)) return currentContents; update(name, newContents); return null; }
@Test public void testFailOnMismatch() throws Exception { ConfigClasspathStore fs = ConfigClasspathStore.create().build(); assertNotNull(fs.write("X.cfg", "xxx", "foo")); assertEquals("", fs.read("X.cfg")); assertNull(fs.write("X.cfg", null, "foo")); assertEquals("foo", fs.read("X.cfg")); assertNotNull(fs.write("X.cfg", "xxx", "foo")); assertEquals("foo", fs.read("X.cfg")); assertNull(fs.write("X.cfg", "foo", "bar")); assertEquals("bar", fs.read("X.cfg")); }
@Test public void testNoFile() throws Exception { ConfigClasspathStore fs = ConfigClasspathStore.create().build(); assertEquals("", fs.read("X.cfg")); }
@Test public void testSimpleCreate() throws Exception { ConfigClasspathStore fs = ConfigClasspathStore.create().build(); assertNull(fs.write("X.cfg", null, "foo")); assertEquals("foo", fs.read("X.cfg")); }