diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/transaction/CuratorTransactionResult.java b/curator-framework/src/main/java/org/apache/curator/framework/api/transaction/CuratorTransactionResult.java index d0e5be84b..bc710f72f 100644 --- a/curator-framework/src/main/java/org/apache/curator/framework/api/transaction/CuratorTransactionResult.java +++ b/curator-framework/src/main/java/org/apache/curator/framework/api/transaction/CuratorTransactionResult.java @@ -43,13 +43,8 @@ public class CuratorTransactionResult { * @param forPath path * @return predicate */ - public static Predicate ofTypeAndPath(final OperationType type, final String forPath) { - return new Predicate() { - @Override - public boolean apply(CuratorTransactionResult result) { - return (result.getType() == type) && result.getForPath().equals(forPath); - } - }; + public static Predicate ofTypeAndPath(OperationType type, String forPath) { + return result -> (result.getType() == type) && result.getForPath().equals(forPath); } public CuratorTransactionResult(OperationType type, String forPath, String resultPath, Stat resultStat) { diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestTransactionsNew.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestTransactionsNew.java index c10e0f46e..d8c1b30dd 100644 --- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestTransactionsNew.java +++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestTransactionsNew.java @@ -59,12 +59,7 @@ public void testErrors() throws Exception { CuratorOp createOp1 = client.transactionOp().create().forPath("/bar"); CuratorOp createOp2 = client.transactionOp().create().forPath("/z/blue"); final BlockingQueue callbackQueue = new LinkedBlockingQueue<>(); - BackgroundCallback callback = new BackgroundCallback() { - @Override - public void processResult(CuratorFramework client, CuratorEvent event) throws Exception { - callbackQueue.add(event); - } - }; + BackgroundCallback callback = (client1, event) -> callbackQueue.add(event); client.transaction().inBackground(callback).forOperations(createOp1, createOp2); CuratorEvent event = callbackQueue.poll(new Timing().milliseconds(), TimeUnit.MILLISECONDS); assertNotNull(event); @@ -124,10 +119,10 @@ public void testWithNamespace() throws Exception { Collection results = client.transaction().forOperations(createOp1, createOp2, setDataOp, createOp3, deleteOp); - assertTrue(client.checkExists().forPath("/foo") != null); - assertTrue(client.usingNamespace(null).checkExists().forPath("/galt/foo") != null); + assertNotNull(client.checkExists().forPath("/foo")); + assertNotNull(client.usingNamespace(null).checkExists().forPath("/galt/foo")); assertArrayEquals(client.getData().forPath("/foo"), "two".getBytes()); - assertTrue(client.checkExists().forPath("/foo/bar") == null); + assertNull(client.checkExists().forPath("/foo/bar")); CuratorTransactionResult ephemeralResult = Iterables.find(results, CuratorTransactionResult.ofTypeAndPath(OperationType.CREATE, "/test-")); @@ -149,7 +144,7 @@ public void testBasic() throws Exception { Collection results = client.transaction().forOperations(createOp1, createOp2); - assertTrue(client.checkExists().forPath("/foo/bar") != null); + assertNotNull(client.checkExists().forPath("/foo/bar")); assertArrayEquals(client.getData().forPath("/foo/bar"), "snafu".getBytes()); CuratorTransactionResult fooResult = @@ -175,17 +170,12 @@ public void testBackground() throws Exception { CuratorOp createOp2 = client.transactionOp().create().forPath("/foo/bar", "snafu".getBytes()); final BlockingQueue> queue = Queues.newLinkedBlockingQueue(); - BackgroundCallback callback = new BackgroundCallback() { - @Override - public void processResult(CuratorFramework client, CuratorEvent event) throws Exception { - queue.add(event.getOpResults()); - } - }; + BackgroundCallback callback = (client1, event) -> queue.add(event.getOpResults()); client.transaction().inBackground(callback).forOperations(createOp1, createOp2); Collection results = queue.poll(5, TimeUnit.SECONDS); assertNotNull(results); - assertTrue(client.checkExists().forPath("/foo/bar") != null); + assertNotNull(client.checkExists().forPath("/foo/bar")); assertArrayEquals(client.getData().forPath("/foo/bar"), "snafu".getBytes()); CuratorTransactionResult fooResult = @@ -221,12 +211,7 @@ public void testBackgroundWithNamespace() throws Exception { CuratorOp deleteOp = client.transactionOp().delete().forPath("/foo/bar"); final BlockingQueue> queue = Queues.newLinkedBlockingQueue(); - BackgroundCallback callback = new BackgroundCallback() { - @Override - public void processResult(CuratorFramework client, CuratorEvent event) throws Exception { - queue.add(event.getOpResults()); - } - }; + BackgroundCallback callback = (client1, event) -> queue.add(event.getOpResults()); client.transaction() .inBackground(callback) .forOperations(createOp1, createOp2, setDataOp, createOp3, deleteOp); @@ -234,10 +219,10 @@ public void processResult(CuratorFramework client, CuratorEvent event) throws Ex Collection results = queue.poll(5, TimeUnit.SECONDS); assertNotNull(results); - assertTrue(client.checkExists().forPath("/foo") != null); - assertTrue(client.usingNamespace(null).checkExists().forPath("/galt/foo") != null); + assertNotNull(client.checkExists().forPath("/foo")); + assertNotNull(client.usingNamespace(null).checkExists().forPath("/galt/foo")); assertArrayEquals(client.getData().forPath("/foo"), "two".getBytes()); - assertTrue(client.checkExists().forPath("/foo/bar") == null); + assertNull(client.checkExists().forPath("/foo/bar")); CuratorTransactionResult ephemeralResult = Iterables.find(results, CuratorTransactionResult.ofTypeAndPath(OperationType.CREATE, "/test-")); diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestTransactionsOld.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestTransactionsOld.java index 9d2a7fa53..bd00720ba 100644 --- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestTransactionsOld.java +++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestTransactionsOld.java @@ -102,10 +102,10 @@ public void testWithNamespace() throws Exception { .and() .commit(); - assertTrue(client.checkExists().forPath("/foo") != null); - assertTrue(client.usingNamespace(null).checkExists().forPath("/galt/foo") != null); + assertNotNull(client.checkExists().forPath("/foo")); + assertNotNull(client.usingNamespace(null).checkExists().forPath("/galt/foo")); assertArrayEquals(client.getData().forPath("/foo"), "two".getBytes()); - assertTrue(client.checkExists().forPath("/foo/bar") == null); + assertNull(client.checkExists().forPath("/foo/bar")); CuratorTransactionResult ephemeralResult = Iterables.find(results, CuratorTransactionResult.ofTypeAndPath(OperationType.CREATE, "/test-")); @@ -154,10 +154,10 @@ public void testWithCompression() throws Exception { .and() .commit(); - assertTrue(client.checkExists().forPath("/foo") != null); + assertNotNull(client.checkExists().forPath("/foo")); assertArrayEquals(client.getData().decompressed().forPath("/foo"), "five".getBytes()); - assertTrue(client.checkExists().forPath("/bar") != null); + assertNotNull(client.checkExists().forPath("/bar")); assertArrayEquals(client.getData().decompressed().forPath("/bar"), "two".getBytes()); assertEquals(client.getACL().forPath("/bar"), ZooDefs.Ids.READ_ACL_UNSAFE); @@ -167,7 +167,7 @@ public void testWithCompression() throws Exception { assertNotEquals(ephemeralResult.getResultPath(), "/test-"); assertTrue(ephemeralResult.getResultPath().startsWith("/test-")); - assertTrue(client.checkExists().forPath("/baz") != null); + assertNotNull(client.checkExists().forPath("/baz")); assertArrayEquals(client.getData().decompressed().forPath("/baz"), "four".getBytes()); assertEquals(client.getACL().forPath("/baz"), ZooDefs.Ids.READ_ACL_UNSAFE); } finally { @@ -189,7 +189,7 @@ public void testBasic() throws Exception { .and() .commit(); - assertTrue(client.checkExists().forPath("/foo/bar") != null); + assertNotNull(client.checkExists().forPath("/foo/bar")); assertArrayEquals(client.getData().forPath("/foo/bar"), "snafu".getBytes()); CuratorTransactionResult fooResult =