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