blob: a6cedf942dfcff40e7805bfde0d3269cf4e5c014 [file] [log] [blame]
Brian O'Connorf3d06162014-10-02 15:54:12 -07001package org.onlab.onos.net.intent;
2
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertFalse;
5import static org.junit.Assert.assertTrue;
6
7import java.util.Arrays;
8import java.util.HashSet;
9import java.util.Set;
10
11import org.junit.Test;
12
13/**
14 * Base facilities to test various intent tests.
15 */
16public abstract class IntentTest {
17 /**
18 * Produces a set of items from the supplied items.
19 *
20 * @param items items to be placed in set
21 * @param <T> item type
22 * @return set of items
23 */
24 protected static <T> Set<T> itemSet(T[] items) {
25 return new HashSet<>(Arrays.asList(items));
26 }
27
28 @Test
29 public void equalsAndHashCode() {
30 Intent one = createOne();
31 Intent like = createOne();
32 Intent another = createAnother();
33
34 assertTrue("should be equal", one.equals(like));
35 assertEquals("incorrect hashCode", one.hashCode(), like.hashCode());
36
37 assertFalse("should not be equal", one.equals(another));
38
39 assertFalse("should not be equal", one.equals(null));
40 assertFalse("should not be equal", one.equals("foo"));
41 }
42
43 @Test
44 public void testToString() {
45 Intent one = createOne();
46 Intent like = createOne();
47 assertEquals("incorrect toString", one.toString(), like.toString());
48 }
49
50 /**
51 * Creates a new intent, but always a like intent, i.e. all instances will
52 * be equal, but should not be the same.
53 *
54 * @return intent
55 */
56 protected abstract Intent createOne();
57
58 /**
59 * Creates another intent, not equals to the one created by
60 * {@link #createOne()} and with a different hash code.
61 *
62 * @return another intent
63 */
64 protected abstract Intent createAnother();
65}