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 24 /** 25 * Covers basic sanity checks for the entire package. 26 * 27 * @author Kurt Alfred Kluever 28 */ 29 30 public class PackageSanityTests extends AbstractPackageSanityTests { 31 32 private static final AbstractGraphBuilder<?> GRAPH_BUILDER_A = 33 GraphBuilder.directed().expectedNodeCount(10); 34 private static final AbstractGraphBuilder<?> GRAPH_BUILDER_B = 35 ValueGraphBuilder.directed().allowsSelfLoops(true).expectedNodeCount(16); 36 37 private static final ImmutableGraph<String> IMMUTABLE_GRAPH_A = 38 GraphBuilder.directed().<String>immutable().addNode("A").build(); 39 private static final ImmutableGraph<String> IMMUTABLE_GRAPH_B = 40 GraphBuilder.directed().<String>immutable().addNode("B").build(); 41 42 private static final NetworkBuilder<?, ?> NETWORK_BUILDER_A = 43 NetworkBuilder.directed().allowsParallelEdges(true).expectedNodeCount(10); 44 private static final NetworkBuilder<?, ?> NETWORK_BUILDER_B = 45 NetworkBuilder.directed().allowsSelfLoops(true).expectedNodeCount(16); 46 47 private static final ImmutableNetwork<String, String> IMMUTABLE_NETWORK_A = 48 NetworkBuilder.directed().<String, String>immutable().addNode("A").build(); 49 private static final ImmutableNetwork<String, String> IMMUTABLE_NETWORK_B = 50 NetworkBuilder.directed().<String, String>immutable().addNode("B").build(); 51 PackageSanityTests()52 public PackageSanityTests() { 53 MutableNetwork<String, String> mutableNetworkA = NetworkBuilder.directed().build(); 54 mutableNetworkA.addNode("a"); 55 MutableNetwork<String, String> mutableNetworkB = NetworkBuilder.directed().build(); 56 mutableNetworkB.addNode("b"); 57 58 setDistinctValues(AbstractGraphBuilder.class, GRAPH_BUILDER_A, GRAPH_BUILDER_B); 59 setDistinctValues(Graph.class, IMMUTABLE_GRAPH_A, IMMUTABLE_GRAPH_B); 60 setDistinctValues(MutableNetwork.class, mutableNetworkA, mutableNetworkB); 61 setDistinctValues(NetworkBuilder.class, NETWORK_BUILDER_A, NETWORK_BUILDER_B); 62 setDistinctValues(Network.class, IMMUTABLE_NETWORK_A, IMMUTABLE_NETWORK_B); 63 setDefault(EndpointPair.class, EndpointPair.ordered("A", "B")); 64 } 65 66 @Override testNulls()67 public void testNulls() throws Exception { 68 try { 69 super.testNulls(); 70 } catch (AssertionError e) { 71 assertWithMessage("Method did not throw null pointer OR element not in graph exception.") 72 .that(e) 73 .hasCauseThat() 74 .hasMessageThat() 75 .contains(ERROR_ELEMENT_NOT_IN_GRAPH); 76 } 77 } 78 } 79