aboutsummaryrefslogtreecommitdiff
path: root/android/guava-tests/test/com/google/common/graph/AbstractStandardDirectedGraphTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'android/guava-tests/test/com/google/common/graph/AbstractStandardDirectedGraphTest.java')
-rw-r--r--android/guava-tests/test/com/google/common/graph/AbstractStandardDirectedGraphTest.java87
1 files changed, 33 insertions, 54 deletions
diff --git a/android/guava-tests/test/com/google/common/graph/AbstractStandardDirectedGraphTest.java b/android/guava-tests/test/com/google/common/graph/AbstractStandardDirectedGraphTest.java
index c50a7da67..b1a69de2f 100644
--- a/android/guava-tests/test/com/google/common/graph/AbstractStandardDirectedGraphTest.java
+++ b/android/guava-tests/test/com/google/common/graph/AbstractStandardDirectedGraphTest.java
@@ -19,8 +19,8 @@ package com.google.common.graph;
import static com.google.common.graph.GraphConstants.ENDPOINTS_MISMATCH;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.TruthJUnit.assume;
+import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.util.Set;
import org.junit.Test;
@@ -36,13 +36,10 @@ public abstract class AbstractStandardDirectedGraphTest extends AbstractGraphTes
assume().that(graphIsMutable()).isTrue();
Set<Integer> nodes = graph.nodes();
- try {
- nodes.add(N2);
- fail(ERROR_MODIFIABLE_SET);
- } catch (UnsupportedOperationException e) {
- addNode(N1);
- assertThat(graph.nodes()).containsExactlyElementsIn(nodes);
- }
+ UnsupportedOperationException e =
+ assertThrows(UnsupportedOperationException.class, () -> nodes.add(N2));
+ addNode(N1);
+ assertThat(graph.nodes()).containsExactlyElementsIn(nodes);
}
@Override
@@ -52,13 +49,10 @@ public abstract class AbstractStandardDirectedGraphTest extends AbstractGraphTes
addNode(N1);
Set<Integer> adjacentNodes = graph.adjacentNodes(N1);
- try {
- adjacentNodes.add(N2);
- fail(ERROR_MODIFIABLE_SET);
- } catch (UnsupportedOperationException e) {
- putEdge(N1, N2);
- assertThat(graph.adjacentNodes(N1)).containsExactlyElementsIn(adjacentNodes);
- }
+ UnsupportedOperationException e =
+ assertThrows(UnsupportedOperationException.class, () -> adjacentNodes.add(N2));
+ putEdge(N1, N2);
+ assertThat(graph.adjacentNodes(N1)).containsExactlyElementsIn(adjacentNodes);
}
@Override
@@ -68,13 +62,10 @@ public abstract class AbstractStandardDirectedGraphTest extends AbstractGraphTes
addNode(N2);
Set<Integer> predecessors = graph.predecessors(N2);
- try {
- predecessors.add(N1);
- fail(ERROR_MODIFIABLE_SET);
- } catch (UnsupportedOperationException e) {
- putEdge(N1, N2);
- assertThat(graph.predecessors(N2)).containsExactlyElementsIn(predecessors);
- }
+ UnsupportedOperationException e =
+ assertThrows(UnsupportedOperationException.class, () -> predecessors.add(N1));
+ putEdge(N1, N2);
+ assertThat(graph.predecessors(N2)).containsExactlyElementsIn(predecessors);
}
@Override
@@ -84,13 +75,10 @@ public abstract class AbstractStandardDirectedGraphTest extends AbstractGraphTes
addNode(N1);
Set<Integer> successors = graph.successors(N1);
- try {
- successors.add(N2);
- fail(ERROR_MODIFIABLE_SET);
- } catch (UnsupportedOperationException e) {
- putEdge(N1, N2);
- assertThat(successors).containsExactlyElementsIn(graph.successors(N1));
- }
+ UnsupportedOperationException e =
+ assertThrows(UnsupportedOperationException.class, () -> successors.add(N2));
+ putEdge(N1, N2);
+ assertThat(successors).containsExactlyElementsIn(graph.successors(N1));
}
@Override
@@ -100,13 +88,12 @@ public abstract class AbstractStandardDirectedGraphTest extends AbstractGraphTes
addNode(N1);
Set<EndpointPair<Integer>> incidentEdges = graph.incidentEdges(N1);
- try {
- incidentEdges.add(EndpointPair.ordered(N1, N2));
- fail(ERROR_MODIFIABLE_SET);
- } catch (UnsupportedOperationException e) {
- putEdge(N1, N2);
- assertThat(incidentEdges).containsExactlyElementsIn(graph.incidentEdges(N1));
- }
+ UnsupportedOperationException e =
+ assertThrows(
+ UnsupportedOperationException.class,
+ () -> incidentEdges.add(EndpointPair.ordered(N1, N2)));
+ putEdge(N1, N2);
+ assertThat(incidentEdges).containsExactlyElementsIn(graph.incidentEdges(N1));
}
@Test
@@ -364,12 +351,9 @@ public abstract class AbstractStandardDirectedGraphTest extends AbstractGraphTes
assume().that(graphIsMutable()).isTrue();
EndpointPair<Integer> endpoints = EndpointPair.unordered(N1, N2);
- try {
- graphAsMutableGraph.putEdge(endpoints);
- fail("Expected IllegalArgumentException: " + ENDPOINTS_MISMATCH);
- } catch (IllegalArgumentException e) {
- assertThat(e).hasMessageThat().contains(ENDPOINTS_MISMATCH);
- }
+ IllegalArgumentException e =
+ assertThrows(IllegalArgumentException.class, () -> graphAsMutableGraph.putEdge(endpoints));
+ assertThat(e).hasMessageThat().contains(ENDPOINTS_MISMATCH);
}
/**
@@ -398,12 +382,9 @@ public abstract class AbstractStandardDirectedGraphTest extends AbstractGraphTes
assume().that(graphIsMutable()).isTrue();
assume().that(graph.allowsSelfLoops()).isFalse();
- try {
- graphAsMutableGraph.putEdge(N1, N1);
- fail(ERROR_ADDED_SELF_LOOP);
- } catch (IllegalArgumentException e) {
- assertThat(e).hasMessageThat().contains(ERROR_SELF_LOOP);
- }
+ IllegalArgumentException e =
+ assertThrows(IllegalArgumentException.class, () -> graphAsMutableGraph.putEdge(N1, N1));
+ assertThat(e).hasMessageThat().contains(ERROR_SELF_LOOP);
}
@Test
@@ -449,12 +430,10 @@ public abstract class AbstractStandardDirectedGraphTest extends AbstractGraphTes
putEdge(N1, N2);
EndpointPair<Integer> endpoints = EndpointPair.unordered(N1, N2);
- try {
- graphAsMutableGraph.removeEdge(endpoints);
- fail("Expected IllegalArgumentException: " + ENDPOINTS_MISMATCH);
- } catch (IllegalArgumentException e) {
- assertThat(e).hasMessageThat().contains(ENDPOINTS_MISMATCH);
- }
+ IllegalArgumentException e =
+ assertThrows(
+ IllegalArgumentException.class, () -> graphAsMutableGraph.removeEdge(endpoints));
+ assertThat(e).hasMessageThat().contains(ENDPOINTS_MISMATCH);
}
@Test