diff options
Diffstat (limited to 'guava-tests/test/com/google/common/graph/AbstractGraphTest.java')
-rw-r--r-- | guava-tests/test/com/google/common/graph/AbstractGraphTest.java | 84 |
1 files changed, 31 insertions, 53 deletions
diff --git a/guava-tests/test/com/google/common/graph/AbstractGraphTest.java b/guava-tests/test/com/google/common/graph/AbstractGraphTest.java index 3a489a11c..a8209244c 100644 --- a/guava-tests/test/com/google/common/graph/AbstractGraphTest.java +++ b/guava-tests/test/com/google/common/graph/AbstractGraphTest.java @@ -16,13 +16,12 @@ package com.google.common.graph; -import static com.google.common.graph.TestUtil.ERROR_NODE_NOT_IN_GRAPH; import static com.google.common.graph.TestUtil.assertNodeNotInGraphErrorMessage; import static com.google.common.graph.TestUtil.assertStronglyEquivalent; import static com.google.common.graph.TestUtil.sanityCheckSet; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.TruthJUnit.assume; -import static org.junit.Assert.fail; +import static org.junit.Assert.assertThrows; import com.google.common.collect.ImmutableSet; import java.util.HashSet; @@ -235,12 +234,9 @@ public abstract class AbstractGraphTest { @Test public void adjacentNodes_nodeNotInGraph() { - try { - graph.adjacentNodes(NODE_NOT_IN_GRAPH); - fail(ERROR_NODE_NOT_IN_GRAPH); - } catch (IllegalArgumentException e) { - assertNodeNotInGraphErrorMessage(e); - } + IllegalArgumentException e = + assertThrows(IllegalArgumentException.class, () -> graph.adjacentNodes(NODE_NOT_IN_GRAPH)); + assertNodeNotInGraphErrorMessage(e); } @Test @@ -251,12 +247,9 @@ public abstract class AbstractGraphTest { @Test public void predecessors_nodeNotInGraph() { - try { - graph.predecessors(NODE_NOT_IN_GRAPH); - fail(ERROR_NODE_NOT_IN_GRAPH); - } catch (IllegalArgumentException e) { - assertNodeNotInGraphErrorMessage(e); - } + IllegalArgumentException e = + assertThrows(IllegalArgumentException.class, () -> graph.predecessors(NODE_NOT_IN_GRAPH)); + assertNodeNotInGraphErrorMessage(e); } @Test @@ -267,12 +260,9 @@ public abstract class AbstractGraphTest { @Test public void successors_nodeNotInGraph() { - try { - graph.successors(NODE_NOT_IN_GRAPH); - fail(ERROR_NODE_NOT_IN_GRAPH); - } catch (IllegalArgumentException e) { - assertNodeNotInGraphErrorMessage(e); - } + IllegalArgumentException e = + assertThrows(IllegalArgumentException.class, () -> graph.successors(NODE_NOT_IN_GRAPH)); + assertNodeNotInGraphErrorMessage(e); } @Test @@ -283,12 +273,9 @@ public abstract class AbstractGraphTest { @Test public void incidentEdges_nodeNotInGraph() { - try { - graph.incidentEdges(NODE_NOT_IN_GRAPH); - fail(ERROR_NODE_NOT_IN_GRAPH); - } catch (IllegalArgumentException e) { - assertNodeNotInGraphErrorMessage(e); - } + IllegalArgumentException e = + assertThrows(IllegalArgumentException.class, () -> graph.incidentEdges(NODE_NOT_IN_GRAPH)); + assertNodeNotInGraphErrorMessage(e); } @Test @@ -306,12 +293,9 @@ public abstract class AbstractGraphTest { @Test public void degree_nodeNotInGraph() { - try { - graph.degree(NODE_NOT_IN_GRAPH); - fail(ERROR_NODE_NOT_IN_GRAPH); - } catch (IllegalArgumentException e) { - assertNodeNotInGraphErrorMessage(e); - } + IllegalArgumentException e = + assertThrows(IllegalArgumentException.class, () -> graph.degree(NODE_NOT_IN_GRAPH)); + assertNodeNotInGraphErrorMessage(e); } @Test @@ -322,12 +306,9 @@ public abstract class AbstractGraphTest { @Test public void inDegree_nodeNotInGraph() { - try { - graph.inDegree(NODE_NOT_IN_GRAPH); - fail(ERROR_NODE_NOT_IN_GRAPH); - } catch (IllegalArgumentException e) { - assertNodeNotInGraphErrorMessage(e); - } + IllegalArgumentException e = + assertThrows(IllegalArgumentException.class, () -> graph.inDegree(NODE_NOT_IN_GRAPH)); + assertNodeNotInGraphErrorMessage(e); } @Test @@ -338,12 +319,9 @@ public abstract class AbstractGraphTest { @Test public void outDegree_nodeNotInGraph() { - try { - graph.outDegree(NODE_NOT_IN_GRAPH); - fail(ERROR_NODE_NOT_IN_GRAPH); - } catch (IllegalArgumentException e) { - assertNodeNotInGraphErrorMessage(e); - } + IllegalArgumentException e = + assertThrows(IllegalArgumentException.class, () -> graph.outDegree(NODE_NOT_IN_GRAPH)); + assertNodeNotInGraphErrorMessage(e); } @Test @@ -407,16 +385,16 @@ public abstract class AbstractGraphTest { public void removeNode_queryAfterRemoval() { assume().that(graphIsMutable()).isTrue(); - addNode(N1); - @SuppressWarnings("unused") - Set<Integer> unused = graph.adjacentNodes(N1); // ensure cache (if any) is populated + putEdge(N1, N2); + putEdge(N2, N1); + Set<Integer> n1AdjacentNodes = graph.adjacentNodes(N1); + Set<Integer> n2AdjacentNodes = graph.adjacentNodes(N2); assertThat(graphAsMutableGraph.removeNode(N1)).isTrue(); - try { - graph.adjacentNodes(N1); - fail(ERROR_NODE_NOT_IN_GRAPH); - } catch (IllegalArgumentException e) { - assertNodeNotInGraphErrorMessage(e); - } + assertThat(n1AdjacentNodes).isEmpty(); + assertThat(n2AdjacentNodes).isEmpty(); + IllegalArgumentException e = + assertThrows(IllegalArgumentException.class, () -> graph.adjacentNodes(N1)); + assertNodeNotInGraphErrorMessage(e); } @Test |