1 /*
2  * Copyright (C) 2015 The Guava Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.common.graph;
18 
19 import static com.google.common.graph.TestUtil.ERROR_ELEMENT_NOT_IN_GRAPH;
20 import static com.google.common.truth.Truth.assertWithMessage;
21 
22 import com.google.common.testing.AbstractPackageSanityTests;
23 import junit.framework.AssertionFailedError;
24 
25 /**
26  * Covers basic sanity checks for the entire package.
27  *
28  * @author Kurt Alfred Kluever
29  */
30 
31 public class PackageSanityTests extends AbstractPackageSanityTests {
32 
33   private static final AbstractGraphBuilder<?> GRAPH_BUILDER_A =
34       GraphBuilder.directed().expectedNodeCount(10);
35   private static final AbstractGraphBuilder<?> GRAPH_BUILDER_B =
36       ValueGraphBuilder.directed().allowsSelfLoops(true).expectedNodeCount(16);
37 
38   private static final ImmutableGraph<String> IMMUTABLE_GRAPH_A =
39       GraphBuilder.directed().<String>immutable().addNode("A").build();
40   private static final ImmutableGraph<String> IMMUTABLE_GRAPH_B =
41       GraphBuilder.directed().<String>immutable().addNode("B").build();
42 
43   private static final NetworkBuilder<?, ?> NETWORK_BUILDER_A =
44       NetworkBuilder.directed().allowsParallelEdges(true).expectedNodeCount(10);
45   private static final NetworkBuilder<?, ?> NETWORK_BUILDER_B =
46       NetworkBuilder.directed().allowsSelfLoops(true).expectedNodeCount(16);
47 
48   private static final ImmutableNetwork<String, String> IMMUTABLE_NETWORK_A =
49       NetworkBuilder.directed().<String, String>immutable().addNode("A").build();
50   private static final ImmutableNetwork<String, String> IMMUTABLE_NETWORK_B =
51       NetworkBuilder.directed().<String, String>immutable().addNode("B").build();
52 
PackageSanityTests()53   public PackageSanityTests() {
54     setDistinctValues(AbstractGraphBuilder.class, GRAPH_BUILDER_A, GRAPH_BUILDER_B);
55     setDistinctValues(Graph.class, IMMUTABLE_GRAPH_A, IMMUTABLE_GRAPH_B);
56     setDistinctValues(NetworkBuilder.class, NETWORK_BUILDER_A, NETWORK_BUILDER_B);
57     setDistinctValues(Network.class, IMMUTABLE_NETWORK_A, IMMUTABLE_NETWORK_B);
58     setDefault(EndpointPair.class, EndpointPair.ordered("A", "B"));
59   }
60 
61   @Override
testNulls()62   public void testNulls() throws Exception {
63     try {
64       super.testNulls();
65     } catch (AssertionFailedError e) {
66       assertWithMessage("Method did not throw null pointer OR element not in graph exception.")
67           .that(e)
68           .hasCauseThat()
69           .hasMessageThat()
70           .contains(ERROR_ELEMENT_NOT_IN_GRAPH);
71     }
72   }
73 }
74