AbstractGraphTemplate implements GraphTemplate { @Override public <T> T update(T entity) { requireNonNull(entity, "entity is required"); checkId(entity); if (isIdNull(entity)) { throw new NullPointerException("to update a graph id cannot be null"); } getVertex(entity).orElseThrow(() -> new EntityNotFoundException("Entity does not find in the update")); UnaryOperator<Vertex> update = e -> getConverter().toVertex(entity); return getFlow().flow(entity, update); }  @Override T insert(T entity); @Override T update(T entity); @Override void delete(T idValue); @Override void deleteEdge(T idEdge); @Override Optional<T> find(ID idValue); @Override EdgeEntity edge(OUT outgoing, String label, IN incoming); @Override Optional<EdgeEntity> edge(E edgeId); @Override Collection<EdgeEntity> getEdges(T entity, Direction direction); @Override Collection<EdgeEntity> getEdges(T entity, Direction direction, String... labels); @SafeVarargs @Override final Collection<EdgeEntity> getEdges(T entity, Direction direction, Supplier<String>... labels); @Override Collection<EdgeEntity> getEdgesById(ID id, Direction direction, String... labels); @Override Collection<EdgeEntity> getEdgesById(ID id, Direction direction); @SafeVarargs @Override final Collection<EdgeEntity> getEdgesById(ID id, Direction direction, Supplier<String>... labels); @Override VertexTraversal getTraversalVertex(Object... vertexIds); @Override EdgeTraversal getTraversalEdge(Object... edgeIds); @Override Transaction getTransaction(); @Override List<T> query(String gremlin); @Override Optional<T> singleResult(String gremlin); @Override PreparedStatement prepare(String gremlin); @Override long count(String label); @Override long count(Class<T> entityClass);  }
@Test public void shouldGetErrorWhenIdIsNullWhenUpdate() { assertThrows(NullPointerException.class, () -> { Person person = builder().withAge() .withName("Otavio").build(); getGraphTemplate().update(person); }); }
@Test public void shouldGetErrorWhenEntityIsNotSavedYet() { assertThrows(EntityNotFoundException.class, () -> { Person person = builder().withAge() .withId(10L) .withName("Otavio").build(); getGraphTemplate().update(person); }); }