Graph { public void edge(T from, T to) { if (from == null || to == null) throw new IllegalArgumentException("Null vertices are not allowed, edge: " + from + "->" + to); adjMap.computeIfAbsent(from, k -> new LinkedHashSet<>()).add(to); adjMap.computeIfAbsent(to, k -> new LinkedHashSet<>()); }  void edge(T from, T to);  }
@Test public void null_vertices_are_not_allowed() { var graph = new Graph<Vertices>(); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Null vertices are not allowed"); graph.edge(A, null); }