ElementHelper { public static boolean areEqual(final Element a, final Object b) { if (a == b) return true; if (null == b || null == a) return false; if (!((a instanceof Vertex && b instanceof Vertex) || (a instanceof Edge && b instanceof Edge) || (a instanceof VertexProperty && b instanceof VertexProperty))) return false; return haveEqualIds(a, (Element) b); } private  ElementHelper(); static void validateLabel(final String label); static void validateMixedElementIds(final Class<? extends Element> clazz, final Object... ids); static void validateProperty(final String key, final Object value); static void legalPropertyKeyValueArray(final Object... propertyKeyValues); static Optional<Object> getIdValue(final Object... keyValues); static Optional<Object[]> remove(final String keyToRemove, final Object... keyValues); static Optional<Object[]> remove(final T accessor, final Object... keyValues); static Object[] upsert(final Object[] keyValues, final Object key, final Object val); static Object[] replaceKey(final Object[] keyValues, final Object oldKey, final Object newKey); static Map<String, Object> asMap(final Object... keyValues); static List<Pair<String, Object>> asPairs(final Object... keyValues); static Set<String> getKeys(final Object... keyValues); static Optional<String> getLabelValue(final Object... keyValues); static void attachProperties(final Element element, final Object... propertyKeyValues); static void attachProperties(final Vertex vertex, final Object... propertyKeyValues); static void attachProperties(final Vertex vertex, final VertexProperty.Cardinality cardinality,
                                        final Object... propertyKeyValues); static Optional<VertexProperty<V>> stageVertexProperty(final Vertex vertex,
                                                                      final VertexProperty.Cardinality cardinality,
                                                                      final String key, final V value, final Object... keyValues); static Object[] getProperties(final Element element, final boolean includeId, final boolean includeLabel, final Set<String> propertiesToCopy); static boolean areEqual(final Element a, final Object b); static boolean areEqual(final Vertex a, final Vertex b); static boolean areEqual(final Edge a, final Edge b); static boolean areEqual(final VertexProperty a, final VertexProperty b); static boolean areEqual(final VertexProperty a, final Object b); static boolean haveEqualIds(final Element a, final Element b); static int hashCode(final Element element); static int hashCode(final Property property); static boolean areEqual(final Property a, final Object b); static Map<String, Object> propertyValueMap(final Element element, final String... propertyKeys); static Map<String, Property> propertyMap(final Element element, final String... propertyKeys); static Map<String, List> vertexPropertyValueMap(final Vertex vertex, final String... propertyKeys); static Map<String, List<VertexProperty>> vertexPropertyMap(final Vertex vertex, final String... propertyKeys); static boolean keyExists(final String key, final String... providedKeys); static boolean idExists(final Object id, final Object... providedIds);  }
@Test public void shouldDetermineElementsAreEqualAsTheyAreSameObject() { final Element mockElement = mock(Element.class); assertTrue(ElementHelper.areEqual(mockElement, mockElement)); }
@Test public void shouldDetermineElementsAreNotEqualAsAIsVertexAndBIsEdge() { final Element mockVertex = mock(Vertex.class); final Element mockEdge = mock(Edge.class); assertFalse(ElementHelper.areEqual(mockVertex, mockEdge)); }
@Test public void shouldDetermineElementsAreNotEqualAsBIsVertexAndAIsEdge() { final Element mockVertex = mock(Vertex.class); final Element mockEdge = mock(Edge.class); assertFalse(ElementHelper.areEqual(mockEdge, mockVertex)); }
@Test public void shouldDetermineVerticesAreEqual() { final Element mockVertexA = mock(Vertex.class); final Element mockVertexB = mock(Vertex.class); when(mockVertexA.id()).thenReturn("1"); when(mockVertexB.id()).thenReturn("1"); assertTrue(ElementHelper.areEqual(mockVertexA, mockVertexB)); }
@Test public void shouldDetermineVerticesAreNotEqual() { final Element mockVertexA = mock(Vertex.class); final Element mockVertexB = mock(Vertex.class); when(mockVertexA.id()).thenReturn("1"); when(mockVertexB.id()).thenReturn("2"); assertFalse(ElementHelper.areEqual(mockVertexA, mockVertexB)); }
@Test public void shouldDetermineElementsAreEqualWhenBothNull() { assertTrue(ElementHelper.areEqual((Element) null, null)); }
@Test public void shouldDetermineElementsAreNotEqualBecauseFirstArgumentIsNull() { Element v = mock(Element.class); assertFalse(ElementHelper.areEqual((Element) null, v)); }
@Test public void shouldDetermineElementsAreNotEqualBecauseSecondArgumentIsNull() { Element v = mock(Element.class); assertFalse(ElementHelper.areEqual(v, null)); }
@Test public void shouldDetermineEdgesAreEqual() { final Element mockEdgeA = mock(Edge.class); final Element mockEdgeB = mock(Edge.class); when(mockEdgeA.id()).thenReturn("1"); when(mockEdgeB.id()).thenReturn("1"); assertTrue(ElementHelper.areEqual(mockEdgeA, mockEdgeB)); }
@Test public void shouldDetermineEdgesAreNotEqual() { final Element mockEdgeA = mock(Edge.class); final Element mockEdgeB = mock(Edge.class); when(mockEdgeA.id()).thenReturn("1"); when(mockEdgeB.id()).thenReturn("2"); assertFalse(ElementHelper.areEqual(mockEdgeA, mockEdgeB)); }
@Test public void shouldDeterminePropertiesAreEqualBecauseBothAreNull() { assertTrue(ElementHelper.areEqual((Property) null, null)); }
@Test public void shouldDeterminePropertiesAreNotEqualBecauseFirstArgumentIsNull() { assertFalse(ElementHelper.areEqual((Property) null, "some object")); }
@Test public void shouldDeterminePropertiesAreNotEqualTestBecauseSecondArgumentIsNull() { final Property mockProperty = mock(Property.class); assertFalse(ElementHelper.areEqual(mockProperty, null)); }
@Test public void shouldFailPropertyAreEqualTestBecauseSecondArgumentIsNotProperty() { final Property mockProperty = mock(Property.class); assertFalse(ElementHelper.areEqual(mockProperty, "i'm a string")); }
@Test public void shouldDeterminePropertiesAreEqualAsTheyAreSameObject() { final Property mockProperty = mock(Property.class); assertTrue(ElementHelper.areEqual(mockProperty, mockProperty)); }
@Test public void shouldDeterminePropertiesAreEqualAsTheyAreBothEmpty() { final Property mockPropertyA = mock(Property.class); final Property mockPropertyB = mock(Property.class); when(mockPropertyA.isPresent()).thenReturn(false); when(mockPropertyB.isPresent()).thenReturn(false); assertTrue(ElementHelper.areEqual(mockPropertyA, mockPropertyB)); }
@Test public void shouldDeterminePropertiesAreNotEqualAsAIsEmptyAndBIsNot() { final Property mockPropertyA = mock(Property.class); final Property mockPropertyB = mock(Property.class); when(mockPropertyA.isPresent()).thenReturn(false); when(mockPropertyB.isPresent()).thenReturn(true); assertFalse(ElementHelper.areEqual(mockPropertyA, mockPropertyB)); }
@Test public void shouldDeterminePropertiesAreNotEqualAsBIsEmptyAndAIsNot() { final Property mockPropertyA = mock(Property.class); final Property mockPropertyB = mock(Property.class); when(mockPropertyA.isPresent()).thenReturn(true); when(mockPropertyB.isPresent()).thenReturn(false); assertFalse(ElementHelper.areEqual(mockPropertyA, mockPropertyB)); }
@Test public void shouldDeterminePropertiesAreEqual() { final Property mockPropertyA = mock(Property.class); final Property mockPropertyB = mock(Property.class); final Element mockElement = mock(Element.class); when(mockPropertyA.isPresent()).thenReturn(true); when(mockPropertyB.isPresent()).thenReturn(true); when(mockPropertyA.element()).thenReturn(mockElement); when(mockPropertyB.element()).thenReturn(mockElement); when(mockPropertyA.key()).thenReturn("k"); when(mockPropertyB.key()).thenReturn("k"); when(mockPropertyA.value()).thenReturn("v"); when(mockPropertyB.value()).thenReturn("v"); assertTrue(ElementHelper.areEqual(mockPropertyA, mockPropertyB)); }
@Test public void shouldDeterminePropertiesAreEqualWhenElementsAreDifferent() { final Property mockPropertyA = mock(Property.class); final Property mockPropertyB = mock(Property.class); final Element mockElement = mock(Element.class); final Element mockElementDifferent = mock(Element.class); when(mockPropertyA.isPresent()).thenReturn(true); when(mockPropertyB.isPresent()).thenReturn(true); when(mockPropertyA.element()).thenReturn(mockElement); when(mockPropertyB.element()).thenReturn(mockElementDifferent); when(mockPropertyA.key()).thenReturn("k"); when(mockPropertyB.key()).thenReturn("k"); when(mockPropertyA.value()).thenReturn("v"); when(mockPropertyB.value()).thenReturn("v"); assertTrue(ElementHelper.areEqual(mockPropertyA, mockPropertyB)); }
@Test public void shouldDeterminePropertiesAreNotEqualWhenKeysAreDifferent() { final Property mockPropertyA = mock(Property.class); final Property mockPropertyB = mock(Property.class); final Element mockElement = mock(Element.class); when(mockPropertyA.isPresent()).thenReturn(true); when(mockPropertyB.isPresent()).thenReturn(true); when(mockPropertyA.element()).thenReturn(mockElement); when(mockPropertyB.element()).thenReturn(mockElement); when(mockPropertyA.key()).thenReturn("k"); when(mockPropertyB.key()).thenReturn("k1"); when(mockPropertyA.value()).thenReturn("v"); when(mockPropertyB.value()).thenReturn("v"); assertFalse(ElementHelper.areEqual(mockPropertyA, mockPropertyB)); }
@Test public void shouldDeterminePropertiesAreNotEqualWhenValuesAreDifferent() { final Property mockPropertyA = mock(Property.class); final Property mockPropertyB = mock(Property.class); final Element mockElement = mock(Element.class); when(mockPropertyA.isPresent()).thenReturn(true); when(mockPropertyB.isPresent()).thenReturn(true); when(mockPropertyA.element()).thenReturn(mockElement); when(mockPropertyB.element()).thenReturn(mockElement); when(mockPropertyA.key()).thenReturn("k"); when(mockPropertyB.key()).thenReturn("k"); when(mockPropertyA.value()).thenReturn("v"); when(mockPropertyB.value()).thenReturn("v1"); assertFalse(ElementHelper.areEqual(mockPropertyA, mockPropertyB)); }
@Test public void shouldDetermineAbsentPropertiesEqual() { Property<?> p1 = mock(Property.class); Property<?> p2 = mock(Property.class); when(p1.isPresent()).thenReturn(false); when(p2.isPresent()).thenReturn(false); assertTrue(ElementHelper.areEqual(p1, p2)); }
@Test public void shouldDetermineAbsentPropertyNotEqualToPresent() { Property<?> p1 = mock(Property.class); Property<?> p2 = mock(Property.class); when(p1.isPresent()).thenReturn(false); when(p2.isPresent()).thenReturn(true); assertFalse(ElementHelper.areEqual(p1, p2)); }
@Test public void shouldDeterminePresentPropertyNotEqualToAbsent() { Property<?> p1 = mock(Property.class); Property<?> p2 = mock(Property.class); when(p1.isPresent()).thenReturn(true); when(p2.isPresent()).thenReturn(false); assertFalse(ElementHelper.areEqual(p1, p2)); }