From 97d2e82d97c5c8620354657ccbfc4b556058944d Mon Sep 17 00:00:00 2001 From: Stephen Mallette Date: Wed, 28 May 2014 07:03:41 -0400 Subject: [PATCH] Corrected logic in in ElementHelper.areEqual around null args and added tests #487 --- .../blueprints/util/ElementHelper.java | 2 ++ .../blueprints/util/ElementHelperTest.java | 30 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/blueprints-core/src/main/java/com/tinkerpop/blueprints/util/ElementHelper.java b/blueprints-core/src/main/java/com/tinkerpop/blueprints/util/ElementHelper.java index ff728451..398a478d 100644 --- a/blueprints-core/src/main/java/com/tinkerpop/blueprints/util/ElementHelper.java +++ b/blueprints-core/src/main/java/com/tinkerpop/blueprints/util/ElementHelper.java @@ -189,6 +189,8 @@ public static void setProperties(final Element element, final Object... keysValu * @return Whether the two elements are equal */ public static boolean areEqual(final Element a, final Object b) { + if (null == a && b != null) + return false; if (a == b) return true; if (null == b) diff --git a/blueprints-test/src/test/java/com/tinkerpop/blueprints/util/ElementHelperTest.java b/blueprints-test/src/test/java/com/tinkerpop/blueprints/util/ElementHelperTest.java index 549aaa31..1dcc9b50 100644 --- a/blueprints-test/src/test/java/com/tinkerpop/blueprints/util/ElementHelperTest.java +++ b/blueprints-test/src/test/java/com/tinkerpop/blueprints/util/ElementHelperTest.java @@ -156,4 +156,34 @@ public void testSetPropertiesVarArgs() { } } + + public void testAreEqualNullFirstArg() { + Graph graph = new TinkerGraph(); + Vertex vertex = graph.addVertex(null); + + ElementHelper.areEqual(null, vertex); + } + + public void testAreEqualNullSecondArg() { + Graph graph = new TinkerGraph(); + Vertex vertex = graph.addVertex(null); + + ElementHelper.areEqual(vertex, null); + } + + public void testAreEqualValid() { + Graph graph = new TinkerGraph(); + Vertex vertex = graph.addVertex(null); + + ElementHelper.areEqual(vertex, vertex); + } + + public void testAreEqualInvalid() { + Graph graph = new TinkerGraph(); + Vertex vertex1 = graph.addVertex(null); + Vertex vertex2 = graph.addVertex(null); + + ElementHelper.areEqual(vertex2, vertex1); + } + }