aboutsummaryrefslogtreecommitdiff
path: root/android/guava-tests/test/com/google/common/graph/ValueGraphTest.java
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2024-02-03 00:32:48 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2024-02-03 00:32:48 +0000
commitf25b489aa8cf9cce098394ef0e7f81c79c634f26 (patch)
treecbc7e4894708533a0ddc4e61da1d74e64393e0e1 /android/guava-tests/test/com/google/common/graph/ValueGraphTest.java
parent205e5f2e2dc52e2212426602327ea0d630e1731f (diff)
parent0ccd979d1e45372e0b57851529eddd9c40671577 (diff)
downloadguava-f25b489aa8cf9cce098394ef0e7f81c79c634f26.tar.gz
Merge "Snap for 11400057 from fcb68273955c94ebe12fda34018935b0c25d56dc to simpleperf-release" into simpleperf-releasesimpleperf-release
Diffstat (limited to 'android/guava-tests/test/com/google/common/graph/ValueGraphTest.java')
-rw-r--r--android/guava-tests/test/com/google/common/graph/ValueGraphTest.java98
1 files changed, 47 insertions, 51 deletions
diff --git a/android/guava-tests/test/com/google/common/graph/ValueGraphTest.java b/android/guava-tests/test/com/google/common/graph/ValueGraphTest.java
index 24323ca00..caf7ed984 100644
--- a/android/guava-tests/test/com/google/common/graph/ValueGraphTest.java
+++ b/android/guava-tests/test/com/google/common/graph/ValueGraphTest.java
@@ -20,7 +20,7 @@ import static com.google.common.graph.GraphConstants.ENDPOINTS_MISMATCH;
import static com.google.common.graph.TestUtil.assertStronglyEquivalent;
import static com.google.common.truth.Truth.assertThat;
import static java.util.concurrent.Executors.newFixedThreadPool;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.assertThrows;
import com.google.common.collect.ImmutableList;
import java.util.Set;
@@ -197,13 +197,16 @@ public final class ValueGraphTest {
public void edgeValueOrDefault_directed_mismatch() {
graph = ValueGraphBuilder.directed().build();
graph.putEdgeValue(1, 2, "A");
- try {
- String unused = graph.edgeValueOrDefault(EndpointPair.unordered(1, 2), "default");
- unused = graph.edgeValueOrDefault(EndpointPair.unordered(2, 1), "default");
- fail("Expected IllegalArgumentException: " + ENDPOINTS_MISMATCH);
- } catch (IllegalArgumentException e) {
- assertThat(e).hasMessageThat().contains(ENDPOINTS_MISMATCH);
- }
+ IllegalArgumentException e =
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> graph.edgeValueOrDefault(EndpointPair.unordered(1, 2), "default"));
+ assertThat(e).hasMessageThat().contains(ENDPOINTS_MISMATCH);
+ e =
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> graph.edgeValueOrDefault(EndpointPair.unordered(2, 1), "default"));
+ assertThat(e).hasMessageThat().contains(ENDPOINTS_MISMATCH);
}
@Test
@@ -225,18 +228,16 @@ public final class ValueGraphTest {
graph = ValueGraphBuilder.undirected().build();
graph.putEdgeValue(1, 2, "A");
// Check that edgeValueOrDefault() throws on each possible ordering of an ordered EndpointPair
- try {
- String unused = graph.edgeValueOrDefault(EndpointPair.ordered(1, 2), "default");
- fail("Expected IllegalArgumentException: " + ENDPOINTS_MISMATCH);
- } catch (IllegalArgumentException e) {
- assertThat(e).hasMessageThat().contains(ENDPOINTS_MISMATCH);
- }
- try {
- String unused = graph.edgeValueOrDefault(EndpointPair.ordered(2, 1), "default");
- fail("Expected IllegalArgumentException: " + ENDPOINTS_MISMATCH);
- } catch (IllegalArgumentException e) {
- assertThat(e).hasMessageThat().contains(ENDPOINTS_MISMATCH);
- }
+ IllegalArgumentException e =
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> graph.edgeValueOrDefault(EndpointPair.ordered(1, 2), "default"));
+ assertThat(e).hasMessageThat().contains(ENDPOINTS_MISMATCH);
+ e =
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> graph.edgeValueOrDefault(EndpointPair.ordered(2, 1), "default"));
+ assertThat(e).hasMessageThat().contains(ENDPOINTS_MISMATCH);
}
@Test
@@ -252,23 +253,21 @@ public final class ValueGraphTest {
@Test
public void putEdgeValue_directed_orderMismatch() {
graph = ValueGraphBuilder.directed().build();
- try {
- graph.putEdgeValue(EndpointPair.unordered(1, 2), "irrelevant");
- fail("Expected IllegalArgumentException: " + ENDPOINTS_MISMATCH);
- } catch (IllegalArgumentException e) {
- assertThat(e).hasMessageThat().contains(ENDPOINTS_MISMATCH);
- }
+ IllegalArgumentException e =
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> graph.putEdgeValue(EndpointPair.unordered(1, 2), "irrelevant"));
+ assertThat(e).hasMessageThat().contains(ENDPOINTS_MISMATCH);
}
@Test
public void putEdgeValue_undirected_orderMismatch() {
graph = ValueGraphBuilder.undirected().build();
- try {
- graph.putEdgeValue(EndpointPair.ordered(1, 2), "irrelevant");
- fail("Expected IllegalArgumentException: " + ENDPOINTS_MISMATCH);
- } catch (IllegalArgumentException e) {
- assertThat(e).hasMessageThat().contains(ENDPOINTS_MISMATCH);
- }
+ IllegalArgumentException e =
+ assertThrows(
+ IllegalArgumentException.class,
+ () -> graph.putEdgeValue(EndpointPair.ordered(1, 2), "irrelevant"));
+ assertThat(e).hasMessageThat().contains(ENDPOINTS_MISMATCH);
}
@Test
@@ -315,13 +314,14 @@ public final class ValueGraphTest {
graph = ValueGraphBuilder.directed().build();
graph.putEdgeValue(1, 2, "1->2");
graph.putEdgeValue(2, 1, "2->1");
- try {
- graph.removeEdge(EndpointPair.unordered(1, 2));
- graph.removeEdge(EndpointPair.unordered(2, 1));
- fail("Expected IllegalArgumentException: " + ENDPOINTS_MISMATCH);
- } catch (IllegalArgumentException e) {
- assertThat(e).hasMessageThat().contains(ENDPOINTS_MISMATCH);
- }
+ IllegalArgumentException e =
+ assertThrows(
+ IllegalArgumentException.class, () -> graph.removeEdge(EndpointPair.unordered(1, 2)));
+ assertThat(e).hasMessageThat().contains(ENDPOINTS_MISMATCH);
+ e =
+ assertThrows(
+ IllegalArgumentException.class, () -> graph.removeEdge(EndpointPair.unordered(2, 1)));
+ assertThat(e).hasMessageThat().contains(ENDPOINTS_MISMATCH);
}
@Test
@@ -329,18 +329,14 @@ public final class ValueGraphTest {
graph = ValueGraphBuilder.undirected().build();
graph.putEdgeValue(1, 2, "1-2");
// Check that removeEdge() throws on each possible ordering of an ordered EndpointPair
- try {
- graph.removeEdge(EndpointPair.ordered(1, 2));
- fail("Expected IllegalArgumentException: " + ENDPOINTS_MISMATCH);
- } catch (IllegalArgumentException e) {
- assertThat(e).hasMessageThat().contains(ENDPOINTS_MISMATCH);
- }
- try {
- graph.removeEdge(EndpointPair.ordered(2, 1));
- fail("Expected IllegalArgumentException: " + ENDPOINTS_MISMATCH);
- } catch (IllegalArgumentException e) {
- assertThat(e).hasMessageThat().contains(ENDPOINTS_MISMATCH);
- }
+ IllegalArgumentException e =
+ assertThrows(
+ IllegalArgumentException.class, () -> graph.removeEdge(EndpointPair.ordered(1, 2)));
+ assertThat(e).hasMessageThat().contains(ENDPOINTS_MISMATCH);
+ e =
+ assertThrows(
+ IllegalArgumentException.class, () -> graph.removeEdge(EndpointPair.ordered(2, 1)));
+ assertThat(e).hasMessageThat().contains(ENDPOINTS_MISMATCH);
}
@Test