blob: 5bf0c74be4994975f44fcc06e31858528a60db08 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 Open Networking Laboratory
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 */
Brian O'Connorf3d06162014-10-02 15:54:12 -070016package org.onlab.onos.net.intent;
17
Thomas Vachuskac96058a2014-10-20 23:00:16 -070018import org.junit.Test;
Brian O'Connorf3d06162014-10-02 15:54:12 -070019
20import java.util.Arrays;
21import java.util.HashSet;
22import java.util.Set;
23
Thomas Vachuskac96058a2014-10-20 23:00:16 -070024import static org.junit.Assert.*;
Brian O'Connorf3d06162014-10-02 15:54:12 -070025
26/**
27 * Base facilities to test various intent tests.
28 */
29public abstract class IntentTest {
30 /**
31 * Produces a set of items from the supplied items.
32 *
33 * @param items items to be placed in set
34 * @param <T> item type
35 * @return set of items
36 */
37 protected static <T> Set<T> itemSet(T[] items) {
38 return new HashSet<>(Arrays.asList(items));
39 }
40
41 @Test
42 public void equalsAndHashCode() {
43 Intent one = createOne();
44 Intent like = createOne();
45 Intent another = createAnother();
46
47 assertTrue("should be equal", one.equals(like));
48 assertEquals("incorrect hashCode", one.hashCode(), like.hashCode());
Brian O'Connorf3d06162014-10-02 15:54:12 -070049 assertFalse("should not be equal", one.equals(another));
Brian O'Connorf3d06162014-10-02 15:54:12 -070050 }
51
52 @Test
53 public void testToString() {
54 Intent one = createOne();
55 Intent like = createOne();
56 assertEquals("incorrect toString", one.toString(), like.toString());
57 }
58
59 /**
60 * Creates a new intent, but always a like intent, i.e. all instances will
61 * be equal, but should not be the same.
62 *
63 * @return intent
64 */
65 protected abstract Intent createOne();
66
67 /**
68 * Creates another intent, not equals to the one created by
69 * {@link #createOne()} and with a different hash code.
70 *
71 * @return another intent
72 */
73 protected abstract Intent createAnother();
74}